summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndi Albrecht <albrecht.andi@gmail.com>2010-11-21 12:43:06 +0100
committerAndi Albrecht <albrecht.andi@gmail.com>2010-11-21 12:43:06 +0100
commit98b3c40f1c91b4a620a53fabfdbb8100bada15e8 (patch)
tree1970558b9a5b751cf5bff40234a4c5068f41d05b
parent16b9b09222313e6cf45cd4daa313fd0f951f6a94 (diff)
downloadsqlparse-98b3c40f1c91b4a620a53fabfdbb8100bada15e8.tar.gz
Group extended identifiers (fixes issue15).
-rw-r--r--CHANGES2
-rw-r--r--sqlparse/engine/grouping.py6
-rw-r--r--tests/test_grouping.py8
3 files changed, 13 insertions, 3 deletions
diff --git a/CHANGES b/CHANGES
index 559ac09..d93b5ea 100644
--- a/CHANGES
+++ b/CHANGES
@@ -10,7 +10,7 @@ Bug Fixes
* Better detection of escaped single quotes (issue13, reported by
Martin Brochhaus, patch by bluemaro with test case by Dan Carley).
* Lots of minor fixes targeting encoding, indentation, statement
- parsing and more.
+ parsing and more (issues 12, 15).
* Code cleanup with a pinch of refactoring.
Release 0.1.1 (May 6, 2009)
diff --git a/sqlparse/engine/grouping.py b/sqlparse/engine/grouping.py
index 5fd38ec..3a2e3c3 100644
--- a/sqlparse/engine/grouping.py
+++ b/sqlparse/engine/grouping.py
@@ -117,7 +117,8 @@ def group_comparison(tlist):
def _parts_valid(token):
return (token.ttype in (T.String.Symbol, T.Name, T.Number,
- T.Number.Integer, T.Literal)
+ T.Number.Integer, T.Literal,
+ T.Literal.Number.Integer)
or isinstance(token, (sql.Identifier,)))
_group_left_right(tlist, T.Operator.Comparison, None, sql.Comparison,
check_left=_parts_valid, check_right=_parts_valid)
@@ -135,7 +136,8 @@ def group_identifier(tlist):
or y.ttype is T.Operator),
lambda y: (y.ttype in (T.String.Symbol,
T.Name,
- T.Wildcard))))
+ T.Wildcard,
+ T.Literal.Number.Integer))))
for t in tl.tokens[i:]:
if next(x)(t):
yield t
diff --git a/tests/test_grouping.py b/tests/test_grouping.py
index 120c7cf..c6f3679 100644
--- a/tests/test_grouping.py
+++ b/tests/test_grouping.py
@@ -88,6 +88,14 @@ class TestGrouping(TestCaseBase):
self.assert_(isinstance(p.tokens[0], sql.Identifier))
self.assert_(isinstance(p.tokens[0].tokens[0], sql.Function))
+ def test_identifier_extended(self): # issue 15
+ p = sqlparse.parse('foo+100')[0]
+ self.assert_(isinstance(p.tokens[0], sql.Identifier))
+ p = sqlparse.parse('foo + 100')[0]
+ self.assert_(isinstance(p.tokens[0], sql.Identifier))
+ p = sqlparse.parse('foo*100')[0]
+ self.assert_(isinstance(p.tokens[0], sql.Identifier))
+
def test_identifier_list(self):
p = sqlparse.parse('a, b, c')[0]
self.assert_(isinstance(p.tokens[0], sql.IdentifierList))