Welcome Guest, Not a member yet? Register   Sign In
using NULL in a where statement
#1

[eluser]adamp1[/eluser]
I just tried to pass the following into a query
Code:
$this->db->update('Users',array('group'=>1),array('active'=>NULL));

Now this looks all good to me, but when I looked at the query which was being run I got this:
Code:
UPDATE `Users` SET `group` = `1` WHERE active IS NULL

The problem was active wasn't escaped. I then replaced it for `active` manually and it worked fine.

So looking into the active record code for _where I found the following lines
Code:
if ( ! is_null($v))
            {

                if ($escape === TRUE)
                {
                    // exception for "field<=" keys
                    if ($this->_has_operator($k))
                    {
                        $k =  preg_replace("/([A-Za-z_0-9]+)/", $this->_protect_identifiers('$1'), $k);
                    }
                    else
                    {
                        $k = $this->_protect_identifiers($k);
                    }
                }

                if ( ! $this->_has_operator($k))
                {
                    $k .= ' =';
                }
            
                $v = ' '.$this->escape($v);

            }

So as you can see only if the value is not NULL will it escape the column name.
#2

[eluser]Derek Allard[/eluser]
There have been a few commits to the where method, and while I don't think any specifically addressed this, I can't recreate your problem, so it might have been hit. Could you check the svn. Is the issue addressed?

Code:
$this->db->update('Users',array('group'=>1),array('active'=>NULL));
// currently gives me
UPDATE `Users` SET `group` = 1 WHERE `active` IS NULL
#3

[eluser]adamp1[/eluser]
Yes that fixes the problem I just checked the SVN. Thing is I don't like working on the SVN code (since I'm developing an application for the community) don't want to release with features which the public doesn't know about.
#4

[eluser]Derek Allard[/eluser]
OK, well in that case, just grab the updated _where() function.




Theme © iAndrew 2016 - Forum software by © MyBB