at 2009-06-16
in Examples, Databases, RFCs
by friebe
(0 comments)
The changes implemented in RFC #1059 make handling deadlocks easier. During deadlocks you might want to your program behave differently than during "regular" statement failures. For example, in Sybase, all transactions, regardless of their nesting level, are rolled back during a deadlock!
You may have written sourcecode as follows in the past:
try { } catch (SQLStatementFailedException $e) { if (1205 == $e->getErrorcode()) { } }The problems should be obvious to the reader: The hardcoded errorcode (here the relevant one for Sybase), the very unelegant if, the missing portability for other drivers (PostgreSQL for example).
The XP Framework now offers a way to handle deadlocks independent of the RDBMS you are accessing. We've introduced a new exception - rdbms.SQLDeadlockException, which will be thrown by the respective implementations.
Example (new functionality)
$conn= DriverManager::getConnection('sybase://...'); try { $tran= $conn->begin(new Transaction('update')); $conn->query('...'); $conn->query('...'); } catch (SQLDeadlockException $e) { } catch (SQLException $e) { $tran && $tran->rollback(); } Note: The old code from above will still work - as SQLDeadlockException is a subclass of SQLStatementFailedException !
|
Subscribe
You can subscribe to the XP framework's news by using RSS syndication.
CategoriesNews General PHP5 Announcements RFCs Further reading Examples Editorial EASC Experiments Unittests Databases 5.8-SERIES Unicode Language 5.9-SERIES
RelatedFind related articles by a search for «Deadlock».
|