From: Michael Trier Date: Tue, 5 May 2009 00:36:37 +0000 (+0000) Subject: Corrected the SQLite SLBoolean type so that it properly treats 1 only as True. Fixes... X-Git-Tag: rel_0_5_4~11 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=01cdbd073469240065dc0f5c224eaf90f4e113ac;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Corrected the SQLite SLBoolean type so that it properly treats 1 only as True. Fixes #1402 --- diff --git a/CHANGES b/CHANGES index e950ca0a1f..5d415a01b3 100644 --- a/CHANGES +++ b/CHANGES @@ -90,6 +90,9 @@ CHANGES since it is only used by mssql now. [ticket:1343] - sqlite + - Corrected the SLBoolean type so that it properly treats only 1 + as True. [ticket:1402] + - Corrected the float type so that it correctly maps to a SLFloat type when being reflected. [ticket:1273] diff --git a/lib/sqlalchemy/databases/sqlite.py b/lib/sqlalchemy/databases/sqlite.py index 4abbe80cdb..8952b2b1da 100644 --- a/lib/sqlalchemy/databases/sqlite.py +++ b/lib/sqlalchemy/databases/sqlite.py @@ -302,7 +302,7 @@ class SLBoolean(sqltypes.Boolean): def process(value): if value is None: return None - return value and True or False + return value == 1 return process colspecs = { diff --git a/test/dialect/sqlite.py b/test/dialect/sqlite.py index 03e7ecdf35..d01be3521d 100644 --- a/test/dialect/sqlite.py +++ b/test/dialect/sqlite.py @@ -11,6 +11,28 @@ from testlib import * class TestTypes(TestBase, AssertsExecutionResults): __only_on__ = 'sqlite' + def test_boolean(self): + """Test that the boolean only treats 1 as True + + """ + + meta = MetaData(testing.db) + t = Table('bool_table', meta, + Column('id', Integer, primary_key=True), + Column('boo', sqlite.SLBoolean)) + + try: + meta.create_all() + testing.db.execute("INSERT INTO bool_table (id, boo) VALUES (1, 'false');") + testing.db.execute("INSERT INTO bool_table (id, boo) VALUES (2, 'true');") + testing.db.execute("INSERT INTO bool_table (id, boo) VALUES (3, '1');") + testing.db.execute("INSERT INTO bool_table (id, boo) VALUES (4, '0');") + testing.db.execute("INSERT INTO bool_table (id, boo) VALUES (5, 1);") + testing.db.execute("INSERT INTO bool_table (id, boo) VALUES (6, 0);") + assert t.select(t.c.boo).order_by(t.c.id).execute().fetchall() == [(3, True,), (5, True,)] + finally: + meta.drop_all() + def test_string_dates_raise(self): self.assertRaises(TypeError, testing.db.execute, select([1]).where(bindparam("date", type_=Date)), date=str(datetime.date(2007, 10, 30)))