To reproduce, visit http://drupal/admin/config/media/file-styles/add, write a name, save and in the next page save again. That results in:
PDOException: SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "i" LINE 1: DELETE i FROM styles_preset_instances i INNER JOIN styles s ... ^: DELETE i FROM {styles_preset_instances} i INNER JOIN {styles} s ON s.sid = i.sid INNER JOIN {styles_presets} p ON i.pid = p.pid AND s.field_type = p.field_type WHERE i.sid = :sid AND p.container_name = :container_name; Array ( [:sid] => 2 [:container_name] => image ) in styles_style_save_preset() (line 627 of /drupal/sites/all/modules/styles/styles.module).
The query should be rewritten in a more portable way.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | styles-delete-query-1105862-4.patch | 1.28 KB | lifepillar |
| #1 | styles-delete-query-1105862-1.patch | 1.2 KB | lifepillar |
Comments
Comment #1
lifepillar commentedEnclosed you find a patch. BTW, it seems that styles_style_save_preset() is called with the wrong value for $delete_only, as on saving it does not write any record into styles_preset_instances. Besides, it is not possible to delete a style (i.e., delete links at admin/config/media/file-styles have no effect).
Comment #2
aaron commentedThat broke mysql, so I checked db_driver() first. I don't have pgsql installed, so can't test that, and would appreciate if you could check against the dev version and report back. Thanks, @druido!
Comment #3
lifepillar commentedI confirm that the current dev fixes this issue with PostgreSQL.
I hadn't realized that MySQL (up to 5.6 included, it seems) does not allow you to delete from a table and select from the same table in a subquery.
Comment #4
lifepillar commentedAlthough the above sentence about MySQL is correct, I have just noticed that the problem in this case is that MySQL doesn't seem to like the variable name for styles_preset_instances. The enclosed patch re-writes the query so that it compiles both in PostgreSQL and MySQL (no need to check for the db driver). You can evaluate which approach is better.
Btw, this patch follows the git standard, as per the new guidelines (http://drupal.org/patch/apply).
Comment #5
aaron commentedMuch cleaner. Thanks, @druido! Committed.