[eluser]drewbee[/eluser]
That is what I get for assuming. Huji is correct in this one gentlemen.
You can see the check in the function _where in the db_active_record.php file.
Code:
if (is_null($v) && ! $this->_has_operator($k))
{
// value appears not to have been set, assign the test to IS NULL
$k .= ' IS NULL';
}
So... this works:
Code:
$where = array('forum_id' => null);
$this->db->where($where, FALSE);
$this->db->get('forum');
Outputs : SELECT * FROM (`forum`) WHERE `forum_id` IS NULL
We can do the positive check, however we cannot do the negative
None of the following work:
Code:
$where = array('forum_id IS NOT' => null);
$where = array('forum_id !=' => null);
After digging through active record, and finding the following function _has_operator in DB_driver.php the function called above uses this:
Code:
function _has_operator($str)
{
$str = trim($str);
if ( ! preg_match("/(\s|<|>|!|=|is null|is not null)/i", $str))
{
return FALSE;
}
return TRUE;
}
To properly check against not null, we do the following, and can also do the following for IS NULL as well:
Code:
$where = array('forum_id IS NULL' => null,
'forum_id IS NOT NULL' => null);
$this->db->get('forum');
Outputs: SELECT * FROM (`forum`) WHERE `forum_id` IS NULL AND `forum_id` IS NOT NULL
Granted, I would expect it to more work like this:
Code:
$where = array('forum_id IS' => null,
'forum_id IS NOT' => null);
You would simply have to change the code in _has_operator and _where accordingly.