Hi folks,

We've added a tweak/fix to db.where() to allow where(table_name, 
column=None) to do the "right thing". At present if you do that web.py will 
output "SELECT * FROM table_name WHERE column = NULL" which doesn't mean 
much (in SQL, NULL is not equal to anything, including other NULLs). What 
you meant was "WHERE column IS NULL".

So I've added a fix and doctest to where() as follows:

    def where(self, table, what='*', order=None, group=None, limit=None, 
              offset=None, _test=False, **kwargs):
        """
        Selects from `table` where keys are equal to values in `kwargs`.
        
            >>> db = DB(None, {})
            >>> db.where('foo', bar_id=3, _test=True)
            <sql: 'SELECT * FROM foo WHERE bar_id = 3'>
            >>> db.where('foo', source=2, crust='dewey', _test=True)
            <sql: "SELECT * FROM foo WHERE source = 2 AND crust = 'dewey'">
            >>> db.where('foo', source=None, _test=True)
            <sql: 'SELECT * FROM foo WHERE source IS NULL'>
        """
        where = []
        for k, v in kwargs.iteritems():
            if v is None:
                where.append(k + ' IS NULL')
            else:
                where.append(k + ' = ' + sqlquote(v))
        return self.select(table, what=what, order=order, 
               group=group, limit=limit, offset=offset, _test=_test, 
               where=SQLQuery.join(where, ' AND '))

-Ben

-- 
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/webpy?hl=en.

Reply via email to