Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #2119 -- fixed problems with splitting SQL statements into sepa…

…rate

statements. Uses a patch from eaw@woudy.org and some contributions from
jpellerin@gmail.com. Also fixes #2034 and #1935.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@3178 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 92571b0d48e30e958f4c3fed43bf035894c09390 1 parent 3e97535
Malcolm Tredinnick malcolmt authored
13 django/core/management.py
View
@@ -333,14 +333,7 @@ def get_sql_initial_data_for_model(model):
# Some backends can't execute more than one SQL statement at a time,
# so split into separate statements.
- sql_expr = re.compile(
- r"""( # each statement ...
- [^\r\n;] # starts with something other than a line ending or ';'
- (?: # then has one or more chunks of ...
- (?:[^;'"]+) # not the end of a statement or start of a quote
- | (?:'[^']*') # something in single quotes
- | (?:"[^"]*") # something in double quotes
- )+)""", re.VERBOSE)
+ statements = re.compile(r";[ \t]*$", re.M)
# Find custom SQL, if it's available.
sql_files = [os.path.join(app_dir, "%s.%s.sql" % (opts.object_name.lower(), settings.DATABASE_ENGINE)),
@@ -348,7 +341,9 @@ def get_sql_initial_data_for_model(model):
for sql_file in sql_files:
if os.path.exists(sql_file):
fp = open(sql_file)
- output.extend(sql_expr.findall(fp.read()))
+ for statement in statements.split(fp.read()):
+ if statement.strip():
+ output.append(statement + ";")
fp.close()
return output
1  tests/regressiontests/initial_sql_regress/sql/simple.sql
View
@@ -2,4 +2,5 @@ INSERT INTO initial_sql_regress_simple (name) VALUES ('John');
INSERT INTO initial_sql_regress_simple (name) VALUES ('Paul');
INSERT INTO initial_sql_regress_simple (name) VALUES ('Ringo');
INSERT INTO initial_sql_regress_simple (name) VALUES ('George');
+INSERT INTO initial_sql_regress_simple (name) VALUES ('Miles O''Brien');
Please sign in to comment.
Something went wrong with that request. Please try again.