Skip to content

Commit a73ec6a

Browse files
author
euromark
committed
Make atomic updateAll and deleteAll return the affected rows instead of bool.
1 parent 6f9131a commit a73ec6a

File tree

4 files changed

+8
-10
lines changed

4 files changed

+8
-10
lines changed

src/Database/Statement/SqliteStatement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function rowCount() {
3232
$changes->execute();
3333
$count = $changes->fetch()[0];
3434
$changes->closeCursor();
35-
return $count;
35+
return (int)$count;
3636
}
3737
return parent::rowCount();
3838
}

src/Datasource/RepositoryInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function query();
7676
* @param array $fields A hash of field => new value.
7777
* @param mixed $conditions Conditions to be used, accepts anything Query::where()
7878
* can take.
79-
* @return bool Success Returns true if one or more rows are affected.
79+
* @return int Count Returns the affected rows.
8080
*/
8181
public function updateAll($fields, $conditions);
8282

@@ -94,7 +94,7 @@ public function updateAll($fields, $conditions);
9494
*
9595
* @param mixed $conditions Conditions to be used, accepts anything Query::where()
9696
* can take.
97-
* @return bool Success Returns true if one or more rows are affected.
97+
* @return int Count Returns the affected rows.
9898
* @see RepositoryInterface::delete()
9999
*/
100100
public function deleteAll($conditions);

src/ORM/Table.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,9 +1024,8 @@ public function updateAll($fields, $conditions) {
10241024
->set($fields)
10251025
->where($conditions);
10261026
$statement = $query->execute();
1027-
$success = $statement->rowCount() > 0;
10281027
$statement->closeCursor();
1029-
return $success;
1028+
return $statement->rowCount();
10301029
}
10311030

10321031
/**
@@ -1104,9 +1103,8 @@ public function deleteAll($conditions) {
11041103
->delete()
11051104
->where($conditions);
11061105
$statement = $query->execute();
1107-
$success = $statement->rowCount() > 0;
11081106
$statement->closeCursor();
1109-
return $success;
1107+
return $statement->rowCount();
11101108
}
11111109

11121110
/**

tests/TestCase/ORM/TableTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ public function testUpdateAll() {
571571
]);
572572
$fields = ['username' => 'mark'];
573573
$result = $table->updateAll($fields, ['id <' => 4]);
574-
$this->assertTrue($result);
574+
$this->assertSame(3, $result);
575575

576576
$result = $table->find('all')
577577
->select(['username'])
@@ -617,7 +617,7 @@ public function testDeleteAll() {
617617
'connection' => $this->connection,
618618
]);
619619
$result = $table->deleteAll(['id <' => 4]);
620-
$this->assertTrue($result);
620+
$this->assertSame(3, $result);
621621

622622
$result = $table->find('all')->toArray();
623623
$this->assertCount(1, $result, 'Only one record should remain');
@@ -636,7 +636,7 @@ public function testDeleteAllAliasedConditions() {
636636
'connection' => $this->connection,
637637
]);
638638
$result = $table->deleteAll(['Managers.id <' => 4]);
639-
$this->assertTrue($result);
639+
$this->assertSame(3, $result);
640640

641641
$result = $table->find('all')->toArray();
642642
$this->assertCount(1, $result, 'Only one record should remain');

0 commit comments

Comments
 (0)