script: strip comments in SQL statements
Regular expression does not match correctly against statements that contain comments at their start. So strip those comments first (and whitespaces, while we are at it). Change-Id: Iad9b544bf995374d76cab1e125658aae2f8511f4 Closes-Bug: #1410494
This commit is contained in:
parent
b011e6cb39
commit
b9caaae4fc
@ -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); "
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user