"WHERE column IS NOT NULL" with Kohana v3 Query Builder
Asked Answered
B

5

14

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 NOT NULL', '')

it builds and invalid query eg.

SELECT * FROM table WHERE col IS NOT NULL '';
Berberidaceous answered 26/9, 2010 at 0:50 Comment(2)
v3 is just fine. and you were so close! All you had to do, was move the NULL to the value argument: ->where('col', 'IS NOT', NULL)Middelburg
Now that v3 has better docs and I've had a chance to get used to it-- I'm enjoying it thoroughly.Berberidaceous
B
24

The operator is not escaped:

->where('col', 'IS NOT', NULL)

No need to use DB::expr, Kohana already supports what you want.

Burkett answered 22/1, 2011 at 23:58 Comment(0)
G
9

This works with the ORM module and is a little less typing.

->where('col', '!=', NULL);
Growth answered 26/9, 2010 at 4:16 Comment(0)
G
3

Not sure (it's 3 AM right now) but ->where('col', '', DB::expr('IS NOT NULL')) might works.

Gallant answered 26/9, 2010 at 0:54 Comment(3)
GENIUS. You sir, are a saint.Berberidaceous
I think it's better to put the 'IS NOT' as the second argument and the value just being NULL. Just like Gerry answered. Using a DB::expr is nice, but adds unnecessary extra overhead (in this case)Middelburg
Yeah the best solution is ->where('col', 'IS NOT', NULL)Berberidaceous
O
0

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.

Openhearted answered 3/10, 2014 at 6:14 Comment(0)
S
-1

This should work:

->where('col', '=', NULL);
Slover answered 27/9, 2010 at 5:30 Comment(1)
That's checking of the value is null, OP wanted is not null.Growth

© 2022 - 2024 — McMap. All rights reserved.