From 134d78c8b44c40102afb030e6284a9d1e6acb65a Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 28 Nov 2010 11:52:24 -0500 Subject: [PATCH] - post_process_text() is called for DDL() constructs, in particular allowing '%' with only one level of escaping. Note this is backwards-incompatible with previously triple-escaped sections. [ticket:1897] --- lib/sqlalchemy/sql/compiler.py | 2 +- test/engine/test_ddlevents.py | 28 ++++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 8ca510e131..eb339cf1d4 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -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 diff --git a/test/engine/test_ddlevents.py b/test/engine/test_ddlevents.py index 1fb22f2897..d0e8af81df 100644 --- a/test/engine/test_ddlevents.py +++ b/test/engine/test_ddlevents.py @@ -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 -- 2.47.2