]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Corrected the SQLite SLBoolean type so that it properly treats 1 only as True. Fixes...
authorMichael Trier <mtrier@gmail.com>
Tue, 5 May 2009 00:36:37 +0000 (00:36 +0000)
committerMichael Trier <mtrier@gmail.com>
Tue, 5 May 2009 00:36:37 +0000 (00:36 +0000)
CHANGES
lib/sqlalchemy/databases/sqlite.py
test/dialect/sqlite.py

diff --git a/CHANGES b/CHANGES
index e950ca0a1fa8203c2fce6952c661528d6f0935fb..5d415a01b3613d8ace2900a081f81e4a047afa47 100644 (file)
--- 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]
 
index 4abbe80cdb7d0a93f870fa2997de4fe9e9cc225d..8952b2b1da7507560674a8f4ce5f3f02085e31be 100644 (file)
@@ -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 = {
index 03e7ecdf35cfbe4d19c86a760faf85b0bce8e05a..d01be3521d4b786ee60c652ccb5bbaa233d5cb56 100644 (file)
@@ -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)))