summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/sqlalchemy/sql/compiler.py3
-rw-r--r--test/sql/select.py22
2 files changed, 13 insertions, 12 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py
index 5cfb42a63..cdb680431 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -281,7 +281,8 @@ class DefaultCompiler(engine.Compiled):
def escape_literal_column(self, text):
"""provide escaping for the literal_column() construct."""
- return re.sub('%', '%%', text)
+ # TODO: some dialects might need different behavior here
+ return text.replace('%', '%%')
def visit_fromclause(self, fromclause, **kwargs):
return fromclause.name
diff --git a/test/sql/select.py b/test/sql/select.py
index 9d561eb2d..69d39ede6 100644
--- a/test/sql/select.py
+++ b/test/sql/select.py
@@ -440,29 +440,29 @@ sq.myothertable_othername AS sq_myothertable_othername FROM (" + sqstring + ") A
def test_composed_string_comparators(self):
self.assert_compile(
- table1.c.name.contains('jo'), "mytable.name LIKE '%' || :mytable_name_1 || '%'" , checkparams = {'mytable_name_1': u'jo'},
+ table1.c.name.contains('jo'), "mytable.name LIKE '%%' || :mytable_name_1 || '%%'" , checkparams = {'mytable_name_1': u'jo'},
)
self.assert_compile(
- table1.c.name.contains('jo'), "mytable.name LIKE concat(concat('%', %s), '%')" , checkparams = {'mytable_name_1': u'jo'},
+ table1.c.name.contains('jo'), "mytable.name LIKE concat(concat('%%', %s), '%%')" , checkparams = {'mytable_name_1': u'jo'},
dialect=mysql.dialect()
)
self.assert_compile(
- table1.c.name.endswith('hn'), "mytable.name LIKE '%' || :mytable_name_1", checkparams = {'mytable_name_1': u'hn'},
+ table1.c.name.endswith('hn'), "mytable.name LIKE '%%' || :mytable_name_1", checkparams = {'mytable_name_1': u'hn'},
)
self.assert_compile(
- table1.c.name.endswith('hn'), "mytable.name LIKE concat('%', %s)",
+ table1.c.name.endswith('hn'), "mytable.name LIKE concat('%%', %s)",
checkparams = {'mytable_name_1': u'hn'}, dialect=mysql.dialect()
)
self.assert_compile(
- table1.c.name.startswith(u"hi \xf6 \xf5"), "mytable.name LIKE :mytable_name_1 || '%'",
+ table1.c.name.startswith(u"hi \xf6 \xf5"), "mytable.name LIKE :mytable_name_1 || '%%'",
checkparams = {'mytable_name_1': u'hi \xf6 \xf5'},
)
- self.assert_compile(column('name').endswith(text("'foo'")), "name LIKE '%' || 'foo'" )
- self.assert_compile(column('name').endswith(literal_column("'foo'")), "name LIKE '%' || 'foo'" )
- self.assert_compile(column('name').startswith(text("'foo'")), "name LIKE 'foo' || '%'" )
- self.assert_compile(column('name').startswith(text("'foo'")), "name LIKE concat('foo', '%')", dialect=mysql.dialect())
- self.assert_compile(column('name').startswith(literal_column("'foo'")), "name LIKE 'foo' || '%'" )
- self.assert_compile(column('name').startswith(literal_column("'foo'")), "name LIKE concat('foo', '%')", dialect=mysql.dialect())
+ self.assert_compile(column('name').endswith(text("'foo'")), "name LIKE '%%' || 'foo'" )
+ self.assert_compile(column('name').endswith(literal_column("'foo'")), "name LIKE '%%' || 'foo'" )
+ self.assert_compile(column('name').startswith(text("'foo'")), "name LIKE 'foo' || '%%'" )
+ self.assert_compile(column('name').startswith(text("'foo'")), "name LIKE concat('foo', '%%')", dialect=mysql.dialect())
+ self.assert_compile(column('name').startswith(literal_column("'foo'")), "name LIKE 'foo' || '%%'" )
+ self.assert_compile(column('name').startswith(literal_column("'foo'")), "name LIKE concat('foo', '%%')", dialect=mysql.dialect())
def test_multiple_col_binds(self):
self.assert_compile(