Code

Ticket #2284: new-patch.diff

File new-patch.diff, 1.9 KB (added by scottanderson@…, 8 years ago)

Reverts old regex but stil fixes escaped quotes problem from ticket #2119

Line 
1Index: django/core/management.py
2===================================================================
3--- django/core/management.py   (revision 3275)
4+++ django/core/management.py   (working copy)
5@@ -337,7 +337,14 @@
6 
7     # Some backends can't execute more than one SQL statement at a time,
8     # so split into separate statements.
9-    statements = re.compile(r";[ \t]*$", re.M)
10+    statements = re.compile(
11+        r"""(           # each statement ...
12+        [^\r\n;]        # starts with something other than a line ending or ';'
13+        (?:             # then has one or more chunks of ...
14+            (?:[^;'"]+) # not the end of a statement or start of a quote
15+          | (?:'(?:[^']|\\')*') # something in single quotes, but not escaped
16+          | (?:"(?:[^"]|\\")") # something in double quotes, but not escaped
17+        )+)""", re.VERBOSE)
18 
19     # Find custom SQL, if it's available.
20     sql_files = [os.path.join(app_dir, "%s.%s.sql" % (opts.object_name.lower(), settings.DATABASE_ENGINE)),
21@@ -345,9 +352,7 @@
22     for sql_file in sql_files:
23         if os.path.exists(sql_file):
24             fp = open(sql_file)
25-            for statement in statements.split(fp.read()):
26-                if statement.strip():
27-                    output.append(statement + ";")
28+            output.extend(statements.findall(fp.read()))
29             fp.close()
30 
31     return output
32@@ -497,7 +502,9 @@
33                 if initial_sql:
34                     print "Installing initial data for %s model" % model._meta.object_name
35                     try:
36-                        for sql in initial_sql:
37+                        for sql in [sql.strip() for sql in initial_sql]:
38+                            if not sql: continue
39+                            print "Executing '%s'" % sql
40                             cursor.execute(sql)
41                     except Exception, e:
42                         sys.stderr.write("Failed to install initial SQL data for %s model: %s" % \