use PDO;
use PDOException;
+use Exception;
use LockManager;
use FSLockManager;
use InvalidArgumentException;
# 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;
}
# 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;
}
/**
* @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;
}
/**