sqlite where = ? w/ string fails

Bug #709527 reported by Matt Haggard
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Storm
Invalid
Undecided
Unassigned

Bug Description

This test fails on my computer. OS X, Python 2.6.1
I'm gonna attach this bug to a branch once I figure out how to do it.

Related branches

Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :

Which test? Please describe the problem here.

Revision history for this message
Matt Haggard (iffy) wrote :

diff --git a/tests/databases/base.py b/tests/databases/base.py
index 0802271..a9194dc 100644
--- a/tests/databases/base.py
+++ b/tests/databases/base.py
@@ -163,6 +163,11 @@ class DatabaseTest(object):
         result = self.connection.execute(Select(SQLRaw("1")))
         self.assertTrue(result.get_one(), (1,))

+ def test_execute_where_string(self):
+ result = self.connection.execute("SELECT * FROM test WHERE "
+ "title = ?", ('Title 10',))
+ self.assertEquals(result.get_one(), (10, "Title 10"))
+
     def test_get_one(self):
         result = self.connection.execute("SELECT * FROM test ORDER BY id")
         self.assertEquals(result.get_one(), (10, "Title 10"))

Revision history for this message
Matt Haggard (iffy) wrote :

The formatting on my last comment is off.

All I'm doing is selecting with a where var = ? where the var is a string.

Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :

What is the error message you are getting?

It works for me:

>>> from storm.locals import *
>>> db = create_database("sqlite:memory")
>>> s = Store(db)
>>> s.execute("SELECT ?", ('foo',)).get_all()
[('foo',)]

Revision history for this message
James Henstridge (jamesh) wrote :

Matt: do you still get the error if you interpolate a unicode string instead of a byte string?

Storm treats byte strings as binary data and unicode strings as text. By the look of it, that database column is defined as text, so won't compare equal to a binary value.

Revision history for this message
James Henstridge (jamesh) wrote :

Just to follow up, consider the following example:

    >>> from storm.locals import *
    >>> db = create_database("sqlite:memory")
    >>> store = Store(db)
    >>> store.execute("SELECT ? = ?", ('foo', u'foo')).get_one()
    (0,)

Revision history for this message
Matt Haggard (iffy) wrote :

James: It was the unicode. I apologize for the buggy bug -- I thought I had tried with unicode and seen the same result.

>>> from storm.locals import *
>>> db = create_database('sqlite:?synchronous=OFF&timeout=0')
>>> s = Store(db)
>>> s.execute("CREATE TABLE test (id INTEGER PRIMARY KEY, title VARCHAR)")
<storm.databases.sqlite.SQLiteResult object at 0x10123cc50>
>>> s.execute("INSERT INTO test VALUES (10, 'foo')")
<storm.databases.sqlite.SQLiteResult object at 0x10123cc90>
>>> s.commit()
>>>
>>> r = s.execute("SELECT * FROM test WHERE title = ?", (u'foo',))
>>>
>>> a = r.get_one()
>>> print a
(10, u'foo')
>>> assert a == (10, 'foo')
>>>

Stuart Bishop (stub)
Changed in storm:
status: New → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.