Letractively / add-mvc-framework

Automatically exported from code.google.com/p/add-mvc-framework
0 stars 0 forks source link

field => null condition on model_rwd #159

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Steps to reproduce the problem:
Pass array with field => null

expected output:
Match items with field equals to null

actual output:
Not matched

Original issue reported on code.google.com by albertdi...@gmail.com on 10 Mar 2015 at 9:17

GoogleCodeExporter commented 8 years ago
{{{

   /**
    * Centralized creator of "WHERE" clause
    *
    * @param mixed $conditions to serialize/normalize, either array or string
    * @param string $prefix to add to the where clause
    *
    * @return string the where clause string
    * @since ADD MVC 0.0
    */
   static function normalize_where($conditions, $prefix = "WHERE") {
      $where_clause = "";
      if (is_array($conditions)) {
         $where_conditions = array();
         $args = array();
         foreach ($conditions as $field=>$value) {
            if (strpos($field,':')) {
               list($field,$operator) = explode(":",$field);
            }
            else {
               $operator = "=";
            }
            if ($value === null) {
               $where_conditions[] = static::db()->meta_quote($field)." IS NULL";
            }
            else {
               $where_conditions[] = static::db()->meta_quote($field)."$operator".static::db()->quote($value);
            }
         }

         if ($where_conditions) {
            $where_clause = "$prefix ".implode(" AND ",$where_conditions);
         }
      }
      else if (is_string($conditions)) {
         # Make sure there's something
         if (trim($conditions)) {
            $where_clause = "$prefix ".$conditions;
         }
         else {
            return false;
         }
      }
      return " $where_clause ";
   }
}}}

Original comment by albertdi...@gmail.com on 10 Mar 2015 at 9:46

GoogleCodeExporter commented 8 years ago
Question is, how compatible is this to different database systems?

Original comment by albertdi...@gmail.com on 10 Mar 2015 at 9:47