diff options
author | Ihar Hrachyshka <ihrachys@redhat.com> | 2015-01-14 00:09:32 +0100 |
---|---|---|
committer | Ihar Hrachyshka <ihrachys@redhat.com> | 2015-01-14 01:45:25 +0100 |
commit | b9caaae4fccb1d6f8dea575ff318975fe197edde (patch) | |
tree | 8692c97fd05897feb3946678077a152db941d4ad | |
parent | b011e6cb39401a72c29b9ba60345c644d4032897 (diff) | |
download | sqlalchemy-migrate-b9caaae4fccb1d6f8dea575ff318975fe197edde.tar.gz |
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
-rw-r--r-- | migrate/tests/versioning/test_script.py | 10 | ||||
-rw-r--r-- | migrate/versioning/script/sql.py | 1 |
2 files changed, 11 insertions, 0 deletions
diff --git a/migrate/tests/versioning/test_script.py b/migrate/tests/versioning/test_script.py index 954bc0d..20e6af0 100644 --- a/migrate/tests/versioning/test_script.py +++ b/migrate/tests/versioning/test_script.py @@ -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); " diff --git a/migrate/versioning/script/sql.py b/migrate/versioning/script/sql.py index 4b0536d..862bc9f 100644 --- a/migrate/versioning/script/sql.py +++ b/migrate/versioning/script/sql.py @@ -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): |