Closed (won't fix)
Project:
Drupal core
Version:
7.x-dev
Component:
database system
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
4 Jul 2008 at 13:03 UTC
Updated:
30 Mar 2011 at 22:44 UTC
The function db_query_range steals the last two arguments to the function as LIMIT offset,count values. This is fine for SELECT queries, but DELETE queries use only LIMIT count.
Additionally, specifying a single parameter is valid in MySQL (ie: LIMIT count) but no provision is made for that by this function.
Effectively that means that the db_query_range function cannot be used to LIMIT DELETE queries or apply a LIMIT without an offset.
I suggest that the LIMIT count value be taken and the offset only applied if the argument is provided. This would make the command compatible with DELETE queries.
Comments
Comment #1
gábor hojtsyOur other supported database PostgreSQL does not support any LIMIT at all on DELETE: http://www.postgresql.org/docs/8.1/static/sql-delete.html
Since this is about a missing feature of one of the functions which was not designed to be used for DELETE queries and only applies to one of our supported databases, it is way far from critical. It is basically a missing feature and therefore should be part of Drupal 7 and possibly backported to Drupal 6 if simple enough. It might not apply to Drupal 7 given the new database layer, in which case feel free to move back to Drupal 6 as a task. Not a bug.
Comment #2
Crell commentedWe could certainly add a range() method to delete or update queries as far as the PHP is concerned, but if Postgres doesn't support that in the first place then I don't know if it's a good idea for us to do so. Damien?
Comment #3
Crell commentedThis can be emulated using a subselect (DELETE FROM foo WHERE foo_id IN (SELECT foo_id FROM foo ... LIMIT 5)) on all databases, but isn't natively supported except on MySQL, so this is a won't fix.
Comment #4
damien tournoud commentedYou can easily do that on D7 with a subquery in a db_delete() query. Won't fix.
Comment #5
agerson commentedThis code results in "PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' 1'"
This code results in "PDOException: SQLSTATE[42000]: Syntax error or access violation: 1235 This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery':"
http://dev.mysql.com/doc/refman/5.0/en/subquery-errors.html
Same problem here:
This code results in "PDOException: SQLSTATE[HY000]: General error: 1093 You can't specify target table 'simpleblogroll' for update" It looks like you can't update the same table which you use in the SELECT part in MYSQL
http://bugs.mysql.com/bug.php?id=6980
Comment #6
agerson commentedI tried to do this with a subselect and a subquery on db_delete() and ran into problems with both. See above.
My original goal was to update some D6 code to D7:
Comment #7
bfroehle commentedUnfortunately you cannot use
->condition()with a subselect. SeeYou'll probably need to use the where() function.
Comment #8
bfroehle commentedAlso, it appears that your original support request has been addressed in #630054-8: About port to Drupal 7, so I'm going to reset the issue status on this one back to it's prior values.