Skip to content

Commit abbcdcf

Browse files
committed
Strip leading and trailing whitespaces from splitted statements.
1 parent 8e50361 commit abbcdcf

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Enhancements
66
* Add STRAIGHT_JOIN statement (by Yago Riveiro).
77
* Function.get_parameters() now returns the parameter if only one parameter is
88
given (issue94, by wayne.wuw).
9+
* sqlparse.split() now removes leading and trailing whitespaces from splitted
10+
statements.
911

1012

1113
Release 0.1.7 (Apr 06, 2013)

sqlparse/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def split(sql, encoding=None):
6767
"""
6868
stack = engine.FilterStack()
6969
stack.split_statements = True
70-
return [unicode(stmt) for stmt in stack.run(sql, encoding)]
70+
return [unicode(stmt).strip() for stmt in stack.run(sql, encoding)]
7171

7272

7373
from sqlparse.engine.filter import StatementFilter

tests/test_split.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,10 @@ def test_encoding_parsestream(self):
131131
stream = StringIO("SELECT 1; SELECT 2;")
132132
stmts = list(sqlparse.parsestream(stream))
133133
self.assertEqual(type(stmts[0].tokens[0].value), unicode)
134+
135+
136+
def test_split_simple():
137+
stmts = sqlparse.split('select * from foo; select * from bar;')
138+
assert len(stmts) == 2
139+
assert stmts[0] == 'select * from foo;'
140+
assert stmts[1] == 'select * from bar;'

0 commit comments

Comments
 (0)