From 40d5a32e59a49075129211358f00e857dac73885 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 15 Nov 2010 12:40:55 -0500 Subject: [PATCH] - Added a bind processor for booleans which coerces to int, for DBAPIs such as pymssql that naively call str() on values. --- CHANGES | 4 ++++ lib/sqlalchemy/processors.py | 6 ++++++ lib/sqlalchemy/types.py | 6 ++++++ 3 files changed, 16 insertions(+) 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 -- 2.47.3