Example #1
0
 /**
  * Requests to rollback a transaction are immediately honoured,
  * regardless of who originally started the current transaction.
  */
 public static function rollbackTransaction()
 {
     $db = self::_singleton();
     $retries = 0;
     $errorCode = 5;
     // Just so we can enter the while loop.
     $query = "ROLLBACK TRANSACTION";
     // SQLITE_BUSY || SQLITE_IOERR_BLOCKED (@see http://www.sqlite.org/c3ref/busy_timeout.html)
     while (self::$_transacting != 0 && ($errorCode == 5 || $errorCode == (10 | 11 << 8)) && $retries < CINTIENT_SQL_BUSY_RETRIES) {
         if ($retries > 0) {
             SystemEvent::raise(SystemEvent::NOTICE, "Database is busy, easing off and retrying. [TRIES={$retries}] [ERRNO={$errorCode}] [ERRMSG={$errorCode}] [QUERY={$query}]" . (!empty($values) ? ' [VALUES=' . implode(' | ', $values) . ']' : ''), __METHOD__);
             sleep(1);
         }
         if (!$db->exec($query)) {
             SystemEvent::raise(SystemEvent::ERROR, "Couldn't rollback transaction.", __METHOD__);
         } else {
             self::$_transacting = 0;
             SystemEvent::raise(SystemEvent::DEBUG, "Transaction rolled back.", __METHOD__);
         }
         $retries++;
         $errorCode = $db->lastErrorCode();
     }
     return self::$_transacting == 0;
 }