summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES3
-rw-r--r--lib/sqlalchemy/sql/compiler.py5
-rw-r--r--test/sql/select.py14
3 files changed, 20 insertions, 2 deletions
diff --git a/CHANGES b/CHANGES
index 55521e4ef..615d91120 100644
--- a/CHANGES
+++ b/CHANGES
@@ -132,6 +132,9 @@ CHANGES
mapper since it's not needed.
- sql
+ - Columns can again contain percent signs within their
+ names. [ticket:1256]
+
- PickleType now favors == comparison by default,
if the incoming object (such as a dict) implements
__eq__(). If the object does not implement
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py
index 921d932d2..39e3dbfd7 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -407,11 +407,12 @@ class DefaultCompiler(engine.Compiled):
return bind_name
+ _trunc_re = re.compile(r'%\((\d+ \w+)\)s', re.U)
def _truncated_identifier(self, ident_class, name):
if (ident_class, name) in self.truncated_names:
return self.truncated_names[(ident_class, name)]
-
- anonname = name % self.anon_map
+
+ anonname = self._trunc_re.sub(lambda m: self.anon_map[m.group(1)], name)
if len(anonname) > self.label_length:
counter = self.truncated_names.get(ident_class, 1)
diff --git a/test/sql/select.py b/test/sql/select.py
index 12c8524cf..ea9f27cdf 100644
--- a/test/sql/select.py
+++ b/test/sql/select.py
@@ -835,6 +835,20 @@ FROM mytable, myothertable WHERE foo.id = foofoo(lala) AND datetime(foo) = Today
"SELECT concat(:param_1, :param_2) "
"COLLATE somecol AS x")
+ def test_percent_chars(self):
+ t = table("table",
+ column("percent%"),
+ column("%(oneofthese)s"),
+ column("spaces % more spaces"),
+ )
+ self.assert_compile(
+ t.select(use_labels=True),
+ '''SELECT "table"."percent%" AS "table_percent%", '''\
+ '''"table"."%(oneofthese)s" AS "table_%(oneofthese)s", '''\
+ '''"table"."spaces % more spaces" AS "table_spaces % more spaces" FROM "table"'''
+ )
+
+
def test_joins(self):
self.assert_compile(
join(table2, table1, table1.c.myid == table2.c.otherid).select(),