summaryrefslogtreecommitdiff
path: root/test/sql/test_operators.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/sql/test_operators.py')
-rw-r--r--test/sql/test_operators.py125
1 files changed, 111 insertions, 14 deletions
diff --git a/test/sql/test_operators.py b/test/sql/test_operators.py
index 03c0f89be..584fb12d5 100644
--- a/test/sql/test_operators.py
+++ b/test/sql/test_operators.py
@@ -15,7 +15,7 @@ from sqlalchemy.sql.elements import _literal_as_text
from sqlalchemy.schema import Column, Table, MetaData
from sqlalchemy.sql import compiler
from sqlalchemy.types import TypeEngine, TypeDecorator, UserDefinedType, \
- Boolean, NullType, MatchType, Indexable, Concatenable, Array
+ Boolean, MatchType, Indexable, Concatenable, Array
from sqlalchemy.dialects import mysql, firebird, postgresql, oracle, \
sqlite, mssql
from sqlalchemy import util
@@ -1995,9 +1995,16 @@ class ComposedLikeOperatorsTest(fixtures.TestBase, testing.AssertsCompiledSQL):
def test_contains_escape(self):
self.assert_compile(
- column('x').contains('y', escape='\\'),
+ column('x').contains('a%b_c', escape='\\'),
"x LIKE '%%' || :x_1 || '%%' ESCAPE '\\'",
- checkparams={'x_1': 'y'}
+ checkparams={'x_1': 'a%b_c'}
+ )
+
+ def test_contains_autoescape(self):
+ self.assert_compile(
+ column('x').contains('a%b_c', autoescape='\\'),
+ "x LIKE '%%' || :x_1 || '%%' ESCAPE '\\'",
+ checkparams={'x_1': 'a\\%b\\_c'}
)
def test_contains_literal(self):
@@ -2023,9 +2030,16 @@ class ComposedLikeOperatorsTest(fixtures.TestBase, testing.AssertsCompiledSQL):
def test_not_contains_escape(self):
self.assert_compile(
- ~column('x').contains('y', escape='\\'),
+ ~column('x').contains('a%b_c', escape='\\'),
"x NOT LIKE '%%' || :x_1 || '%%' ESCAPE '\\'",
- checkparams={'x_1': 'y'}
+ checkparams={'x_1': 'a%b_c'}
+ )
+
+ def test_not_contains_autoescape(self):
+ self.assert_compile(
+ ~column('x').contains('a%b_c', autoescape='\\'),
+ "x NOT LIKE '%%' || :x_1 || '%%' ESCAPE '\\'",
+ checkparams={'x_1': 'a\\%b\\_c'}
)
def test_contains_concat(self):
@@ -2060,6 +2074,62 @@ class ComposedLikeOperatorsTest(fixtures.TestBase, testing.AssertsCompiledSQL):
dialect=mysql.dialect()
)
+ def test_like(self):
+ self.assert_compile(
+ column('x').like('y'),
+ "x LIKE :x_1",
+ checkparams={'x_1': 'y'}
+ )
+
+ def test_like_escape(self):
+ self.assert_compile(
+ column('x').like('a%b_c', escape='\\'),
+ "x LIKE :x_1 ESCAPE '\\'",
+ checkparams={'x_1': 'a%b_c'}
+ )
+
+ def test_ilike(self):
+ self.assert_compile(
+ column('x').ilike('y'),
+ "lower(x) LIKE lower(:x_1)",
+ checkparams={'x_1': 'y'}
+ )
+
+ def test_ilike_escape(self):
+ self.assert_compile(
+ column('x').ilike('a%b_c', escape='\\'),
+ "lower(x) LIKE lower(:x_1) ESCAPE '\\'",
+ checkparams={'x_1': 'a%b_c'}
+ )
+
+ def test_notlike(self):
+ self.assert_compile(
+ column('x').notlike('y'),
+ "x NOT LIKE :x_1",
+ checkparams={'x_1': 'y'}
+ )
+
+ def test_notlike_escape(self):
+ self.assert_compile(
+ column('x').notlike('a%b_c', escape='\\'),
+ "x NOT LIKE :x_1 ESCAPE '\\'",
+ checkparams={'x_1': 'a%b_c'}
+ )
+
+ def test_notilike(self):
+ self.assert_compile(
+ column('x').notilike('y'),
+ "lower(x) NOT LIKE lower(:x_1)",
+ checkparams={'x_1': 'y'}
+ )
+
+ def test_notilike_escape(self):
+ self.assert_compile(
+ column('x').notilike('a%b_c', escape='\\'),
+ "lower(x) NOT LIKE lower(:x_1) ESCAPE '\\'",
+ checkparams={'x_1': 'a%b_c'}
+ )
+
def test_startswith(self):
self.assert_compile(
column('x').startswith('y'),
@@ -2069,9 +2139,16 @@ class ComposedLikeOperatorsTest(fixtures.TestBase, testing.AssertsCompiledSQL):
def test_startswith_escape(self):
self.assert_compile(
- column('x').startswith('y', escape='\\'),
+ column('x').startswith('a%b_c', escape='\\'),
"x LIKE :x_1 || '%%' ESCAPE '\\'",
- checkparams={'x_1': 'y'}
+ checkparams={'x_1': 'a%b_c'}
+ )
+
+ def test_startswith_autoescape(self):
+ self.assert_compile(
+ column('x').startswith('a%b_c', autoescape='\\'),
+ "x LIKE :x_1 || '%%' ESCAPE '\\'",
+ checkparams={'x_1': 'a\\%b\\_c'}
)
def test_not_startswith(self):
@@ -2083,9 +2160,16 @@ class ComposedLikeOperatorsTest(fixtures.TestBase, testing.AssertsCompiledSQL):
def test_not_startswith_escape(self):
self.assert_compile(
- ~column('x').startswith('y', escape='\\'),
+ ~column('x').startswith('a%b_c', escape='\\'),
"x NOT LIKE :x_1 || '%%' ESCAPE '\\'",
- checkparams={'x_1': 'y'}
+ checkparams={'x_1': 'a%b_c'}
+ )
+
+ def test_not_startswith_autoescape(self):
+ self.assert_compile(
+ ~column('x').startswith('a%b_c', autoescape='\\'),
+ "x NOT LIKE :x_1 || '%%' ESCAPE '\\'",
+ checkparams={'x_1': 'a\\%b\\_c'}
)
def test_startswith_literal(self):
@@ -2159,9 +2243,16 @@ class ComposedLikeOperatorsTest(fixtures.TestBase, testing.AssertsCompiledSQL):
def test_endswith_escape(self):
self.assert_compile(
- column('x').endswith('y', escape='\\'),
+ column('x').endswith('a%b_c', escape='\\'),
"x LIKE '%%' || :x_1 ESCAPE '\\'",
- checkparams={'x_1': 'y'}
+ checkparams={'x_1': 'a%b_c'}
+ )
+
+ def test_endswith_autoescape(self):
+ self.assert_compile(
+ column('x').endswith('a%b_c', autoescape='\\'),
+ "x LIKE '%%' || :x_1 ESCAPE '\\'",
+ checkparams={'x_1': 'a\\%b\\_c'}
)
def test_not_endswith(self):
@@ -2173,9 +2264,16 @@ class ComposedLikeOperatorsTest(fixtures.TestBase, testing.AssertsCompiledSQL):
def test_not_endswith_escape(self):
self.assert_compile(
- ~column('x').endswith('y', escape='\\'),
+ ~column('x').endswith('a%b_c', escape='\\'),
"x NOT LIKE '%%' || :x_1 ESCAPE '\\'",
- checkparams={'x_1': 'y'}
+ checkparams={'x_1': 'a%b_c'}
+ )
+
+ def test_not_endswith_autoescape(self):
+ self.assert_compile(
+ ~column('x').endswith('a%b_c', autoescape='\\'),
+ "x NOT LIKE '%%' || :x_1 ESCAPE '\\'",
+ checkparams={'x_1': 'a\\%b\\_c'}
)
def test_endswith_literal(self):
@@ -2413,4 +2511,3 @@ class AnyAllTest(fixtures.TestBase, testing.AssertsCompiledSQL):
"FROM tab1 WHERE tab1.data < :data_1)",
checkparams={'data_1': 10, 'param_1': 5}
)
-