Merge "Improve docs for Title::getInternalURL/getCanonicalURL"
[lhc/web/wiklou.git] / includes / libs / rdbms / database / DatabaseSqlite.php
index 487e122..82a7e35 100644 (file)
@@ -25,6 +25,7 @@ namespace Wikimedia\Rdbms;
 
 use PDO;
 use PDOException;
+use Exception;
 use LockManager;
 use FSLockManager;
 use InvalidArgumentException;
@@ -215,6 +216,11 @@ class DatabaseSqlite extends Database {
                        # Enforce LIKE to be case sensitive, just like MySQL
                        $this->query( 'PRAGMA case_sensitive_like = 1' );
 
+                       $sync = $this->sessionVars['synchronous'] ?? null;
+                       if ( in_array( $sync, [ 'EXTRA', 'FULL', 'NORMAL' ], true ) ) {
+                               $this->query( "PRAGMA synchronous = $sync" );
+                       }
+
                        return $this->conn;
                }
 
@@ -648,17 +654,24 @@ class DatabaseSqlite extends Database {
 
                # SQLite can't handle multi-row inserts, so divide up into multiple single-row inserts
                if ( isset( $a[0] ) && is_array( $a[0] ) ) {
-                       $ret = true;
-                       foreach ( $a as $v ) {
-                               if ( !parent::insert( $table, $v, "$fname/multi-row", $options ) ) {
-                                       $ret = false;
+                       $affectedRowCount = 0;
+                       try {
+                               $this->startAtomic( $fname, self::ATOMIC_CANCELABLE );
+                               foreach ( $a as $v ) {
+                                       parent::insert( $table, $v, "$fname/multi-row", $options );
+                                       $affectedRowCount += $this->affectedRows();
                                }
+                               $this->endAtomic( $fname );
+                       } catch ( Exception $e ) {
+                               $this->cancelAtomic( $fname );
+                               throw $e;
                        }
+                       $this->affectedRowCount = $affectedRowCount;
                } else {
-                       $ret = parent::insert( $table, $a, "$fname/single-row", $options );
+                       parent::insert( $table, $a, "$fname/single-row", $options );
                }
 
-               return $ret;
+               return true;
        }
 
        /**
@@ -666,26 +679,30 @@ class DatabaseSqlite extends Database {
         * @param array $uniqueIndexes Unused
         * @param string|array $rows
         * @param string $fname
-        * @return bool|ResultWrapper
         */
        function replace( $table, $uniqueIndexes, $rows, $fname = __METHOD__ ) {
                if ( !count( $rows ) ) {
-                       return true;
+                       return;
                }
 
                # SQLite can't handle multi-row replaces, so divide up into multiple single-row queries
                if ( isset( $rows[0] ) && is_array( $rows[0] ) ) {
-                       $ret = true;
-                       foreach ( $rows as $v ) {
-                               if ( !$this->nativeReplace( $table, $v, "$fname/multi-row" ) ) {
-                                       $ret = false;
+                       $affectedRowCount = 0;
+                       try {
+                               $this->startAtomic( $fname, self::ATOMIC_CANCELABLE );
+                               foreach ( $rows as $v ) {
+                                       $this->nativeReplace( $table, $v, "$fname/multi-row" );
+                                       $affectedRowCount += $this->affectedRows();
                                }
+                               $this->endAtomic( $fname );
+                       } catch ( Exception $e ) {
+                               $this->cancelAtomic( $fname );
+                               throw $e;
                        }
+                       $this->affectedRowCount = $affectedRowCount;
                } else {
-                       $ret = $this->nativeReplace( $table, $rows, "$fname/single-row" );
+                       $this->nativeReplace( $table, $rows, "$fname/single-row" );
                }
-
-               return $ret;
        }
 
        /**
@@ -1001,7 +1018,7 @@ class DatabaseSqlite extends Database {
                        }
                }
 
-               $res = $this->query( $sql, $fname );
+               $res = $this->query( $sql, $fname, self::QUERY_PSEUDO_PERMANENT );
 
                // Take over indexes
                $indexList = $this->query( 'PRAGMA INDEX_LIST(' . $this->addQuotes( $oldName ) . ')' );