]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
fixed up boolean datatype for sqlite, mysql, ms-sql
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 13 Jul 2006 01:12:53 +0000 (01:12 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 13 Jul 2006 01:12:53 +0000 (01:12 +0000)
CHANGES
lib/sqlalchemy/databases/mssql.py
lib/sqlalchemy/databases/mysql.py
lib/sqlalchemy/databases/sqlite.py
test/sql/testtypes.py

diff --git a/CHANGES b/CHANGES
index 9db4d3efe3f82f4bce2f78055711749e7a2f68ce..acf61f87029d15e165501fd0d7d80ae481966cff 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -8,6 +8,7 @@ activated when activemapper is imported
 - 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
index 89cc883989a7f83fca5bba862643e323fb678e57..c297195caff6fd3fc8e6935a366d40f756788fb8 100644 (file)
@@ -143,6 +143,19 @@ class MSBinary(sqltypes.Binary):
 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,
index e152a483384a3c6782a26deff14601d0a8c69e4c..997010f1c233bcdce0275b3e3d6a79b770578836 100644 (file)
@@ -157,7 +157,7 @@ class MSBinary(sqltypes.Binary):
             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:
@@ -182,7 +182,20 @@ class MSEnum(sqltypes.String):
 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,
index 2b10a8ad93641a37264e13b89d30e207ebe6750a..c07952ff215c0e7d5e99f92ab73f3e9578aed95d 100644 (file)
@@ -79,6 +79,10 @@ class SLBinary(sqltypes.Binary):
 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,
index 71c98f105b119c6ad6771abb7d1e9dec5f81734e..9a25cbee500c5b8ea5ee11674545813e4595d7d0 100644 (file)
@@ -272,6 +272,32 @@ class DateTest(AssertMixin):
         
         #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()