foreach ( $a as &$row ) {
$this->insertOneRow( $table, $row, $fname );
}
- $retVal = true;
if ( in_array( 'IGNORE', $options ) ) {
$this->ignoreDupValOnIndex = false;
}
- return $retVal;
+ return true;
}
private function fieldBindStatement( $table, $col, &$val, $includeCol = false ) {
$this->ignoreDupValOnIndex = true;
}
- $retval = $this->query( $sql, $fname );
+ $this->query( $sql, $fname );
if ( in_array( 'IGNORE', $insertOptions ) ) {
$this->ignoreDupValOnIndex = false;
}
-
- return $retval;
}
public function upsert( $table, array $rows, array $uniqueIndexes, array $set,
$options = [ $options ];
}
- $fh = $options['fileHandle'] ?? null;
$options = $this->makeInsertOptions( $options );
if ( isset( $a[0] ) && is_array( $a[0] ) ) {
$sql .= '(' . $this->makeList( $a ) . ')';
}
- if ( $fh !== null && false === fwrite( $fh, $sql ) ) {
- return false;
- } elseif ( $fh !== null ) {
- return true;
- }
+ $this->query( $sql, $fname );
- return (bool)$this->query( $sql, $fname );
+ return true;
}
/**
$sql .= " WHERE " . $this->makeList( $conds, self::LIST_AND );
}
- return (bool)$this->query( $sql, $fname );
+ $this->query( $sql, $fname );
+
+ return true;
}
public function makeList( $a, $mode = self::LIST_COMMA ) {
* @param string $table Table name
* @param array|string $rows Row(s) to insert
* @param string $fname Caller function name
- *
- * @return ResultWrapper
*/
protected function nativeReplace( $table, $rows, $fname ) {
$table = $this->tableName( $table );
$sql .= '(' . $this->makeList( $row ) . ')';
}
- return $this->query( $sql, $fname );
+ $this->query( $sql, $fname );
}
public function upsert( $table, array $rows, array $uniqueIndexes, array $set,
$this->startAtomic( $fname, self::ATOMIC_CANCELABLE );
# Update any existing conflicting row(s)
if ( $where !== false ) {
- $ok = $this->update( $table, $set, $where, $fname );
+ $this->update( $table, $set, $where, $fname );
$affectedRowCount += $this->affectedRows();
- } else {
- $ok = true;
}
# Now insert any non-conflicting row(s)
- $ok = $this->insert( $table, $rows, $fname, [ 'IGNORE' ] ) && $ok;
+ $this->insert( $table, $rows, $fname, [ 'IGNORE' ] );
$affectedRowCount += $this->affectedRows();
$this->endAtomic( $fname );
$this->affectedRowCount = $affectedRowCount;
throw $e;
}
- return $ok;
+ return true;
}
public function deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds,
$sql .= ' WHERE ' . $conds;
}
- return $this->query( $sql, $fname );
+ $this->query( $sql, $fname );
+
+ return true;
}
final public function insertSelect(
if ( $this->cliMode && $this->isInsertSelectSafe( $insertOptions, $selectOptions ) ) {
// For massive migrations with downtime, we don't want to select everything
// into memory and OOM, so do all this native on the server side if possible.
- return $this->nativeInsertSelect(
+ $this->nativeInsertSelect(
+ $destTable,
+ $srcTable,
+ $varMap,
+ $conds,
+ $fname,
+ array_diff( $insertOptions, $hints ),
+ $selectOptions,
+ $selectJoinConds
+ );
+ } else {
+ $this->nonNativeInsertSelect(
$destTable,
$srcTable,
$varMap,
);
}
- return $this->nonNativeInsertSelect(
- $destTable,
- $srcTable,
- $varMap,
- $conds,
- $fname,
- array_diff( $insertOptions, $hints ),
- $selectOptions,
- $selectJoinConds
- );
+ return true;
}
/**
* @param array $insertOptions
* @param array $selectOptions
* @param array $selectJoinConds
- * @return bool
*/
protected function nonNativeInsertSelect( $destTable, $srcTable, $varMap, $conds,
$fname = __METHOD__,
$srcTable, implode( ',', $fields ), $conds, $fname, $selectOptions, $selectJoinConds
);
if ( !$res ) {
- return false;
+ return;
}
try {
} else {
$this->cancelAtomic( $fname );
}
- return $ok;
} catch ( Exception $e ) {
$this->cancelAtomic( $fname );
throw $e;
* @param array $insertOptions
* @param array $selectOptions
* @param array $selectJoinConds
- * @return bool
*/
protected function nativeInsertSelect( $destTable, $srcTable, $varMap, $conds,
$fname = __METHOD__,
" INTO $destTable (" . implode( ',', array_keys( $varMap ) ) . ') ' .
$selectSql;
- return $this->query( $sql, $fname );
+ $this->query( $sql, $fname );
}
/**
throw $e;
}
$this->scrollableCursor = true;
+
+ return true;
}
/**
$this->ignoreDupKeyErrors = false;
- return $ret;
+ return true;
}
/**
* @param array $insertOptions
* @param array $selectOptions
* @param array $selectJoinConds
- * @return bool
* @throws Exception
*/
- public function nativeInsertSelect( $destTable, $srcTable, $varMap, $conds, $fname = __METHOD__,
+ protected function nativeInsertSelect( $destTable, $srcTable, $varMap, $conds, $fname = __METHOD__,
$insertOptions = [], $selectOptions = [], $selectJoinConds = []
) {
$this->scrollableCursor = false;
try {
- $ret = parent::nativeInsertSelect(
+ parent::nativeInsertSelect(
$destTable,
$srcTable,
$varMap,
throw $e;
}
$this->scrollableCursor = true;
-
- return $ret;
}
/**
* @param array $uniqueIndexes
* @param array $rows
* @param string $fname
- * @return ResultWrapper
*/
public function replace( $table, $uniqueIndexes, $rows, $fname = __METHOD__ ) {
- return $this->nativeReplace( $table, $rows, $fname );
+ $this->nativeReplace( $table, $rows, $fname );
}
protected function isInsertSelectSafe( array $insertOptions, array $selectOptions ) {
* @param array|string $conds
* @param bool|string $fname
* @throws DBUnexpectedError
- * @return bool|ResultWrapper
*/
public function deleteJoin(
$delTable, $joinTable, $delVar, $joinVar, $conds, $fname = __METHOD__
$sql .= ' AND ' . $this->makeList( $conds, self::LIST_AND );
}
- return $this->query( $sql, $fname );
+ $this->query( $sql, $fname );
}
/**
$sql .= implode( ',', $rowTuples );
$sql .= " ON DUPLICATE KEY UPDATE " . $this->makeList( $set, self::LIST_SET );
- return (bool)$this->query( $sql, $fname );
+ $this->query( $sql, $fname );
+
+ return true;
}
/**
* @param array $insertOptions
* @param array $selectOptions
* @param array $selectJoinConds
- * @return bool
*/
- public function nativeInsertSelect(
+ protected function nativeInsertSelect(
$destTable, $srcTable, $varMap, $conds, $fname = __METHOD__,
$insertOptions = [], $selectOptions = [], $selectJoinConds = []
) {
$sql = "INSERT INTO $destTable (" . implode( ',', array_keys( $varMap ) ) . ') ' .
$selectSql . ' ON CONFLICT DO NOTHING';
- return $this->query( $sql, $fname );
+ $this->query( $sql, $fname );
} else {
// IGNORE and we don't have ON CONFLICT DO NOTHING, so just use the non-native version
- return $this->nonNativeInsertSelect(
+ $this->nonNativeInsertSelect(
$destTable, $srcTable, $varMap, $conds, $fname,
$insertOptions, $selectOptions, $selectJoinConds
);
}
+ } else {
+ parent::nativeInsertSelect( $destTable, $srcTable, $varMap, $conds, $fname,
+ $insertOptions, $selectOptions, $selectJoinConds );
}
-
- return parent::nativeInsertSelect( $destTable, $srcTable, $varMap, $conds, $fname,
- $insertOptions, $selectOptions, $selectJoinConds );
}
public function tableName( $name, $format = 'quoted' ) {
use PDO;
use PDOException;
+use Exception;
use LockManager;
use FSLockManager;
use InvalidArgumentException;
# 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 );
}
+ $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;
}
/**
* @param array $a Array of rows to insert
* @param string $fname Calling function name (use __METHOD__) for logs/profiling
* @param array $options Array of options
- *
- * @return bool
+ * @return bool Return true if no exception was thrown (deprecated since 1.33)
* @throws DBError
*/
public function insert( $table, $a, $fname = __METHOD__, $options = [] );
* @param array $options An array of UPDATE options, can be:
* - IGNORE: Ignore unique key conflicts
* - LOW_PRIORITY: MySQL-specific, see MySQL manual.
- * @return bool
+ * @return bool Return true if no exception was thrown (deprecated since 1.33)
* @throws DBError
*/
public function update( $table, $values, $conds, $fname = __METHOD__, $options = [] );
* things like "field = field + 1" or similar computed values.
* @param string $fname Calling function name (use __METHOD__) for logs/profiling
* @throws DBError
- * @return bool
+ * @return bool Return true if no exception was thrown (deprecated since 1.33)
*/
public function upsert(
$table, array $rows, array $uniqueIndexes, array $set, $fname = __METHOD__
* for the format. Use $conds == "*" to delete all rows
* @param string $fname Name of the calling function
* @throws DBUnexpectedError
- * @return bool|IResultWrapper
+ * @return bool Return true if no exception was thrown (deprecated since 1.33)
* @throws DBError
*/
public function delete( $table, $conds, $fname = __METHOD__ );
* @param array $selectJoinConds Join conditions for the SELECT part of the query, see
* IDatabase::select() for details.
*
- * @return bool
+ * @return bool Return true if no exception was thrown (deprecated since 1.33)
* @throws DBError
*/
public function insertSelect( $destTable, $srcTable, $varMap, $conds,
// Redeclare parent method to make it public
public function nativeReplace( $table, $rows, $fname ) {
- return parent::nativeReplace( $table, $rows, $fname );
+ parent::nativeReplace( $table, $rows, $fname );
}
function getType() {