Merge pull request #23164 from owncloud/db-connection-precondition-fix
Prevent certain DBs throwing exceptions on same-value updates
This commit is contained in:
commit
27760ae54e
|
@ -293,7 +293,7 @@ class Connection extends \Doctrine\DBAL\Connection implements IDBConnection {
|
||||||
$updateQb->where($where);
|
$updateQb->where($where);
|
||||||
$affected = $updateQb->execute();
|
$affected = $updateQb->execute();
|
||||||
|
|
||||||
if ($affected === 0) {
|
if ($affected === 0 && !empty($updatePreconditionValues)) {
|
||||||
throw new PreconditionNotMetException();
|
throw new PreconditionNotMetException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,11 @@ class Connection extends \Test\TestCase {
|
||||||
$this->connection = \OC::$server->getDatabaseConnection();
|
$this->connection = \OC::$server->getDatabaseConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function tearDown() {
|
||||||
|
parent::tearDown();
|
||||||
|
$this->connection->dropTable('table');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $table
|
* @param string $table
|
||||||
*/
|
*/
|
||||||
|
@ -86,6 +91,7 @@ class Connection extends \Test\TestCase {
|
||||||
* @depends testTableExists
|
* @depends testTableExists
|
||||||
*/
|
*/
|
||||||
public function testDropTable() {
|
public function testDropTable() {
|
||||||
|
$this->makeTestTable();
|
||||||
$this->assertTableExist('table');
|
$this->assertTableExist('table');
|
||||||
$this->connection->dropTable('table');
|
$this->connection->dropTable('table');
|
||||||
$this->assertTableNotExist('table');
|
$this->assertTableNotExist('table');
|
||||||
|
@ -111,8 +117,6 @@ class Connection extends \Test\TestCase {
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertEquals('foo', $this->getTextValueByIntergerField(1));
|
$this->assertEquals('foo', $this->getTextValueByIntergerField(1));
|
||||||
|
|
||||||
$this->connection->dropTable('table');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetValuesOverWrite() {
|
public function testSetValuesOverWrite() {
|
||||||
|
@ -131,8 +135,6 @@ class Connection extends \Test\TestCase {
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertEquals('bar', $this->getTextValueByIntergerField(1));
|
$this->assertEquals('bar', $this->getTextValueByIntergerField(1));
|
||||||
|
|
||||||
$this->connection->dropTable('table');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetValuesOverWritePrecondition() {
|
public function testSetValuesOverWritePrecondition() {
|
||||||
|
@ -154,8 +156,6 @@ class Connection extends \Test\TestCase {
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertEquals('bar', $this->getTextValueByIntergerField(1));
|
$this->assertEquals('bar', $this->getTextValueByIntergerField(1));
|
||||||
|
|
||||||
$this->connection->dropTable('table');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -179,4 +179,22 @@ class Connection extends \Test\TestCase {
|
||||||
'booleanfield' => false
|
'booleanfield' => false
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSetValuesSameNoError() {
|
||||||
|
$this->makeTestTable();
|
||||||
|
$this->connection->setValues('table', [
|
||||||
|
'integerfield' => 1
|
||||||
|
], [
|
||||||
|
'textfield' => 'foo',
|
||||||
|
'clobfield' => 'not_null'
|
||||||
|
]);
|
||||||
|
|
||||||
|
// this will result in 'no affected rows' on certain optimizing DBs
|
||||||
|
// ensure the PreConditionNotMetException isn't thrown
|
||||||
|
$this->connection->setValues('table', [
|
||||||
|
'integerfield' => 1
|
||||||
|
], [
|
||||||
|
'textfield' => 'foo'
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue