I'm trying to debug an issue with a delete query not happening. I've added logging before the query, after the query and I'm logging the return value of the query. Everything looks right, the only problem is that the rows are still in the database.
It's a simple query, I can't see anything wrong with it:
$result = db_delete('cloud_files')
->condition('uri', $uri)
->execute();
I've checked the $uri in every way I possibly can and it's right. I've tried executing the delete query by hand and it works just fine. The table name is correct, the field name is correct, the $uri is correct. I don't know what else to check.
I've used the Devel module to log the queries and while it logs queries that happen both before and after this query, it doesn't log this query at all. However, I've got error_log() calls before and after the query so I know this code is being run and it reports that it is running successfully.
I've even added code to select the data before deleting it and it works!
$select = db_select('cloud_files', 'cf')
->fields('cf')
->condition('uri', $uri)
->execute();
$entry = $select->fetchAssoc();
error_log("entry: ".print_r($entry, true));
That works, it prints out the row I'm trying to delete.
dqp() doesn't work for delete queries, so I don't know of any way of getting the truly final sql being executed.
I've made sure that if I connect using the mysql command line client from the drupal host with the user/password in the drupal config that all of the commands work.
How do I debug this? What is going wrong?
EDIT:
Is there any kind of transaction happening during a delete action? Could this behavior be the result of those delete queries happening in a transaction that gets aborted?
hook_query_alter()
to display the final query that will be executed?DELETE
permissions to the user that Drupal is using to connect to the db? Also, try running adb_query('DELETE FROM...');
directly and see if you get the same problem. That runs a flat query string against the db, if it doesn't work I'd say the problem is with the MySQL server somewhere