]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Added a bind processor for booleans which coerces
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 15 Nov 2010 17:40:55 +0000 (12:40 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 15 Nov 2010 17:40:55 +0000 (12:40 -0500)
to int, for DBAPIs such as pymssql that naively call
str() on values.

CHANGES
lib/sqlalchemy/processors.py
lib/sqlalchemy/types.py

diff --git a/CHANGES b/CHANGES
index a6fd7009ec5ddead0fa4911b753c433955b02d6b..c2107364f494f3e97a28794e1fd585b4a30a95f7 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -32,6 +32,10 @@ CHANGES
   - The 'info' attribute of Column is copied during 
     Column.copy(), i.e. as occurs when using columns
     in declarative mixins.  [ticket:1967]
+
+  - Added a bind processor for booleans which coerces
+    to int, for DBAPIs such as pymssql that naively call 
+    str() on values.
     
 - engine
   - Implemented sequence check capability for the C 
index e73e26456e98f8b203b94abadfd553e2a457e254..88dabe87c394da6a8ccdaf55c28e175f2bfd3fba 100644 (file)
@@ -26,6 +26,12 @@ def str_to_datetime_processor_factory(regexp, type_):
             return type_(*map(int, rmatch(value).groups(0)))
     return process
 
+def boolean_to_int(value):
+    if value is None:
+        return None
+    else:
+        return int(value)
+
 try:
     from sqlalchemy.cprocessors import UnicodeResultProcessor, \
                                        DecimalResultProcessor, \
index 9f322d1eb584e2c30abf852bf2ebbf551fbf830e..111f2314bfa62b05bf88bf53e45fa44192905e5d 100644 (file)
@@ -1682,6 +1682,12 @@ class Boolean(TypeEngine, SchemaType):
                     )
         table.append_constraint(e)
     
+    def bind_processor(self, dialect):
+        if dialect.supports_native_boolean:
+            return None
+        else:
+            return processors.boolean_to_int
+        
     def result_processor(self, dialect, coltype):
         if dialect.supports_native_boolean:
             return None