Browse Source

Changing the empty conditions list approach as not all drivers were happy

Jose Lorenzo Rodriguez 11 years ago
parent
commit
de876f0f54
1 changed files with 7 additions and 4 deletions
  1. 7 4
      src/Database/Expression/Comparison.php

+ 7 - 4
src/Database/Expression/Comparison.php

@@ -131,10 +131,17 @@ class Comparison extends QueryExpression {
 			$template = '%s %s (%s)';
 			$type = str_replace('[]', '', $this->_type);
 			$value = $this->_flattenValue($this->_value, $generator, $type);
+
+			// To avoid SQL erros when comparing a field to a list of empty values,
+			// generate a condition that will always evaluate to false
+			if ($value === '') {
+				return ['1 != 1', ''];
+			}
 		} else {
 			$template = '%s %s %s';
 			$value = $this->_bindValue($this->_value, $generator, $this->_type);
 		}
+
 		return [$template, $value];
 	}
 
@@ -167,10 +174,6 @@ class Comparison extends QueryExpression {
 			$parts[] = $this->_bindValue($v, $generator, $type);
 		}
 
-		if (empty($parts)) {
-			return "SELECT CAST(NULL as $type)";
-		}
-
 		return implode(',', $parts);
 	}