From: Mike Bayer Date: Mon, 15 Nov 2010 17:40:55 +0000 (-0500) Subject: - Added a bind processor for booleans which coerces X-Git-Tag: rel_0_7b1~266 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=40d5a32e59a49075129211358f00e857dac73885;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - Added a bind processor for booleans which coerces to int, for DBAPIs such as pymssql that naively call str() on values. --- diff --git a/CHANGES b/CHANGES index a6fd7009ec..c2107364f4 100644 --- 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 diff --git a/lib/sqlalchemy/processors.py b/lib/sqlalchemy/processors.py index e73e26456e..88dabe87c3 100644 --- a/lib/sqlalchemy/processors.py +++ b/lib/sqlalchemy/processors.py @@ -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, \ diff --git a/lib/sqlalchemy/types.py b/lib/sqlalchemy/types.py index 9f322d1eb5..111f2314bf 100644 --- a/lib/sqlalchemy/types.py +++ b/lib/sqlalchemy/types.py @@ -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