Home » Database » DB » Bug #6414
DB module attempts to guess which statements modify the database, incorrectly
Details
| Submitted | 2006-01-04 15:40 UTC |
|---|---|
| From | chris at mysociety dot org |
| Status | Duplicate |
| Package | DB |
| PHP Version | Irrelevant |
| OS | irrelevant |
| Roadmaps | (Not assigned) |
Comments
[2006-01-04 15:40 UTC] chris at mysociety dot org
Description:
------------
DB::isManip attempts to guess whether a given statement is going to modify the database. The PostgreSQL module uses this (a) to determine whether to start a transaction, and (b) to decide whether any database changes have occured during the given transaction.
Unfortunately the method does not and can not determine the answer to the question accurately. For instance, isManip will return false for the query,
select function_with_side_effects_and_return_value(...);
whereas it should return true. Similarly, if you do a select ... for update, then the driver should begin a transaction (so that the lock obtained by the query will persist over the transaction), but isManip also returns false for this case.
It's possible to work around this by doing $db->query("commit") explicitly, but that's nasty and anyway the behaviour isn't documented, so this might break in a future version.
Test script:
---------------
/* $db is a connection to a PostgreSQL database */
$db->query("select function_with_side_effects_and_return_value(...)");
$db->commit();
Expected result:
----------------
Results of function committed.
Actual result:
--------------
Results of function not committed.