summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndi Albrecht <albrecht.andi@gmail.com>2013-09-28 08:40:31 +0200
committerAndi Albrecht <albrecht.andi@gmail.com>2013-09-28 08:40:31 +0200
commitf4a152924fc6df8f42c9006f9f07aa3d26d78e82 (patch)
tree249e179f0cafbfbfaa6b6cd6264f3d2558a7d538
parent3df9bf4054d6dff589a50225d87be11fa4817c2e (diff)
downloadsqlparse-f4a152924fc6df8f42c9006f9f07aa3d26d78e82.tar.gz
Fix tagging of identifiers by not taking single quoted strings into account (fixes #111).
-rw-r--r--CHANGES5
-rw-r--r--sqlparse/engine/grouping.py3
-rw-r--r--tests/test_grouping.py11
-rw-r--r--tests/test_parse.py12
4 files changed, 25 insertions, 6 deletions
diff --git a/CHANGES b/CHANGES
index c59bca2..72624d2 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,11 @@
Development Version
-------------------
+Bug Fixes
+* Fix an regression introduced in 0.1.5 where sqlparse didn't properly
+ distinguished between single and double quoted strings when tagging
+ identifier (issue111).
+
Enhancements
* New option to truncate long string literals when formatting.
* Scientific numbers are pares correctly (issue107).
diff --git a/sqlparse/engine/grouping.py b/sqlparse/engine/grouping.py
index 4ba90aa..3536a8b 100644
--- a/sqlparse/engine/grouping.py
+++ b/sqlparse/engine/grouping.py
@@ -145,7 +145,6 @@ def group_identifier(tlist):
or y.ttype is T.Operator
or y.ttype is T.Wildcard),
lambda y: (y.ttype in (T.String.Symbol,
- T.String.Single,
T.Name,
T.Wildcard,
T.Literal.Number.Integer,
@@ -165,7 +164,7 @@ def group_identifier(tlist):
# chooses the next token. if two tokens are found then the
# first is returned.
t1 = tl.token_next_by_type(
- i, (T.String.Symbol, T.String.Single, T.Name, T.Literal.Number.Integer,
+ i, (T.String.Symbol, T.Name, T.Literal.Number.Integer,
T.Literal.Number.Float))
t2 = tl.token_next_by_instance(i, (sql.Function, sql.Parenthesis))
if t1 and t2:
diff --git a/tests/test_grouping.py b/tests/test_grouping.py
index 2b7cefd..fe6aa7d 100644
--- a/tests/test_grouping.py
+++ b/tests/test_grouping.py
@@ -236,10 +236,13 @@ def test_identifier_with_op_trailing_ws():
assert p.tokens[1].ttype is T.Whitespace
-def test_identifier_string_concat():
- p = sqlparse.parse('\'foo\' || bar')[0]
- assert len(p.tokens) == 1
- assert isinstance(p.tokens[0], sql.Identifier)
+# This test seems to be wrong. It was introduced when fixing #53, but #111
+# showed that this shouldn't be an identifier at all. I'm leaving this
+# commented in the source for a while.
+# def test_identifier_string_concat():
+# p = sqlparse.parse('\'foo\' || bar')[0]
+# assert len(p.tokens) == 1
+# assert isinstance(p.tokens[0], sql.Identifier)
def test_identifier_consumes_ordering(): # issue89
diff --git a/tests/test_parse.py b/tests/test_parse.py
index 953a237..ea29f88 100644
--- a/tests/test_parse.py
+++ b/tests/test_parse.py
@@ -157,3 +157,15 @@ def test_scientific_numbers(num):
p = sqlparse.parse(num)[0].tokens
assert len(p) == 1
assert p[0].ttype is T.Number.Float
+
+
+def test_single_quotes_are_strings():
+ p = sqlparse.parse("'foo'")[0].tokens
+ assert len(p) == 1
+ assert p[0].ttype is T.String.Single
+
+
+def test_double_quotes_are_identifiers():
+ p = sqlparse.parse('"foo"')[0].tokens
+ assert len(p) == 1
+ assert isinstance(p[0], sqlparse.sql.Identifier)