Commits

Mike Bayer committed db2b175

fixed up boolean datatype for sqlite, mysql, ms-sql

  • Participants
  • Parent commits 8b45d6b

Comments (0)

Files changed (5)

 - small fix to URL regexp to allow filenames with '@' in them
 - fixes to Session expunge/update/etc.
 - select_table mappers *still* werent always compiling
+- fixed up Boolean datatype
 
 0.2.5
 - fixed endless loop bug in select_by(), if the traversal hit

lib/sqlalchemy/databases/mssql.py

 class MSBoolean(sqltypes.Boolean):
     def get_col_spec(self):
         return "BIT"
+    def convert_result_value(self, value, dialect):
+        if value is None:
+            return None
+        return value and True or False
+    def convert_bind_param(self, value, dialect):
+        if value is True:
+            return 1
+        elif value is False:
+            return 0
+        elif value is None:
+            return None
+        else:
+            return value and True or False
         
 colspecs = {
     sqltypes.Integer : MSInteger,

lib/sqlalchemy/databases/mysql.py

             return "BINARY(%d)" % self.length
         else:
             return "BLOB"
-    def convert_result_value(self, value, engine):
+    def convert_result_value(self, value, dialect):
         if value is None:
             return None
         else:
 class MSBoolean(sqltypes.Boolean):
     def get_col_spec(self):
         return "BOOLEAN"
-        
+    def convert_result_value(self, value, dialect):
+        if value is None:
+            return None
+        return value and True or False
+    def convert_bind_param(self, value, dialect):
+        if value is True:
+            return 1
+        elif value is False:
+            return 0
+        elif value is None:
+            return None
+        else:
+            return value and True or False
+            
 colspecs = {
 #    sqltypes.BIGinteger : MSInteger,
     sqltypes.Integer : MSInteger,

lib/sqlalchemy/databases/sqlite.py

 class SLBoolean(sqltypes.Boolean):
     def get_col_spec(self):
         return "BOOLEAN"
+    def convert_result_value(self, value, dialect):
+        if value is None:
+            return None
+        return value and True or False
         
 colspecs = {
     sqltypes.Integer : SLInteger,

test/sql/testtypes.py

         
         #x = db.text("select * from query_users_with_date where user_datetime=:date", bindparams=[bindparam('date', )]).execute(date=datetime.datetime(2005, 11, 10, 11, 52, 35)).fetchall()
         #print repr(x)
+
+class BooleanTest(AssertMixin):
+    def setUpAll(self):
+        global bool_table
+        metadata = BoundMetaData(testbase.db)
+        bool_table = Table('booltest', metadata, 
+            Column('id', Integer, primary_key=True),
+            Column('value', Boolean))
+        bool_table.create()
+    def tearDownAll(self):
+        bool_table.drop()
+    def testbasic(self):
+        bool_table.insert().execute(id=1, value=True)
+        bool_table.insert().execute(id=2, value=False)
+        bool_table.insert().execute(id=3, value=True)
+        bool_table.insert().execute(id=4, value=True)
+        bool_table.insert().execute(id=5, value=True)
+        
+        res = bool_table.select(bool_table.c.value==True).execute().fetchall()
+        print res
+        assert(res==[(1, True),(3, True),(4, True),(5, True)])
+        
+        res2 = bool_table.select(bool_table.c.value==False).execute().fetchall()
+        print res2
+        assert(res2==[(2, False)])
+        
         
 if __name__ == "__main__":
     testbase.main()