diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-11-28 11:52:24 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-11-28 11:52:24 -0500 |
commit | 134d78c8b44c40102afb030e6284a9d1e6acb65a (patch) | |
tree | a51f5b94f569d438e84758883d84415edb164b0a | |
parent | ac5d11afb3fa601d3194bbe8c087c568608985fa (diff) | |
download | sqlalchemy-134d78c8b44c40102afb030e6284a9d1e6acb65a.tar.gz |
- 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]
-rw-r--r-- | lib/sqlalchemy/sql/compiler.py | 2 | ||||
-rw-r--r-- | 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 8ca510e13..eb339cf1d 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 1fb22f289..d0e8af81d 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 |