Merge "script: strip comments in SQL statements"

This commit is contained in:
Jenkins 2015-02-24 23:05:33 +00:00 committed by Gerrit Code Review
commit 24521798bc
2 changed files with 11 additions and 0 deletions

View File

@ -281,6 +281,16 @@ class TestSqlScript(fixture.Pathed, fixture.DB):
for script_pattern in (
"BEGIN TRANSACTION; %s; COMMIT;",
"BEGIN; %s; END TRANSACTION;",
"/* comment */BEGIN TRANSACTION; %s; /* comment */COMMIT;",
"/* comment */ BEGIN TRANSACTION; %s; /* comment */ COMMIT;",
"""
-- comment
BEGIN TRANSACTION;
%s;
-- comment
COMMIT;""",
):
test_statement = ("CREATE TABLE TEST1 (field1 int); "

View File

@ -54,6 +54,7 @@ class SqlScript(base.BaseScript):
# not all drivers reliably handle multistatement queries or
# commands passed to .execute(), so split them and execute one
# by one
text = sqlparse.format(text, strip_comments=True, strip_whitespace=True)
for statement in sqlparse.split(text):
if statement:
if re.match(ignored_regex, statement):