summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES2
-rw-r--r--sqlparse/filters.py17
-rw-r--r--tests/test_format.py8
3 files changed, 21 insertions, 6 deletions
diff --git a/CHANGES b/CHANGES
index d93b5ea..666e3fb 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 (issues 12, 15).
+ parsing and more (issues 12, 14, 15).
* Code cleanup with a pinch of refactoring.
Release 0.1.1 (May 6, 2009)
diff --git a/sqlparse/filters.py b/sqlparse/filters.py
index 2015674..a3ae192 100644
--- a/sqlparse/filters.py
+++ b/sqlparse/filters.py
@@ -133,10 +133,18 @@ class ReindentFilter(Filter):
def _split_kwds(self, tlist):
split_words = ('FROM', 'JOIN$', 'AND', 'OR',
'GROUP', 'ORDER', 'UNION', 'VALUES',
- 'SET')
- idx = 0
- token = tlist.token_next_match(idx, T.Keyword, split_words,
+ 'SET', 'BETWEEN')
+ def _next_token(i):
+ t = tlist.token_next_match(i, T.Keyword, split_words,
regex=True)
+ if t and t.value.upper() == 'BETWEEN':
+ t = _next_token(tlist.token_index(t)+1)
+ if t and t.value.upper() == 'AND':
+ t = _next_token(tlist.token_index(t)+1)
+ return t
+
+ idx = 0
+ token = _next_token(idx)
while token:
prev = tlist.token_prev(tlist.token_index(token), False)
offset = 1
@@ -151,8 +159,7 @@ class ReindentFilter(Filter):
else:
nl = self.nl()
tlist.insert_before(token, nl)
- token = tlist.token_next_match(tlist.token_index(nl) + offset,
- T.Keyword, split_words, regex=True)
+ token = _next_token(tlist.token_index(nl) + offset)
def _split_statements(self, tlist):
idx = 0
diff --git a/tests/test_format.py b/tests/test_format.py
index 88693c0..32e8bef 100644
--- a/tests/test_format.py
+++ b/tests/test_format.py
@@ -104,6 +104,14 @@ class TestFormatReindent(TestCaseBase):
'select *',
'from bar;']))
+ def test_keywords_between(self): # issue 14
+ # don't break AND after BETWEEN
+ f = lambda sql: sqlparse.format(sql, reindent=True)
+ s = 'and foo between 1 and 2 and bar = 3'
+ self.ndiffAssertEqual(f(s), '\n'.join(['',
+ 'and foo between 1 and 2',
+ 'and bar = 3']))
+
def test_parenthesis(self):
f = lambda sql: sqlparse.format(sql, reindent=True)
s = 'select count(*) from (select * from foo);'