diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2009-01-02 21:24:17 +0000 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2009-01-02 21:24:17 +0000 |
| commit | 5bc1f17cb53248e7cea609693a3b2a9bb702545b (patch) | |
| tree | e31a0341ecacd3115612fcebfc904f1549535465 /test/sql/query.py | |
| parent | 2f2d84fbb14f1282677de8fc1186da8f41081214 (diff) | |
| download | sqlalchemy-5bc1f17cb53248e7cea609693a3b2a9bb702545b.tar.gz | |
- mysql, 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]
Diffstat (limited to 'test/sql/query.py')
| -rw-r--r-- | test/sql/query.py | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/test/sql/query.py b/test/sql/query.py index e62dfa076..275bbe78c 100644 --- a/test/sql/query.py +++ b/test/sql/query.py @@ -4,7 +4,7 @@ from sqlalchemy import * from sqlalchemy import exc, sql from sqlalchemy.engine import default from testlib import * - +from testlib.testing import eq_ class QueryTest(TestBase): @@ -235,6 +235,35 @@ 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'}, |
