This makes them consistent with nonNativeInsertSelect()
Style aside, there is also the potential edge case of:
a) no transaction being active yet, with
b) the first query being replace() or upsert(), with
c) DBO_TRX being set (usually part of an implicit transaction round)
Previously, in that case, these methods would commit the transaction
they started, rather than leave it open. The correct semantics are
to leave it open. Since MySQL redefined upsert() to use ON DUPLICATE
KEY UPDATE, it already had the right behavior.
Also make sure that rollback() always sets the affectedRowCount
field to 0.
Change-Id: I15f923d3d4799cffc60e3aaea934f4ca1a9488e1
- $useTrx = !$this->trxLevel;
- if ( $useTrx ) {
- $this->begin( $fname, self::TRANSACTION_INTERNAL );
- }
+ $this->startAtomic( $fname );
$affectedRowCount = 0;
foreach ( $rows as $row ) {
// Delete rows which collide with this one
$affectedRowCount = 0;
foreach ( $rows as $row ) {
// Delete rows which collide with this one
$this->insert( $table, $row, $fname );
$affectedRowCount += $this->affectedRows();
}
$this->insert( $table, $row, $fname );
$affectedRowCount += $this->affectedRows();
}
+ $this->endAtomic( $fname );
+ $this->affectedRowCount = $affectedRowCount;
} catch ( Exception $e ) {
} catch ( Exception $e ) {
- if ( $useTrx ) {
- $this->rollback( $fname, self::FLUSHING_INTERNAL );
- }
+ $this->rollback( $fname, self::FLUSHING_INTERNAL );
- if ( $useTrx ) {
- $this->commit( $fname, self::FLUSHING_INTERNAL );
- }
-
- $this->affectedRowCount = $affectedRowCount;
- $useTrx = !$this->trxLevel;
- if ( $useTrx ) {
- $this->begin( $fname, self::TRANSACTION_INTERNAL );
- }
+ $this->startAtomic( $fname );
# Update any existing conflicting row(s)
if ( $where !== false ) {
$ok = $this->update( $table, $set, $where, $fname );
# Update any existing conflicting row(s)
if ( $where !== false ) {
$ok = $this->update( $table, $set, $where, $fname );
# Now insert any non-conflicting row(s)
$ok = $this->insert( $table, $rows, $fname, [ 'IGNORE' ] ) && $ok;
$affectedRowCount += $this->affectedRows();
# Now insert any non-conflicting row(s)
$ok = $this->insert( $table, $rows, $fname, [ 'IGNORE' ] ) && $ok;
$affectedRowCount += $this->affectedRows();
+ $this->endAtomic( $fname );
+ $this->affectedRowCount = $affectedRowCount;
} catch ( Exception $e ) {
} catch ( Exception $e ) {
- if ( $useTrx ) {
- $this->rollback( $fname, self::FLUSHING_INTERNAL );
- }
+ $this->rollback( $fname, self::FLUSHING_INTERNAL );
- if ( $useTrx ) {
- $this->commit( $fname, self::FLUSHING_INTERNAL );
- }
- $this->affectedRowCount = $affectedRowCount;
$this->affectedRowCount = $affectedRowCount;
} else {
$this->rollback( $fname, self::FLUSHING_INTERNAL );
$this->affectedRowCount = $affectedRowCount;
} else {
$this->rollback( $fname, self::FLUSHING_INTERNAL );
- $this->affectedRowCount = 0;
}
return $ok;
} catch ( Exception $e ) {
$this->rollback( $fname, self::FLUSHING_INTERNAL );
}
return $ok;
} catch ( Exception $e ) {
$this->rollback( $fname, self::FLUSHING_INTERNAL );
- $this->affectedRowCount = 0;
} catch ( Exception $e ) {
// already logged; let LoadBalancer move on during mass-rollback
}
} catch ( Exception $e ) {
// already logged; let LoadBalancer move on during mass-rollback
}
+
+ $this->affectedRowCount = 0; // for the sake of consistency