mirror of
https://github.com/django/django.git
synced 2024-12-22 17:16:24 +00:00
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
This commit is contained in:
parent
f375b54503
commit
0fd9eef86f
1
AUTHORS
1
AUTHORS
@ -65,6 +65,7 @@ answer newbie questions, and generally made Django that much better:
|
|||||||
Robert Rock Howard <http://djangomojo.com/>
|
Robert Rock Howard <http://djangomojo.com/>
|
||||||
Jason Huggins <http://www.jrandolph.com/blog/>
|
Jason Huggins <http://www.jrandolph.com/blog/>
|
||||||
Michael Josephson <http://www.sdjournal.com/>
|
Michael Josephson <http://www.sdjournal.com/>
|
||||||
|
jpellerin@gmail.com
|
||||||
junzhang.jn@gmail.com
|
junzhang.jn@gmail.com
|
||||||
Russell Keith-Magee <freakboy@iinet.net.au>
|
Russell Keith-Magee <freakboy@iinet.net.au>
|
||||||
Garth Kidd <http://www.deadlybloodyserious.com/>
|
Garth Kidd <http://www.deadlybloodyserious.com/>
|
||||||
|
@ -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'))
|
app_dir = os.path.normpath(os.path.join(os.path.dirname(models.get_app(model._meta.app_label).__file__), 'sql'))
|
||||||
output = []
|
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.
|
# Find custom SQL, if it's available.
|
||||||
sql_files = [os.path.join(app_dir, "%s.%s.sql" % (opts.object_name.lower(), settings.DATABASE_ENGINE)),
|
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())]
|
os.path.join(app_dir, "%s.sql" % opts.object_name.lower())]
|
||||||
for sql_file in sql_files:
|
for sql_file in sql_files:
|
||||||
if os.path.exists(sql_file):
|
if os.path.exists(sql_file):
|
||||||
fp = open(sql_file)
|
fp = open(sql_file)
|
||||||
output.append(fp.read())
|
output.extend(sql_expr.findall(fp.read()))
|
||||||
fp.close()
|
fp.close()
|
||||||
|
|
||||||
return output
|
return output
|
||||||
|
Loading…
Reference in New Issue
Block a user