From bb1dd85dcc123a60ab5fdc0d3a61641703d91948 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 4 Feb 2008 21:47:42 +0000 Subject: [PATCH] - add dummy column to appease older SQLite verisons in unicode.py - add test "escape_literal_column" comiler method to start addressing literal '%' character --- lib/sqlalchemy/sql/compiler.py | 8 ++++++-- test/sql/unicode.py | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 71bfd17658..5cfb42a631 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -269,16 +269,20 @@ class DefaultCompiler(engine.Compiled): return None elif column.table is None or not column.table.named_with_column: if getattr(column, "is_literal", False): - return name + return self.escape_literal_column(name) else: return self.preparer.quote(column, name) else: if getattr(column, "is_literal", False): - return self.preparer.quote(column.table, ANONYMOUS_LABEL.sub(self._process_anon, column.table.name)) + "." + name + return self.preparer.quote(column.table, ANONYMOUS_LABEL.sub(self._process_anon, column.table.name)) + "." + self.escape_literal_column(name) else: return self.preparer.quote(column.table, ANONYMOUS_LABEL.sub(self._process_anon, column.table.name)) + "." + self.preparer.quote(column, name) + def escape_literal_column(self, text): + """provide escaping for the literal_column() construct.""" + return re.sub('%', '%%', text) + def visit_fromclause(self, fromclause, **kwargs): return fromclause.name diff --git a/test/sql/unicode.py b/test/sql/unicode.py index 98a2b6aa2b..6f035f2bfc 100644 --- a/test/sql/unicode.py +++ b/test/sql/unicode.py @@ -116,7 +116,9 @@ class EscapesDefaultsTest(testing.PersistTest): def test_default_exec(self): metadata = MetaData(testing.db) t1 = Table('t1', metadata, - Column(u'special_col', Integer, Sequence('special_col'), primary_key=True)) + Column(u'special_col', Integer, Sequence('special_col'), primary_key=True), + Column('data', String(50)) # to appease SQLite without DEFAULT VALUES + ) t1.create() try: -- 2.47.3