summaryrefslogtreecommitdiff
path: root/test/dialect/test_postgresql.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2013-06-28 11:35:57 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2013-06-28 11:35:57 -0400
commit04b66bc5e7b8e8e93d78e9c70a533cd39e367aaf (patch)
tree5e014b0285328cc1e8b8db0e669326a23cc6a0d0 /test/dialect/test_postgresql.py
parentfc348366f76bdb3072c69ad8e03f305de38d486c (diff)
downloadsqlalchemy-04b66bc5e7b8e8e93d78e9c70a533cd39e367aaf.tar.gz
Fixed bug in HSTORE type where keys/values that contained
backslashed quotes would not be escaped correctly when using the "non native" (i.e. non-psycopg2) means of translating HSTORE data. Patch courtesy Ryan Kelly. [ticket:2766]
Diffstat (limited to 'test/dialect/test_postgresql.py')
-rw-r--r--test/dialect/test_postgresql.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/test/dialect/test_postgresql.py b/test/dialect/test_postgresql.py
index 46a7b316b..ba42015e8 100644
--- a/test/dialect/test_postgresql.py
+++ b/test/dialect/test_postgresql.py
@@ -2948,6 +2948,16 @@ class HStoreTest(fixtures.TestBase):
'"key1"=>"value1", "key2"=>"value2"'
)
+ def test_bind_serialize_with_slashes_and_quotes(self):
+ from sqlalchemy.engine import default
+
+ dialect = default.DefaultDialect()
+ proc = self.test_table.c.hash.type._cached_bind_processor(dialect)
+ eq_(
+ proc({'\\"a': '\\"1'}),
+ '"\\\\\\"a"=>"\\\\\\"1"'
+ )
+
def test_parse_error(self):
from sqlalchemy.engine import default
@@ -2974,6 +2984,17 @@ class HStoreTest(fixtures.TestBase):
{"key1": "value1", "key2": "value2"}
)
+ def test_result_deserialize_with_slashes_and_quotes(self):
+ from sqlalchemy.engine import default
+
+ dialect = default.DefaultDialect()
+ proc = self.test_table.c.hash.type._cached_result_processor(
+ dialect, None)
+ eq_(
+ proc('"\\\\\\"a"=>"\\\\\\"1"'),
+ {'\\"a': '\\"1'}
+ )
+
def test_bind_serialize_psycopg2(self):
from sqlalchemy.dialects.postgresql import psycopg2
@@ -3288,6 +3309,22 @@ class HStoreRoundTripTest(fixtures.TablesTest):
engine = testing.db
self._test_unicode_round_trip(engine)
+ def test_escaped_quotes_round_trip_python(self):
+ engine = self._non_native_engine()
+ self._test_escaped_quotes_round_trip(engine)
+
+ @testing.only_on("postgresql+psycopg2")
+ def test_escaped_quotes_round_trip_native(self):
+ engine = testing.db
+ self._test_escaped_quotes_round_trip(engine)
+
+ def _test_escaped_quotes_round_trip(self, engine):
+ engine.execute(
+ self.tables.data_table.insert(),
+ {'name': 'r1', 'data': {r'key \"foo\"': r'value \"bar"\ xyz'}}
+ )
+ self._assert_data([{r'key \"foo\"': r'value \"bar"\ xyz'}])
+
class _RangeTypeMixin(object):
__requires__ = 'range_types',
__dialect__ = 'postgresql+psycopg2'