Commits

Michael Trier  committed 911ed16

Corrected the SQLite SLBoolean type so that it properly treats 1 only as True. Fixes #1402

  • Participants
  • Parent commits 0095a03

Comments (0)

Files changed (3)

       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]
 

File lib/sqlalchemy/databases/sqlite.py

         def process(value):
             if value is None:
                 return None
-            return value and True or False
+            return value == 1
         return process
 
 colspecs = {

File test/dialect/sqlite.py

 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)))