Skip to content

Commit

Permalink
Fixed #19416 -- Fixed multi-line commands in initial SQL files
Browse files Browse the repository at this point in the history
Thanks Aymeric Augustin for detecting this regression.
  • Loading branch information
claudep committed Dec 3, 2012
1 parent 6d27547 commit 5fa5621
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
10 changes: 5 additions & 5 deletions django/core/management/sql.py
Expand Up @@ -145,15 +145,15 @@ def sql_all(app, style, connection):
def _split_statements(content):
comment_re = re.compile(r"^((?:'[^']*'|[^'])*?)--.*$")
statements = []
statement = ""
statement = []
for line in content.split("\n"):
cleaned_line = comment_re.sub(r"\1", line).strip()
if not cleaned_line:
continue
statement += cleaned_line
if statement.endswith(";"):
statements.append(statement)
statement = ""
statement.append(cleaned_line)
if cleaned_line.endswith(";"):
statements.append(" ".join(statement))
statement = []
return statements


Expand Down
3 changes: 2 additions & 1 deletion tests/regressiontests/initial_sql_regress/sql/simple.sql
Expand Up @@ -2,7 +2,8 @@
INSERT INTO initial_sql_regress_simple (name) VALUES ('John'); -- another comment
INSERT INTO initial_sql_regress_simple (name) VALUES ('-- Comment Man');
INSERT INTO initial_sql_regress_simple (name) VALUES ('Paul');
INSERT INTO initial_sql_regress_simple (name) VALUES ('Ringo');
INSERT INTO initial_sql_regress_simple
VALUES (150, 'Ringo');

This comment has been minimized.

Copy link
@manfre

manfre Dec 10, 2012

Contributor

Why was this test converted to an identity insert? This bypasses SQLCompilers and any backend that needs to do special handling for identity inserts.

This comment has been minimized.

Copy link
@claudep

claudep Dec 10, 2012

Author Member

Thanks, fixed in 0cdfa76

INSERT INTO initial_sql_regress_simple (name) VALUES ('George');
INSERT INTO initial_sql_regress_simple (name) VALUES ('Miles O''Brien');
INSERT INTO initial_sql_regress_simple (name) VALUES ('Semicolon;Man');
Expand Down

0 comments on commit 5fa5621

Please sign in to comment.