Opened 18 years ago

Closed 18 years ago

#2119 closed defect (fixed)

[patch] get_sql_initial_data_for_model can't handle quoted quotes

Reported by: eaw@… Owned by: Adrian Holovaty
Component: Core (Management commands) Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Adrian Holovaty)

The RE in get_sql_initial_data_model can't parse data of the form 'Susan O\'Brien' properly (it ends up generating invalid SQL), so I've taken the approach of simply splitting the initial data into separate SQL statements where ";[ \t]*$" occurs (i.e. a ; at the end of line). [This definition of a statement probably needs to be documented.] Here is the svn diff of the change:

Index: management.py
===================================================================
--- management.py       (revision 3110)
+++ management.py       (working copy)
@@ -341,10 +341,14 @@
     # 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())]
+
+    statements = re.compile(";[ \t]*$", re.M)
     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

Attachments (1)

theDiff (809 bytes ) - added by eaw@… 18 years ago.
Patch to split initial sql data into statements by ";"

Download all attachments as: .zip

Change History (5)

by eaw@…, 18 years ago

Attachment: theDiff added

Patch to split initial sql data into statements by ";"

comment:1 by Adrian Holovaty, 18 years ago

Summary: get_sql_initial_data_for_model can't handle quoted quotes[patch] get_sql_initial_data_for_model can't handle quoted quotes

comment:2 by Adrian Holovaty, 18 years ago

Description: modified (diff)

(Fixed formatting in description.)

comment:3 by jpellerin@…, 18 years ago

This is much better than my original patch. Easier to understand and more correct.

comment:4 by Malcolm Tredinnick, 18 years ago

Resolution: fixed
Status: newclosed

(In [3178]) Fixed #2119 -- fixed problems with splitting SQL statements into separate
statements. Uses a patch from eaw@… and some contributions from
jpellerin@…. Also fixes #2034 and #1935.

Note: See TracTickets for help on using tickets.
Back to Top