Opened 18 years ago

Closed 18 years ago

Last modified 18 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

Description

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

Index: management.py
===================================================================
--- management.py       (revision 3007)
+++ management.py       (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 by jpellerin@…, 18 years ago

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 by ian@…, 18 years ago

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 by jpellerin@…, 18 years ago

Ian,

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 by Joeboy, 18 years ago

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

comment:5 by jpellerin@…, 18 years ago

No, in that case also, the collected chunks of sql are executed one at a time. Take a look: source:django/trunk/django/core/management.py#L585. 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 by Joeboy, 18 years ago

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 manage.py 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 by Go, 18 years ago

Type: defect

comment:8 by Malcolm Tredinnick, 18 years ago

Resolution: fixed
Status: newclosed
Type: defect

This was fixed in [3178].

comment:9 by anonymous, 18 years ago

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

comment:10 by Adrian Holovaty, 18 years ago

milestone: Version 0.92

Milestone Version 0.92 deleted

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