behavior. [ticket:1243]
- postgres
+ - "%" signs in text() constructs are automatically escaped to "%%".
+ Because of the backwards incompatible nature of this change,
+ a warning is emitted if '%%' is detected in the string. [ticket:1267]
+
- Calling alias.execute() in conjunction with
server_side_cursors won't raise AttributeError.
convert_unicode=True flags. [ticket:1233]
- mysql
+ - "%" signs in text() constructs are automatically escaped to "%%".
+ Because of the backwards incompatible nature of this change,
+ a warning is emitted if '%%' is detected in the string.
+
- Fixed bug in exception raise when FK columns not present
during reflection. [ticket:1241]
return 'CAST(%s AS %s)' % (self.process(cast.clause), type_)
+ def post_process_text(self, text):
+ if '%%' in text:
+ util.warn("The SQLAlchemy MySQLDB dialect now automatically escapes '%' in text() expressions to '%%'.")
+ return text.replace('%', '%%')
+
def get_select_precolumns(self, select):
if isinstance(select._distinct, basestring):
return select._distinct.upper() + " "
def visit_typeclause(self, typeclause, **kwargs):
return typeclause.type.dialect_impl(self.dialect).get_col_spec()
+ def post_process_text(self, text):
+ return text
+
def visit_textclause(self, textclause, **kwargs):
if textclause.typemap is not None:
for colname, type_ in textclause.typemap.iteritems():
# un-escape any \:params
return BIND_PARAMS_ESC.sub(lambda m: m.group(1),
- BIND_PARAMS.sub(do_bindparam, textclause.text)
+ BIND_PARAMS.sub(do_bindparam, self.post_process_text(textclause.text))
)
def visit_null(self, null, **kwargs):
from sqlalchemy import exc, sql
from sqlalchemy.engine import default
from testlib import *
-
+from testlib.testing import eq_
class QueryTest(TestBase):
l.append(row)
self.assert_(len(l) == 2, "fetchmany(size=2) got %s rows" % len(l))
+ def test_like_ops(self):
+ users.insert().execute(
+ {'user_id':1, 'user_name':'apples'},
+ {'user_id':2, 'user_name':'oranges'},
+ {'user_id':3, 'user_name':'bananas'},
+ {'user_id':4, 'user_name':'legumes'},
+ {'user_id':5, 'user_name':'hi % there'},
+ )
+
+ for expr, result in (
+ (select([users.c.user_id]).where(users.c.user_name.startswith('apple')), [(1,)]),
+ (select([users.c.user_id]).where(users.c.user_name.contains('i % t')), [(5,)]),
+ (select([users.c.user_id]).where(users.c.user_name.endswith('anas')), [(3,)]),
+ ):
+ eq_(expr.execute().fetchall(), result)
+
+
+ @testing.emits_warning('.*now automatically escapes.*')
+ def test_percents_in_text(self):
+ for expr, result in (
+ (text("select 6 % 10"), 6),
+ (text("select 17 % 10"), 7),
+ (text("select '%'"), '%'),
+ (text("select '%%'"), '%%'),
+ (text("select '%%%'"), '%%%'),
+ (text("select 'hello % world'"), "hello % world")
+ ):
+ eq_(testing.db.scalar(expr), result)
+
def test_ilike(self):
users.insert().execute(
{'user_id':1, 'user_name':'one'},