summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndi Albrecht <albrecht.andi@gmail.com>2011-07-29 20:58:14 +0200
committerAndi Albrecht <albrecht.andi@gmail.com>2011-07-29 20:58:14 +0200
commitc918cc9dc30b3a7684a96feae95fc5c05638360e (patch)
tree749eed3f2622dfc59ae130ea43dbc8a4eea678c6
parent0ec64528c5fb1efb71122985eab9c7137a80603d (diff)
downloadsqlparse-c918cc9dc30b3a7684a96feae95fc5c05638360e.tar.gz
Add parsing of MS Access column names with braces (fixes issue27).
-rw-r--r--CHANGES2
-rw-r--r--sqlparse/lexer.py1
-rw-r--r--tests/test_parse.py7
3 files changed, 10 insertions, 0 deletions
diff --git a/CHANGES b/CHANGES
index 203d98c..f0af911 100644
--- a/CHANGES
+++ b/CHANGES
@@ -16,6 +16,8 @@ Bug Fixes
* Improve parsing of stand-alone comments (issue26).
* Detection of placeholders in paramterized queries (issue22,
reported by Glyph Lefkowitz).
+ * Add parsing of MS Access column names with braces (issue27,
+ reported by frankz...@gmail.com).
Release 0.1.2 (Nov 23, 2010)
diff --git a/sqlparse/lexer.py b/sqlparse/lexer.py
index 950ef1b..ecfdbce 100644
--- a/sqlparse/lexer.py
+++ b/sqlparse/lexer.py
@@ -189,6 +189,7 @@ class Lexer:
(r"(''|'.*?[^\\]')", tokens.String.Single),
# not a real string literal in ANSI SQL:
(r'(""|".*?[^\\]")', tokens.String.Symbol),
+ (r'(\[.*[^\]]\])', tokens.Name),
(r'(LEFT |RIGHT )?(INNER |OUTER )?JOIN\b', tokens.Keyword),
(r'END( IF| LOOP)?\b', tokens.Keyword),
(r'NOT NULL\b', tokens.Keyword),
diff --git a/tests/test_parse.py b/tests/test_parse.py
index 6ff8dd8..5f9bb2d 100644
--- a/tests/test_parse.py
+++ b/tests/test_parse.py
@@ -95,3 +95,10 @@ class SQLParseTest(TestCaseBase):
self.assert_(t[-1].ttype is sqlparse.tokens.Name.Placeholder)
self.assertEqual(t[-1].value, '$a')
+ def test_access_symbol(self): # see issue27
+ t = sqlparse.parse('select a.[foo bar] as foo')[0].tokens
+ self.assert_(isinstance(t[-1], sqlparse.sql.Identifier))
+ self.assertEqual(t[-1].get_name(), 'foo')
+ self.assertEqual(t[-1].get_real_name(), '[foo bar]')
+ self.assertEqual(t[-1].get_parent_name(), 'a')
+