Permalink
Browse files

DbManager_MySQL: patch for correctly handling "!= null" and "is not n…

…ull"
  • Loading branch information...
1 parent ec72d5a commit 4c95226e0357097e8e0fffa27836ddb1b87e9f8d @cirkuitnet committed Aug 8, 2011
Showing with 20 additions and 1 deletion.
  1. +6 −1 DbManagers/DbManager_MySQL.php
  2. +14 −0 DbManagers/DbManager_Tests.php
@@ -798,7 +798,12 @@ private function GenerateWhereSingle($table, $column, $condition, $val, $dotNota
else if($addColumnQuotes) $column = "`$column`";
//else $column = $column;
- if ($val === null) {$ret = $column." is null";} //'is null' for null
+ if ($val === null) {
+ if($condition == "!=" || $condition == "IS NOT"){
+ $ret = $column." is not null"; //'is not null' for null
+ }
+ else $ret = $column." is null"; //'is null' for null
+ }
else if(is_numeric($val) && !$options['quote-numerics']){
//no quotes around a numeric unless the value is HUGE and falls outside normal values for SIGNED integers... mysql does weird conversion things if the column is a varchar and these large numbers are used... it wont lookup these big numbers correctly unless quotes are used
if($val < (0-$this->PHP_INT_MAX_HALF) || $val > $this->PHP_INT_MAX_HALF){
@@ -36,6 +36,7 @@ public function TestAll(){
$result = $this->TestWhereClause19(); if($result['passed']) $passed++; else $failed++;
$result = $this->TestWhereClause20(); if($result['passed']) $passed++; else $failed++;
$result = $this->TestWhereClause21(); if($result['passed']) $passed++; else $failed++;
+ $result = $this->TestWhereClause22(); if($result['passed']) $passed++; else $failed++;
// test database copy. connected user should have permissions to drop/create tables and databases
//this also tests creating and dropping databases and tables
@@ -380,6 +381,19 @@ private function TestWhereClause21() {
'quote-numerics'=>true
));
}
+
+ private function TestWhereClause22() {
+ $expectedResult = "WHERE (((col1 != 0 OR col1 is null)) AND (col2 is null) AND (col3 is not null) AND (col4 is not null))";
+ $array_where = array(
+ "AND" => array(
+ "col1" => array("!=" => "0"),
+ "col2" => array("=" => NULL),
+ "col3" => array("IS NOT"=>null),
+ "col4" => array("!="=>null),
+ )
+ );
+ return $this->TestWhereClause($array_where, $expectedResult, __FUNCTION__);
+ }
}

0 comments on commit 4c95226

Please sign in to comment.