I tried to use drupal_write_record() to write a record to the database.
I spent an hour trying to track down why it isn't working.
Here's why.
While you can catch the PDOExceptions lower down the chain, these errors just return null.
This patch isn't a total solution for this (needs to be ported to other adapters, or the validation should be part of the base class), but it is a start to show the problem. We may also not want to use PDOException, because it isn't really a PDO Exception, but a Drupal API Exception.
| Comment | File | Size | Author |
|---|---|---|---|
| mysql_insert_exception_handling.patch | 863 bytes | JacobSingh |
Comments
Comment #1
JacobSingh commentedI'm not sure why, but putting this in causes the admin page WSOD for me.
I assume that something is not catching the exception, or rather, catching it and then dying in some unpleasant way.
Comment #2
dries commentedI agree that silently ignoring what are most likely to be broken queries is not the right approach. We should definitely be throwing exceptions in those cases.
For consistency and predictability of the API, those 3 checks should probably be factored out, made part of the base class and re-used in each of the database backends.
Comment #4
Crell commentedThat code is already being factored to the base class in #481288: Add support for INSERT INTO ... SELECT FROM .... Marking this as a dupe and leaving a note over there to convert them to exceptions while we're at it.
Comment #5
berdirThis is not an exception, see #481288-16: Add support for INSERT INTO ... SELECT FROM ... for an explanation.