database: Avoid use of PDO transaction system for SQLite
authorTimo Tijhof <krinklemail@gmail.com>
Thu, 19 Feb 2015 01:05:20 +0000 (01:05 +0000)
committerTimo Tijhof <krinklemail@gmail.com>
Thu, 19 Feb 2015 20:03:54 +0000 (20:03 +0000)
This is in preparation for changing doBegin() to use BEGIN IMMEDIATE.

PDO::beginTransaction() doesn't support any parameters for mode.
Use direct queries instead so that modes (such as IMMEDIATE) can
be used.

Since PDO's transaction system maintains state internally (similarly
to what MediaWiki Database classes do) we have to abandon use of
PDO commit() and rollback() as well (in favour of direct queries
already provided by DatabaseBase).

Bug: T89180
Change-Id: I2ad2a3c2a6d4737f5ef8822fba7cbcf5e36021f4

includes/db/DatabaseSqlite.php

index 9257ffe..95c44df 100644 (file)
@@ -144,8 +144,8 @@ class DatabaseSqlite extends DatabaseBase {
                }
 
                $this->mOpened = !!$this->mConn;
-               # set error codes only, don't raise exceptions
                if ( $this->mOpened ) {
+                       # Set error codes only, don't raise exceptions
                        $this->mConn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT );
                        # Enforce LIKE to be case sensitive, just like MySQL
                        $this->query( 'PRAGMA case_sensitive_like = 1' );
@@ -711,38 +711,6 @@ class DatabaseSqlite extends DatabaseBase {
                return false;
        }
 
-       protected function doBegin( $fname = '' ) {
-               if ( $this->mTrxLevel == 1 ) {
-                       $this->commit( __METHOD__ );
-               }
-               try {
-                       $this->mConn->beginTransaction();
-               } catch ( PDOException $e ) {
-                       throw new DBUnexpectedError( $this, 'Error in BEGIN query: ' . $e->getMessage() );
-               }
-               $this->mTrxLevel = 1;
-       }
-
-       protected function doCommit( $fname = '' ) {
-               if ( $this->mTrxLevel == 0 ) {
-                       return;
-               }
-               try {
-                       $this->mConn->commit();
-               } catch ( PDOException $e ) {
-                       throw new DBUnexpectedError( $this, 'Error in COMMIT query: ' . $e->getMessage() );
-               }
-               $this->mTrxLevel = 0;
-       }
-
-       protected function doRollback( $fname = '' ) {
-               if ( $this->mTrxLevel == 0 ) {
-                       return;
-               }
-               $this->mConn->rollBack();
-               $this->mTrxLevel = 0;
-       }
-
        /**
         * @param string $s
         * @return string