summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Amy <cocoade@googlemail.com>2012-11-07 20:39:42 +0700
committerMike Amy <cocoade@googlemail.com>2012-11-07 20:39:42 +0700
commiteb9afb54f65d1d0ffeaa0a083bbccf0a048fb162 (patch)
tree6966e0aaf16d1a61ce3afbc13bf929130555a6f0
parent997135e26c6e68becc178d312dc8b073033cb13c (diff)
downloadsqlparse-eb9afb54f65d1d0ffeaa0a083bbccf0a048fb162.tar.gz
Special case grouping logic for VARCHAR, otherwise it gets lost from field definitions.
-rw-r--r--sqlparse/engine/grouping.py9
-rw-r--r--tests/test_grouping.py4
2 files changed, 9 insertions, 4 deletions
diff --git a/sqlparse/engine/grouping.py b/sqlparse/engine/grouping.py
index 1487c24..f30d9e1 100644
--- a/sqlparse/engine/grouping.py
+++ b/sqlparse/engine/grouping.py
@@ -289,10 +289,11 @@ def group_aliased(tlist):
while token:
next_ = tlist.token_next(tlist.token_index(token))
if next_ is not None and isinstance(next_, clss):
- grp = tlist.tokens_between(token, next_)[1:]
- token.tokens.extend(grp)
- for t in grp:
- tlist.tokens.remove(t)
+ if not next_.value.upper().startswith('VARCHAR'):
+ grp = tlist.tokens_between(token, next_)[1:]
+ token.tokens.extend(grp)
+ for t in grp:
+ tlist.tokens.remove(t)
idx = tlist.token_index(token) + 1
token = tlist.token_next_by_instance(idx, clss)
diff --git a/tests/test_grouping.py b/tests/test_grouping.py
index 8d84804..c63d8e5 100644
--- a/tests/test_grouping.py
+++ b/tests/test_grouping.py
@@ -189,6 +189,10 @@ class TestGrouping(TestCaseBase):
self.assert_(isinstance(p.tokens[0], sql.Function))
self.assertEqual(len(list(p.tokens[0].get_parameters())), 2)
+ def test_varchar(self):
+ p = sqlparse.parse('"text" Varchar(50) NOT NULL')[0]
+ self.assert_(isinstance(p.tokens[2], sql.Function))
+
class TestStatement(TestCaseBase):