Opened 13 years ago

Closed 13 years ago

Last modified 12 years ago

#2044 closed task (fixed)

[patch] sqlinitialdata is ignoring semi-colons

Reported by: ian@… Owned by: Adrian Holovaty
Component: Translations Version:
Severity: major Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


currently it seems to be stripping of the semi-colons at the end of a SQL statement.. which means mysql can't import.

---       (revision 3007)
+++       (working copy)
@@ -336,7 +336,7 @@
             (?:[^;'"]+) # not the end of a statement or start of a quote
           | (?:'[^']*') # something in single quotes
           | (?:"[^"]*") # something in double quotes
-        )+)""", re.VERBOSE)
+        )+;?)""", 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)),

Change History (10)

comment:1 Changed 13 years ago by jpellerin@…

See also #2034 -- I think both patches are needed to handle all cases. (Though I think this one should be modified to make the trailing semi-colon optional -- it should be legal to have an initial data file containing a single statement with no semi-colon.)

On the other hand, it might be better to add a flag to each backend that indicates whether it can accept multiple statements in one execute(), and only try to split the initial data files up for those backends that can't. The ones that can are always going to do a better job of parsing a big ball of sql into statements than any regex.

comment:2 Changed 13 years ago by ian@…

hi Jpellerin.

I thought the ';?' meant the semi-colon was optional.
anyway.. what your saying wouldn't work as the file get's catted together with other ones, and
has a 'BEGIN;' and 'COMMIT;' added to it so the semi-colon can't be optional.

does postgres/other backends like ';' to differentiate commands?

comment:3 Changed 13 years ago by jpellerin@…


You're quite right about the ;?... I should learn not to try to read regexes while half asleep. Sorry.

However, the sql files aren't catted together to send to the backend -- otherwise my original patch to split the initial data file into statements wouldn't do anything. Each file (or, after the patch, each statement) is appended to a list, and each item in the list is sent to the backend as a single query, so a file with one statement and no trailing ; works fine.

comment:4 Changed 13 years ago by Joeboy

But if you're doing, say, an sqlreset and piping it to mysql then surely the lines will be concatenated.

comment:5 Changed 13 years ago by jpellerin@…

No, in that case also, the collected chunks of sql are executed one at a time. Take a look: source:django/trunk/django/core/ They look catted if you run the commands that print the sql to the console, but when django itself executes the sql, it iterates over a list of statements.

comment:6 Changed 13 years ago by Joeboy

Sure, that's true, when django itself is executing the sql. I notice that there seems to be a new 'reset' command that executes the sqlreset code, but even so shouldn't piping it continue to be supported? It looks like still has operations that require you to send the sql to the db yourself.

Is it a big deal to make sure there's a semicolon at the end of the line?

comment:7 Changed 13 years ago by Go

Type: defect

comment:8 Changed 13 years ago by Malcolm Tredinnick

Resolution: fixed
Status: newclosed
Type: defect

This was fixed in [3178].

comment:9 Changed 13 years ago by anonymous

Component: django-admin.pyTranslations
milestone: Version 0.92
priority: normalhigh
Severity: normalmajor
Type: defecttask

comment:10 Changed 12 years ago by Adrian Holovaty

milestone: Version 0.92

Milestone Version 0.92 deleted

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