From f87c9d8167606da7f0bcd5d8e3f2f96be38c7100 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 29 May 2013 18:08:28 -0400 Subject: hstores are text, and in py3k they seem to be implcitly unicode. so add unicode encoding for py2k for the non-native hstore, pullreq for native psycopg2 support coming.... --- lib/sqlalchemy/dialects/postgresql/hstore.py | 36 ++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'lib/sqlalchemy/dialects/postgresql') diff --git a/lib/sqlalchemy/dialects/postgresql/hstore.py b/lib/sqlalchemy/dialects/postgresql/hstore.py index e555a1afd..b2150bc44 100644 --- a/lib/sqlalchemy/dialects/postgresql/hstore.py +++ b/lib/sqlalchemy/dialects/postgresql/hstore.py @@ -260,19 +260,35 @@ class HSTORE(sqltypes.Concatenable, sqltypes.TypeEngine): _adapt_expression(self, op, other_comparator) def bind_processor(self, dialect): - def process(value): - if isinstance(value, dict): - return _serialize_hstore(value) - else: - return value + if util.py2k: + encoding = dialect.encoding + def process(value): + if isinstance(value, dict): + return _serialize_hstore(value).encode(encoding) + else: + return value + else: + def process(value): + if isinstance(value, dict): + return _serialize_hstore(value) + else: + return value return process def result_processor(self, dialect, coltype): - def process(value): - if value is not None: - return _parse_hstore(value) - else: - return value + if util.py2k: + encoding = dialect.encoding + def process(value): + if value is not None: + return _parse_hstore(value.decode(encoding)) + else: + return value + else: + def process(value): + if value is not None: + return _parse_hstore(value) + else: + return value return process -- cgit v1.2.1