]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- post_process_text() is called for DDL() constructs, in particular allowing
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 28 Nov 2010 16:52:24 +0000 (11:52 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 28 Nov 2010 16:52:24 +0000 (11:52 -0500)
'%' with only one level of escaping.  Note this is backwards-incompatible
with previously triple-escaped sections.  [ticket:1897]

lib/sqlalchemy/sql/compiler.py
test/engine/test_ddlevents.py

index 8ca510e131ae5da68ea7c5a2edd0d4cab9c23f6c..eb339cf1d454e23c7a40671bc7a66f618e93d104 100644 (file)
@@ -1129,7 +1129,7 @@ class DDLCompiler(engine.Compiled):
             context.setdefault('schema', sch)
             context.setdefault('fullname', preparer.format_table(ddl.target))
         
-        return ddl.statement % context
+        return self.sql_compiler.post_process_text(ddl.statement % context)
 
     def visit_create_table(self, create):
         table = create.element
index 1fb22f28975de22c30776982b21ba781717ba8b7..d0e8af81dfa04cf394a9ca6d65272405ef8a3993 100644 (file)
@@ -2,12 +2,12 @@ from sqlalchemy.test.testing import assert_raises, assert_raises_message
 from sqlalchemy.schema import DDL, CheckConstraint, AddConstraint, \
     DropConstraint
 from sqlalchemy import create_engine
-from sqlalchemy import MetaData, Integer, String, event, exc
+from sqlalchemy import MetaData, Integer, String, event, exc, text
 from sqlalchemy.test.schema import Table
 from sqlalchemy.test.schema import Column
 import sqlalchemy as tsa
 from sqlalchemy.test import TestBase, testing, engines
-from sqlalchemy.test.testing import AssertsCompiledSQL
+from sqlalchemy.test.testing import AssertsCompiledSQL, eq_
 from nose import SkipTest
 
 class DDLEventTest(TestBase):
@@ -404,6 +404,30 @@ class DDLExecutionTest(TestBase):
                 r = eval(py)
                 assert list(r) == [(1,)], py
 
+    @testing.fails_on('postgresql+pg8000', 'pg8000 requires explicit types')
+    def test_platform_escape(self):
+        """test the escaping of % characters in the DDL construct."""
+        
+        default_from = testing.db.dialect.statement_compiler(
+                            testing.db.dialect, DDL("")).default_from()
+        
+        eq_(
+            testing.db.execute(
+                text("select 'foo%something'" + default_from)
+            ).scalar(),
+            'foo%something'
+        )
+    
+        eq_(
+            testing.db.execute(
+                DDL("select 'foo%%something'" + default_from)
+            ).scalar(),
+            'foo%something'
+        )
+    
+
+        
+        
 class DDLTest(TestBase, AssertsCompiledSQL):
     def mock_engine(self):
         executor = lambda *a, **kw: None