summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/postgresql/hstore.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2013-05-29 18:08:28 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2013-05-29 18:08:28 -0400
commit534e05888e1ec7018c03d979df4f34074a61f12b (patch)
tree45ca244b99ea893fbff553b47caa46915574e914 /lib/sqlalchemy/dialects/postgresql/hstore.py
parent9fc6201f0c039631de436d38d7b162f56f9b08dd (diff)
downloadsqlalchemy-534e05888e1ec7018c03d979df4f34074a61f12b.tar.gz
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....
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/hstore.py')
-rw-r--r--lib/sqlalchemy/dialects/postgresql/hstore.py36
1 files changed, 26 insertions, 10 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/hstore.py b/lib/sqlalchemy/dialects/postgresql/hstore.py
index adfb82da7..b0b13eb0e 100644
--- a/lib/sqlalchemy/dialects/postgresql/hstore.py
+++ b/lib/sqlalchemy/dialects/postgresql/hstore.py
@@ -262,19 +262,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