From 23f9e1d823d00c2a54bec707985455a6c71942dc Mon Sep 17 00:00:00 2001 From: "Evgeniy V. Kokovikhin" Date: Mon, 26 Dec 2011 14:04:08 +0400 Subject: [PATCH 1/2] throw exception for null values --- core/DB/Dialect.class.php | 21 ++++++++++++--------- test/core/LogicTest.class.php | 8 ++++++++ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/core/DB/Dialect.class.php b/core/DB/Dialect.class.php index 5c6b9e4641..1323e24b9f 100644 --- a/core/DB/Dialect.class.php +++ b/core/DB/Dialect.class.php @@ -100,17 +100,20 @@ public function toValueString($expression) private function toNeededString($expression, $method) { + if (null === $expression) + throw new WrongArgumentException( + 'not null expression expected' + ); + $string = null; - if (null !== $expression) { - if ($expression instanceof DialectString) { - if ($expression instanceof Query) - $string .= '('.$expression->toDialectString($this).')'; - else - $string .= $expression->toDialectString($this); - } else { - $string .= $this->$method($expression); - } + if ($expression instanceof DialectString) { + if ($expression instanceof Query) + $string .= '('.$expression->toDialectString($this).')'; + else + $string .= $expression->toDialectString($this); + } else { + $string .= $this->$method($expression); } return $string; diff --git a/test/core/LogicTest.class.php b/test/core/LogicTest.class.php index bfaa3834e7..83b20e5c4c 100644 --- a/test/core/LogicTest.class.php +++ b/test/core/LogicTest.class.php @@ -210,6 +210,14 @@ public function testBaseSqlGeneration() '(- a)', Expression::minus('a')->toDialectString($dialect) ); + + try { + Expression::eq('id', null)->toDialectString($dialect); + + $this->fail(); + } catch (WrongArgumentException $e) { + //it's Ok + } } public function testPgGeneration() From b9ff40b0e78435d19e6450a99bb1e8ab5e5643b8 Mon Sep 17 00:00:00 2001 From: "Evgeniy V. Kokovikhin" Date: Wed, 11 Jan 2012 11:07:41 +0400 Subject: [PATCH 2/2] + changelog --- doc/ChangeLog | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/ChangeLog b/doc/ChangeLog index 5407f828ee..c19bd04dbc 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,8 @@ +2012-01-11 Evgeny V. Kokovikhin + + * core/DB/Dialect.class.php: throw exception for null values. Thanks to + Nikita V. Konstantinov. + 2011-11-21 Alexey S. Denisov, Evgeny V. Kokovikhin * meta/types/ObjectType.class.php, test/misc/DAOTest.class.php: changed logic