Skip to content

Commit 23f9e1d

Browse files
committed
throw exception for null values
1 parent 554b118 commit 23f9e1d

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

core/DB/Dialect.class.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,20 @@ public function toValueString($expression)
100100

101101
private function toNeededString($expression, $method)
102102
{
103+
if (null === $expression)
104+
throw new WrongArgumentException(
105+
'not null expression expected'
106+
);
107+
103108
$string = null;
104109

105-
if (null !== $expression) {
106-
if ($expression instanceof DialectString) {
107-
if ($expression instanceof Query)
108-
$string .= '('.$expression->toDialectString($this).')';
109-
else
110-
$string .= $expression->toDialectString($this);
111-
} else {
112-
$string .= $this->$method($expression);
113-
}
110+
if ($expression instanceof DialectString) {
111+
if ($expression instanceof Query)
112+
$string .= '('.$expression->toDialectString($this).')';
113+
else
114+
$string .= $expression->toDialectString($this);
115+
} else {
116+
$string .= $this->$method($expression);
114117
}
115118

116119
return $string;

test/core/LogicTest.class.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,14 @@ public function testBaseSqlGeneration()
210210
'(- a)',
211211
Expression::minus('a')->toDialectString($dialect)
212212
);
213+
214+
try {
215+
Expression::eq('id', null)->toDialectString($dialect);
216+
217+
$this->fail();
218+
} catch (WrongArgumentException $e) {
219+
//it's Ok
220+
}
213221
}
214222

215223
public function testPgGeneration()

0 commit comments

Comments
 (0)