summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndi Albrecht <albrecht.andi@gmail.com>2014-10-29 08:35:58 +0100
committerAndi Albrecht <albrecht.andi@gmail.com>2014-10-29 08:35:58 +0100
commit0619bb662fb102eabb78f7059270d5766812c1e1 (patch)
treece916f90636572ff36d8097c4970405371d4c559
parent991e7348075accae6d08025212251af21e92e664 (diff)
downloadsqlparse-0619bb662fb102eabb78f7059270d5766812c1e1.tar.gz
Handle single quoted strings in comparisons correctly (fixes issue148).
-rw-r--r--CHANGES8
-rw-r--r--sqlparse/engine/grouping.py3
-rw-r--r--tests/test_grouping.py8
3 files changed, 18 insertions, 1 deletions
diff --git a/CHANGES b/CHANGES
index b4bf892..0b8d517 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,11 @@
+Development Version
+-------------------
+
+Bug Fixes
+* Properly handle string literals in comparisons (issue148, change proposed
+ by aadis).
+
+
Release 0.1.13 (Oct 09, 2014)
-----------------------------
diff --git a/sqlparse/engine/grouping.py b/sqlparse/engine/grouping.py
index 15dc5de..a63b80c 100644
--- a/sqlparse/engine/grouping.py
+++ b/sqlparse/engine/grouping.py
@@ -134,7 +134,8 @@ def group_assignment(tlist):
def group_comparison(tlist):
def _parts_valid(token):
- return (token.ttype in (T.String.Symbol, T.Name, T.Number,
+ return (token.ttype in (T.String.Symbol, T.String.Single,
+ T.Name, T.Number,
T.Number.Integer, T.Literal,
T.Literal.Number.Integer, T.Name.Placeholder)
or isinstance(token, (sql.Identifier, sql.Parenthesis))
diff --git a/tests/test_grouping.py b/tests/test_grouping.py
index 38c1f66..93f1b0e 100644
--- a/tests/test_grouping.py
+++ b/tests/test_grouping.py
@@ -287,6 +287,14 @@ def test_comparison_with_parenthesis(): # issue23
assert comp.right.ttype is T.Number.Integer
+def test_comparison_with_strings(): # issue148
+ p = sqlparse.parse('foo = \'bar\'')[0]
+ assert len(p.tokens) == 1
+ assert isinstance(p.tokens[0], sql.Comparison)
+ assert p.tokens[0].right.value == '\'bar\''
+ assert p.tokens[0].right.ttype == T.String.Single
+
+
@pytest.mark.parametrize('start', ['FOR', 'FOREACH'])
def test_forloops(start):
p = sqlparse.parse('%s foo in bar LOOP foobar END LOOP' % start)[0]