summaryrefslogtreecommitdiff
path: root/test/sql
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2020-10-17 11:39:56 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2020-10-17 13:15:57 -0400
commit296c84313ab29bf9599634f38caaf7dd092e4e23 (patch)
treec354411cbb809544a9d471afbf35571e61886ded /test/sql
parent3179f70408cb91c7586fc2021959efb5b2fe9f0e (diff)
downloadsqlalchemy-296c84313ab29bf9599634f38caaf7dd092e4e23.tar.gz
Ensure escaping of percent signs in columns, parameters
Improved support for column names that contain percent signs in the string, including repaired issues involving anoymous labels that also embedded a column name with a percent sign in it, as well as re-established support for bound parameter names with percent signs embedded on the psycopg2 dialect, using a late-escaping process similar to that used by the cx_Oracle dialect. * Added new constructor for _anonymous_label() that ensures incoming string tokens based on column or table names will have percent signs escaped; abstracts away the format of the label. * generalized cx_Oracle's quoted_bind_names facility into the compiler itself, and leveraged this for the psycopg2 dialect's issue with percent signs in names as well. the parameter substitution is now integrated with compiler.construct_parameters() as well as the recently reworked set_input_sizes(), reducing verbosity in the cx_Oracle dialect. Fixes: #5653 Change-Id: Ia2ad13ea68b4b0558d410026e5a33f5cb3fbab2c
Diffstat (limited to 'test/sql')
-rw-r--r--test/sql/test_compiler.py18
-rw-r--r--test/sql/test_selectable.py2
2 files changed, 19 insertions, 1 deletions
diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py
index ffabf9379..ef2f75b2d 100644
--- a/test/sql/test_compiler.py
+++ b/test/sql/test_compiler.py
@@ -941,6 +941,24 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL):
"AS z FROM keyed) AS anon_2) AS anon_1",
)
+ @testing.combinations("per cent", "per % cent", "%percent")
+ def test_percent_names_collide_with_anonymizing(self, name):
+ table1 = table("t1", column(name))
+
+ jj = select(table1.c[name]).subquery()
+ jjj = join(table1, jj, table1.c[name] == jj.c[name])
+
+ j2 = jjj.select().apply_labels().subquery("foo")
+
+ self.assert_compile(
+ j2.select(),
+ 'SELECT foo."t1_%(name)s", foo."anon_1_%(name)s" FROM '
+ '(SELECT t1."%(name)s" AS "t1_%(name)s", anon_1."%(name)s" '
+ 'AS "anon_1_%(name)s" FROM t1 JOIN (SELECT t1."%(name)s" AS '
+ '"%(name)s" FROM t1) AS anon_1 ON t1."%(name)s" = '
+ 'anon_1."%(name)s") AS foo' % {"name": name},
+ )
+
def test_exists(self):
s = select(table1.c.myid).where(table1.c.myid == 5)
diff --git a/test/sql/test_selectable.py b/test/sql/test_selectable.py
index b98fbd3d0..c75e8886d 100644
--- a/test/sql/test_selectable.py
+++ b/test/sql/test_selectable.py
@@ -740,7 +740,7 @@ class SelectableTest(
assert u2.corresponding_column(s1.selected_columns.col1) is u2.c.col1
assert u2.corresponding_column(s2.selected_columns.col1) is u2.c.col1
- def test_foo(self):
+ def test_union_alias_misc(self):
s1 = select(table1.c.col1, table1.c.col2)
s2 = select(table1.c.col2, table1.c.col1)