Skip to content

Commit e0171a0

Browse files
committed
Merge pull request #59 from dovg/nullStringDialect
throw exception for null values
2 parents 554b118 + b9ff40b commit e0171a0

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-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;

doc/ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2012-01-11 Evgeny V. Kokovikhin
2+
3+
* core/DB/Dialect.class.php: throw exception for null values. Thanks to
4+
Nikita V. Konstantinov.
5+
16
2011-11-21 Alexey S. Denisov, Evgeny V. Kokovikhin
27

38
* meta/types/ObjectType.class.php, test/misc/DAOTest.class.php: changed logic

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)