diff options
| author | Andi Albrecht <albrecht.andi@gmail.com> | 2013-05-15 08:14:12 +0200 |
|---|---|---|
| committer | Andi Albrecht <albrecht.andi@gmail.com> | 2013-05-15 08:14:12 +0200 |
| commit | abbcdcf9e135cb3f432041caa434cedd7048d788 (patch) | |
| tree | 6facdbf58f8ce231ae5007d0298c89f69ce130ce | |
| parent | 8e5036120f79e8628bd3c493bc4815bbcc8427b1 (diff) | |
| download | sqlparse-abbcdcf9e135cb3f432041caa434cedd7048d788.tar.gz | |
Strip leading and trailing whitespaces from splitted statements.
| -rw-r--r-- | CHANGES | 2 | ||||
| -rw-r--r-- | sqlparse/__init__.py | 2 | ||||
| -rw-r--r-- | tests/test_split.py | 7 |
3 files changed, 10 insertions, 1 deletions
@@ -6,6 +6,8 @@ Enhancements * Add STRAIGHT_JOIN statement (by Yago Riveiro). * Function.get_parameters() now returns the parameter if only one parameter is given (issue94, by wayne.wuw). +* sqlparse.split() now removes leading and trailing whitespaces from splitted + statements. Release 0.1.7 (Apr 06, 2013) diff --git a/sqlparse/__init__.py b/sqlparse/__init__.py index 53e00ac..16fa76e 100644 --- a/sqlparse/__init__.py +++ b/sqlparse/__init__.py @@ -67,7 +67,7 @@ def split(sql, encoding=None): """ stack = engine.FilterStack() stack.split_statements = True - return [unicode(stmt) for stmt in stack.run(sql, encoding)] + return [unicode(stmt).strip() for stmt in stack.run(sql, encoding)] from sqlparse.engine.filter import StatementFilter diff --git a/tests/test_split.py b/tests/test_split.py index f0b6dda..e4ebf7e 100644 --- a/tests/test_split.py +++ b/tests/test_split.py @@ -131,3 +131,10 @@ class SQLSplitTest(TestCaseBase): stream = StringIO("SELECT 1; SELECT 2;") stmts = list(sqlparse.parsestream(stream)) self.assertEqual(type(stmts[0].tokens[0].value), unicode) + + +def test_split_simple(): + stmts = sqlparse.split('select * from foo; select * from bar;') + assert len(stmts) == 2 + assert stmts[0] == 'select * from foo;' + assert stmts[1] == 'select * from bar;' |
