#7856: custom_sql_for_model incorrectly parses the sql file for advanced sql
statements
----------------------------+-----------------------------------------------
Reporter: thebitguru | Owner: nobody
Status: new | Milestone:
Component: Core framework | Version: SVN
Keywords: | Stage: Unreviewed
Has_patch: 0 |
----------------------------+-----------------------------------------------
django.core.management.custom_sql_for_model incorrectly parses advanced
SQL statements in model sql files. In my specific case I am adding a
[http://www.postgresql.org/docs/8.3/interactive/sql-createrule.html
Postgresql RULE] that has sub-statements in it. In this case the custom
sql function breaks up the one rule statement into multiple ones.
I have the following SQL in app/sql/model.sql (replace ''app'' and
''model'' appropriately).
{{{
#!sql
CREATE RULE productlinkimage_onupdate_set_linked AS ON UPDATE TO
core_productlinkimage
WHERE NEW.image_id <> OLD.image_id AND NEW.is_deleted = OLD.is_deleted
DO (
UPDATE core_image SET number_linked = number_linked + 1 WHERE
core_image.id = NEW.image_id;
UPDATE core_image SET number_linked = number_linked - 1 WHERE
core_image.id = OLD.image_id
);
}}}
Then when I do `django-admin.py syncdb` it creates the following set of
commands to execute separately, and, obviously, fails.
{{{
Starting SQL statement (I have added the line breaks for for better
wrapping)
==> u'\nCREATE RULE productlinkimage_onupdate_set_linked AS ON UPDATE TO
core_productlinkimage
\nWHERE NEW.image_id <> OLD.image_id AND NEW.is_deleted =
OLD.is_deleted\nDO (
\n\tUPDATE core_image SET number_linked = number_linked + 1 WHERE
core_image.id = NEW.image_id;',
Next SQL statement
==> u'\tUPDATE core_image SET number_linked = number_linked - 1 WHERE
core_image.id = OLD.image_id\n);',
}}}
The exact output is...
{{{
Installing custom SQL for core.Product model
Failed to install custom SQL for core.Product model: syntax error at end
of input
LINE 6: ...nked = number_linked + 1 WHERE core_image.id = NEW.image_id;
}}}
--
Ticket URL: <http://code.djangoproject.com/ticket/7856>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---