summaryrefslogtreecommitdiff
path: root/django/core
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2006-05-26 05:20:21 +0000
committerAdrian Holovaty <adrian@holovaty.com>2006-05-26 05:20:21 +0000
commit0fd9eef86f56b8dfe219bb0a45f6e5ff8bb75226 (patch)
treea33ea959882909c852eaeb4575fb30903d4e70aa /django/core
parentf375b54503a15360e1b1c08a0ad09c5862bd2083 (diff)
Fixed #1935 -- Initial SQL data now works in SQLite if there are multiple statements. Thanks, jpellerin@gmail.com
git-svn-id: http://code.djangoproject.com/svn/django/trunk@2985 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/core')
-rw-r--r--django/core/management.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/django/core/management.py b/django/core/management.py
index a3a28af1af..8e8133f443 100644
--- a/django/core/management.py
+++ b/django/core/management.py
@@ -328,13 +328,23 @@ def get_sql_initial_data_for_model(model):
app_dir = os.path.normpath(os.path.join(os.path.dirname(models.get_app(model._meta.app_label).__file__), 'sql'))
output = []
+ # 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 is...
+ (?: # 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)
+
# Find custom SQL, if it's available.
sql_files = [os.path.join(app_dir, "%s.%s.sql" % (opts.object_name.lower(), settings.DATABASE_ENGINE)),
os.path.join(app_dir, "%s.sql" % opts.object_name.lower())]
for sql_file in sql_files:
if os.path.exists(sql_file):
fp = open(sql_file)
- output.append(fp.read())
+ output.extend(sql_expr.findall(fp.read()))
fp.close()
return output