Example #1
0
 /**
  * Build a proper WHERE and return it
  *
  * @example
  * <code>
  * $array = ($verb, $field, $operator, $value, $type);
  * $this->build_where($array);
  * </code>
  *
  * @return  VOID
  *
  * @since   2016-09-28
  * @author  Jim Harney <*****@*****.**>
  * @author  Wesley Dekkers <*****@*****.**>
  **/
 public function build_where($rule, $verb = true)
 {
     $field = \PDope\Utilities::escape_mysql_identifier($rule->field);
     $operator = $rule->operator;
     $token = $rule->token;
     if (is_object($rule)) {
         $field = \PDope\Utilities::escape_mysql_identifier($rule->field);
         $operator = $rule->operator;
         $token = $rule->token;
         if ($verb) {
             $sql .= " {$rule->verb} ";
         }
         if (is_array($token) && $operator == 'BETWEEN') {
             if (\PDope\Utilities::is_special_type($rule->type)) {
                 throw new \Exception("PDopeCustomWhereBuilder get_where(), array, does not support special type [{$rule->type}]");
             }
             $token_list = implode(", ", $token);
             $sql .= " {$field} {$operator} {$token[0]} AND {$token[1]}";
         } elseif (is_array($token)) {
             if (\PDope\Utilities::is_special_type($rule->type)) {
                 throw new \Exception("PDopeCustomWhereBuilder get_where(), array, does not support special type [{$rule->type}]");
             }
             $token_list = implode(", ", $token);
             $sql .= "({$field} {$operator} ({$token_list}))";
         } else {
             $token = \PDope\Utilities::translate_special_token($token, $rule->type);
             $sql .= "({$field} {$operator} {$token})";
         }
     }
     return $sql;
 }
Example #2
0
 /**
  * builds the "WHERE" clause
  *
  * @example
  * <code>
  * $this->build_where_sql();
  * </code>
  *
  * @return  VOID
  *
  * @since   2016-5-21
  * @author  Jim Harney <*****@*****.**>
  **/
 private function build_where_sql()
 {
     // if we used a custom where clause, we do not need to build it
     if ($this->used_custom_where || count($this->where_parameters) < 1) {
         return;
     }
     $sql = "WHERE \n";
     for ($i = 0; $i < count($this->where_parameters); $i++) {
         $parameter = $this->where_parameters[$i];
         if ($i == 0) {
             $sql .= "\t";
         } else {
             $sql .= "\tAND ";
         }
         $name = $parameter->name;
         $type = $parameter->type;
         $value = $this->model_object->{$name};
         if (is_array($value)) {
             if (\PDope\Utilities::is_special_type($type)) {
                 throw new \Exception("PDopeStatement build_where_sql(), array, does not support special type [{$type}]");
             }
             $sql .= "(" . \PDope\Utilities::escape_mysql_identifier($name) . " IN (";
             for ($j = 0; $j < count($value); $j++) {
                 if ($j > 0) {
                     $sql .= ", ";
                 }
                 $token = "{$name}_{$j}";
                 $token = \PDope\Utilities::format_token($token);
                 $sql .= $token;
             }
             $sql .= "))";
         } else {
             if (\PDope\Utilities::is_special_type($type)) {
                 $token = \PDope\Utilities::translate_special_token($name, $type);
                 $sql .= "(" . \PDope\Utilities::escape_mysql_identifier($name) . " = {$token}) \n";
             } else {
                 $token = \PDope\Utilities::format_token($name);
                 $sql .= "(" . \PDope\Utilities::escape_mysql_identifier($name) . " = {$token}) \n";
             }
         }
     }
     $this->sql_where .= $sql;
     // $this->log_debug("build_where_sql() built \n$sql");
 }