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 '';
laurent
  • 88,262
  • 77
  • 290
  • 428
MeatFlavourDev
  • 1,149
  • 1
  • 11
  • 22
  • 3
    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)` – SpadXIII Sep 27 '10 at 08:46
  • Now that v3 has better docs and I've had a chance to get used to it-- I'm enjoying it thoroughly. – MeatFlavourDev Apr 03 '11 at 10:25

5 Answers5

24

The operator is not escaped:

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

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

shadowhand
  • 3,202
  • 19
  • 23
9

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

->where('col', '!=', NULL);
Gerry Shaw
  • 9,178
  • 5
  • 41
  • 45
3

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

Crozin
  • 43,890
  • 13
  • 88
  • 135
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.

pogeybait
  • 3,065
  • 2
  • 21
  • 23
-1

This should work:

->where('col', '=', NULL);
biakaveron
  • 5,493
  • 1
  • 16
  • 20