summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCorey Zumar <corey.zumar@databricks.com>2019-12-26 00:59:04 -0800
committerAndi Albrecht <albrecht.andi@gmail.com>2020-01-16 09:19:34 +0100
commitd34e55ca921526e4d2f200503c99c4703930b7ff (patch)
treef14be948cf3038d25acb6f7042c16ea574e1a1c0 /tests
parentea54b8b1a4064b1289273fd8d14d498b5068c82f (diff)
downloadsqlparse-d34e55ca921526e4d2f200503c99c4703930b7ff.tar.gz
Like/ilike comparison test
Diffstat (limited to 'tests')
-rw-r--r--tests/test_grouping.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/test_grouping.py b/tests/test_grouping.py
index dedd4da..2dd8ca7 100644
--- a/tests/test_grouping.py
+++ b/tests/test_grouping.py
@@ -485,6 +485,41 @@ def test_comparison_with_strings(operator):
assert p.tokens[0].right.ttype == T.String.Single
+def test_like_and_ilike_comparison():
+ def validate_where_clause(where_clause, expected_tokens):
+ assert len(where_clause.tokens) == len(expected_tokens)
+ for where_token, expected_token in zip(where_clause, expected_tokens):
+ expected_ttype, expected_value = expected_token
+ assert where_token.match(expected_ttype, expected_value)
+
+ [p1] = sqlparse.parse("select * from mytable where column LIKE 'expr%' limit 5;")
+ [p1_where] = [token for token in p1 if isinstance(token, sql.Where)]
+ validate_where_clause(p1_where, [
+ (T.Keyword, "where"),
+ (T.Whitespace, None),
+ (T.Keyword, "column"),
+ (T.Whitespace, None),
+ (T.Comparison, "LIKE"),
+ (T.Whitespace, None),
+ (T.String.Single, "'expr%'"),
+ (T.Whitespace, None),
+ ])
+
+ [p2] = sqlparse.parse(
+ "select * from mytable where mycol NOT ILIKE '-expr' group by mytable.othercolumn")
+ [p2_where] = [token for token in p2 if isinstance(token, sql.Where)]
+ validate_where_clause(p2_where, [
+ (T.Keyword, "where"),
+ (T.Whitespace, None),
+ (T.Keyword, "mycol"),
+ (T.Whitespace, None),
+ (T.Comparison, "NOT ILIKE"),
+ (T.Whitespace, None),
+ (T.String.Single, "'-expr'"),
+ (T.Whitespace, None),
+ ])
+
+
def test_comparison_with_functions():
# issue230
p = sqlparse.parse('foo = DATE(bar.baz)')[0]