Django

Code

Ticket #2119 (closed: fixed)

Opened 2 years ago

Last modified 2 years ago

[patch] get_sql_initial_data_for_model can't handle quoted quotes

Reported by: eaw@woudy.org Assigned to: adrian
Milestone: Component: django-admin.py
Version: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description (Last modified by adrian)

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

theDiff (0.8 kB) - added by eaw@woudy.org on 06/07/06 23:28:49.
Patch to split initial sql data into statements by ";"

Change History

06/07/06 23:28:49 changed by eaw@woudy.org

  • attachment theDiff added.

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

06/07/06 23:29:40 changed by adrian

  • summary changed from get_sql_initial_data_for_model can't handle quoted quotes to [patch] get_sql_initial_data_for_model can't handle quoted quotes.

06/07/06 23:30:04 changed by adrian

  • description changed.

(Fixed formatting in description.)

06/08/06 09:28:08 changed by jpellerin@gmail.com

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

06/20/06 03:00:45 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

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


Add/Change #2119 ([patch] get_sql_initial_data_for_model can't handle quoted quotes)




Change Properties
Action