"WHERE column IS NOT NULL" with Kohana v3 Query Builder
Is it possible with Kohana v3 Query Builder to use the IS NOT NULL operator?
The where($column, $op, $value) method requires all three parameters and even if I specify
->where('col', 'IS开发者_JAVA技巧 NOT NULL', '')
it builds and invalid query eg.
SELECT * FROM table WHERE col IS NOT NULL '';
The operator is not escaped:
->where('col', 'IS NOT', NULL)
No need to use DB::expr, Kohana already supports what you want.
This works with the ORM module and is a little less typing.
->where('col', '!=', NULL);
Not sure (it's 3 AM right now) but ->where('col', '', DB::expr('IS NOT NULL'))
might works.
The WHERE clause takes 3 arguments, the 1st and 3rd which are always attempted to be converted to the backticks format (i.e. `table`.`field`). As long as you supply the DB::Expr on at least the 3rd argument, you can get away with leaving nothing in 1st and 2nd args and the following should work as well:
->where('', '', DB::Expr('!isNull(col)'));
This is confirmed to work on Kohana 3.2 and above.
This should work:
->where('col', '=', NULL);
精彩评论