Opened 18 years ago
Closed 18 years ago
#2452 closed enhancement (fixed)
[PATCH] Allow to use comments in the "initial sql data" files.
Reported by: | Pawel J. Sawicki (http://pjs.name) | Owned by: | Adrian Holovaty |
---|---|---|---|
Component: | Core (Other) | Version: | |
Severity: | minor | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
In order to allow comments to be placed in the initial sql data files (http://www.djangoproject.com/documentation/model_api/#providing-initial-sql-data) the following patch may be used:
$ svn diff management.py Index: management.py =================================================================== --- management.py (revision 3496) +++ management.py (working copy) @@ -499,7 +499,9 @@ print "Installing initial data for %s model" % model._meta.object_name try: for sql in initial_sql: - cursor.execute(sql) + # Allow to use comments in the initial sql data files. + if not sql.strip().startswith('--'): + cursor.execute(sql) except Exception, e: sys.stderr.write("Failed to install initial SQL data for %s model: %s" % \ (model._meta.object_name, e))
Attachments (1)
Change History (9)
comment:1 by , 18 years ago
comment:2 by , 18 years ago
Isn't the '--' prefix an "ISO way" to make comments in the SQL language? I'm not a DB expert - just asking just out of curiosity.
comment:3 by , 18 years ago
I believe the --
will take care of comments on all database backends we support.
comment:4 by , 18 years ago
comment:5 by , 18 years ago
Ok - I get it. Nevertheless this is quite enough for me, for the time being.
I need to version the sql files and add $Id$ "svn:keywords" ("-- $Id$\n" line). Since the patch is a one-liner I'll stick with it until the initial sql parsing procedures are revisited.
comment:6 by , 18 years ago
wouldn't it just be easier to not try and parse these at all?
just read the files and dump them to stdout
by , 18 years ago
Attachment: | management.diff added |
---|
Patch that correctly removes any comments presented within any initial sql data files.
comment:7 by , 18 years ago
I've fixed the patch since the previous one didn't work as it should (under some conditions).
comment:8 by , 18 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
I haven't tried this patch, but from looking at it it doesn't seem to take differences in SQL comments betweeen databases in to account. Should this be handled at by code in the individual database adapters?