Opened 17 years ago
Closed 12 years ago
#4680 closed Bug (fixed)
Fixes problem in initial_sql where "--" is in a string
Reported by: | Tim Chase | Owned by: | anonymous |
---|---|---|---|
Component: | Core (Management commands) | Version: | dev |
Severity: | Normal | Keywords: | initial-sql manage.py sprintdec01 |
Cc: | code.djangoproject@…, claude@… | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
In the core/management.py get_custom_sql_for_model() function, if the initial SQL has a "--" in a string, it chokes.
The attached diff should fix the problem. Test cases:
select '--' as foo; -> select '--' as foo;
select '--' as foo; -- select stuff -> select '--' as foo;
select '--' as foo; -- select stuff -- because I want to -> select '--' as foo;
select * foo; -- select stuff -- because I want to -> select * foo;
select * foo; -- select stuff -> select * foo;
Attachments (4)
Change History (18)
by , 17 years ago
Attachment: | initial_sql.diff added |
---|
comment:1 by , 17 years ago
Needs tests: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 17 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 17 years ago
Owner: | changed from | to
---|---|
Status: | assigned → new |
by , 17 years ago
Attachment: | django-ignore-comments-in-sql.patch added |
---|
updated patch. Seems simpler than the previous one. Added test casesto simple.sql as well as a unittest for custom_sql_for_model itself
comment:5 by , 17 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:6 by , 17 years ago
Patch needs improvement: | set |
---|---|
Triage Stage: | Ready for checkin → Accepted |
The first patch doesn't work (as demonstrated by the tests in the second patch). I don't like the code changes in the second patch, though. Having to a linear scan through every character, one at a time, in the initial SQL strings seems inefficient. There must be a better way.
comment:7 by , 17 years ago
Yeah, I was not entirely happy either BUT how often is this called? Is it really in a time efficient section? In other words, while it may not be 100% pretty do we really care? My understanding is this code only happens at application initialization time from manage.py or similar. We could make a sample sql file that had a thousand or two entries and see just how long it takes.
I am willing to help get this finalized, but I do not see a clear regex only solution out of this.
comment:8 by , 16 years ago
Component: | Tools → django-admin.py |
---|
comment:9 by , 16 years ago
There are a couple of related problems here:
- It chokes on strings that contain a semicolon
- It also chokes when you're trying to define stored procedures, e.g.
delimiter $$ create procedure DoSomething() begin select count(*) from MyTable ; end $$ delimiter ;
Wouldn't a better solution be to spawn a separate process (mysql -e /path/to/sql/file
) to handle the initial SQL as a batch than to try and reinvent the database engine's parser?
comment:11 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → Bug |
by , 13 years ago
Attachment: | 4680-test.diff added |
---|
Just a test case demonstrating the issue is still present
comment:12 by , 13 years ago
Cc: | added |
---|---|
Easy pickings: | unset |
Patch needs improvement: | unset |
UI/UX: | unset |
A possible patch, inspired from the initial patch regex to clean comments.
comment:13 by , 12 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:14 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
"svn diff" against trunk