Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #1935 -- Initial SQL data now works in SQLite if there are mult…

…iple statements. Thanks, jpellerin@gmail.com

git-svn-id: http://code.djangoproject.com/svn/django/trunk@2985 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 0fd9eef86f56b8dfe219bb0a45f6e5ff8bb75226 1 parent f375b54
Adrian Holovaty authored May 26, 2006
1  AUTHORS
@@ -65,6 +65,7 @@ answer newbie questions, and generally made Django that much better:
65 65
     Robert Rock Howard <http://djangomojo.com/>
66 66
     Jason Huggins <http://www.jrandolph.com/blog/>
67 67
     Michael Josephson <http://www.sdjournal.com/>
  68
+    jpellerin@gmail.com
68 69
     junzhang.jn@gmail.com
69 70
     Russell Keith-Magee <freakboy@iinet.net.au>
70 71
     Garth Kidd <http://www.deadlybloodyserious.com/>
12  django/core/management.py
@@ -328,13 +328,23 @@ def get_sql_initial_data_for_model(model):
328 328
     app_dir = os.path.normpath(os.path.join(os.path.dirname(models.get_app(model._meta.app_label).__file__), 'sql'))
329 329
     output = []
330 330
 
  331
+    # Some backends can't execute more than one SQL statement at a time,
  332
+    # so split into separate statements.
  333
+    sql_expr = re.compile(
  334
+        r"""(           # each statement is...
  335
+        (?:             # one or more chunks of ...
  336
+            (?:[^;'"]+) # not the end of a statement or start of a quote
  337
+          | (?:'[^']+') # something in single quotes
  338
+          | (?:"[^"]+") # something in double quotes
  339
+        )+)""", re.VERBOSE)
  340
+
331 341
     # Find custom SQL, if it's available.
332 342
     sql_files = [os.path.join(app_dir, "%s.%s.sql" % (opts.object_name.lower(), settings.DATABASE_ENGINE)),
333 343
                  os.path.join(app_dir, "%s.sql" % opts.object_name.lower())]
334 344
     for sql_file in sql_files:
335 345
         if os.path.exists(sql_file):
336 346
             fp = open(sql_file)
337  
-            output.append(fp.read())
  347
+            output.extend(sql_expr.findall(fp.read()))
338 348
             fp.close()
339 349
 
340 350
     return output

0 notes on commit 0fd9eef

Please sign in to comment.
Something went wrong with that request. Please try again.