]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Columns can again contain percent signs within their
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 23 Dec 2008 01:22:54 +0000 (01:22 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 23 Dec 2008 01:22:54 +0000 (01:22 +0000)
names. [ticket:1256]

CHANGES
lib/sqlalchemy/sql/compiler.py
test/sql/select.py

diff --git a/CHANGES b/CHANGES
index 55521e4ef08c89d486397234509c865ee3e01c9f..615d91120773ddd9f1b779c62f31c6d981e0e4c1 100644 (file)
--- 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 
index 921d932d2f388d6a539f110a7bb86176d2c21236..39e3dbfd7f9add02c65b423c4f47ddd03a8cc32e 100644 (file)
@@ -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)
index 12c8524cf8f127508ddde650c3dbd9488b9155f4..ea9f27cdf2dd06dcf124f774619e228d9b4b953b 100644 (file)
@@ -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(),