zzzeek / sqla_issue_test

1 stars 0 forks source link

Select against MySQL seems to ignore "!= None" parameter #227

Closed zzzeek closed 6 years ago

zzzeek commented 18 years ago

Originally reported by: Anonymous


Here's the mysql to create my table. Create it the database "cc" for my test code.

CREATE TABLE `simple` (
  `id` int(11) NOT NULL auto_increment,
  `license_uri` text NOT NULL,
  `search_engine` varchar(255) NOT NULL default  '',
  `count` bigint(20) NOT NULL default '0',
  `timestamp` datetime default NULL,
  `country` varchar(255) default NULL,
  `language` varchar(255) default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1

Here's an INSERT for testing:

INSERT INTO simple (license_uri) VALUES ('http://www.nevermind.com/');

Here's a SELECT to show it got inserted:

SELECT timestamp, count, license_uri FROM simple WHERE license_uri = 'http://www.nevermind.com/';

You'll see timestamp is NULL. Okay, now let's use sqlsoup to select from the table.

Demo code:

# Set up data
from sqlalchemy.ext.sqlsoup import SqlSoup
from sqlalchemy import *
db = SqlSoup('mysql://root:@localhost/cc')
everything = db.simple.select(and_(db.simple.timestamp != None, db.simple.c.license_uri == 'http://www.nevermind.com/'))
for thing in everything:
    if thing.timestamp == None:
        print "BUG!"

This prints "BUG!". It should not; no rows where timestamp == None should ever be returned.


zzzeek commented 18 years ago

Original comment by Michael Bayer (Bitbucket: zzzeek, GitHub: zzzeek):


reopen this when u figure it out. might want to determine if the issue is with SqlSoup or with straight SQL too.

zzzeek commented 18 years ago

Original comment by Anonymous:


Er, the sample code doesn't work. You can close this until I figure out working minimal sample code. Sorry. . . .