Skip to content

Commit

Permalink
Return numeric-string instead of just string to represent row count
Browse files Browse the repository at this point in the history
  • Loading branch information
simPod committed Mar 11, 2022
1 parent 82331b8 commit b1f927f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
17 changes: 14 additions & 3 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -624,10 +624,11 @@ private function addCriteriaCondition(
* @param array<int, int|string|Type|null>|array<string, int|string|Type|null> $types Parameter types
*
* @return int|string The number of affected rows.
* @psalm-return int|numeric-string
*
* @throws Exception
*/
public function delete($table, array $criteria, array $types = [])
public function delete($table, array $criteria, array $types = []): int
{
if (count($criteria) === 0) {
throw InvalidArgumentException::fromEmptyCriteria();
Expand Down Expand Up @@ -661,6 +662,7 @@ public function close()
* @param int $level The level to set.
*
* @return int|string
* @psalm-return int|numeric-string
*
* @throws Exception
*/
Expand Down Expand Up @@ -698,10 +700,11 @@ public function getTransactionIsolation()
* @param array<int, int|string|Type|null>|array<string, int|string|Type|null> $types Parameter types
*
* @return int|string The number of affected rows.
* @psalm-return int|numeric-string
*
* @throws Exception
*/
public function update($table, array $data, array $criteria, array $types = [])
public function update($table, array $data, array $criteria, array $types = []): int
{
$columns = $values = $conditions = $set = [];

Expand Down Expand Up @@ -733,10 +736,11 @@ public function update($table, array $data, array $criteria, array $types = [])
* @param array<int, int|string|Type|null>|array<string, int|string|Type|null> $types Parameter types
*
* @return int|string The number of affected rows.
* @psalm-return int|numeric-string
*
* @throws Exception
*/
public function insert($table, array $data, array $types = [])
public function insert($table, array $data, array $types = []): int
{
if (count($data) === 0) {
return $this->executeStatement('INSERT INTO ' . $table . ' () VALUES ()');
Expand Down Expand Up @@ -1126,6 +1130,7 @@ public function executeCacheQuery($sql, $params, $types, QueryCacheProfile $qcp)
* @param array<int, int|string|Type|null>|array<string, int|string|Type|null> $types Parameter types
*
* @return int|string The number of affected rows.
* @psalm-return int|numeric-string
*
* @throws Exception
*/
Expand Down Expand Up @@ -1826,6 +1831,9 @@ private function handleDriverException(
*
* @param array<mixed> $params The query parameters
* @param array<int|string|null> $types The parameter types
*
* @return int|string
* @psalm-return int|numeric-string
*/
public function executeUpdate(string $sql, array $params = [], array $types = []): int
{
Expand All @@ -1846,6 +1854,9 @@ public function query(string $sql): Result
* BC layer for a wide-spread use-case of old DBAL APIs
*
* @deprecated This API is deprecated and will be removed after 2022
*
* @return int|string
* @psalm-return int|numeric-string
*/
public function exec(string $sql): int
{
Expand Down
5 changes: 4 additions & 1 deletion src/Driver/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@ public function quote($value, $type = ParameterType::STRING);
/**
* Executes an SQL statement and return the number of affected rows.
*
* @return int|string
* @psalm-return int|numeric-string
*
* @throws Exception
*/
public function exec(string $sql): int;
public function exec(string $sql);

/**
* Returns the ID of the last inserted row or sequence value.
Expand Down
6 changes: 4 additions & 2 deletions src/Query/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,12 @@ public function executeQuery(): Result
*
* Should be used for INSERT, UPDATE and DELETE
*
* @return int The number of affected rows.
* @return int|string The number of affected rows.
* @psalm-return int|numeric-string
*
* @throws Exception
*/
public function executeStatement(): int
public function executeStatement()
{
return $this->connection->executeStatement($this->getSQL(), $this->params, $this->paramTypes);
}
Expand All @@ -330,6 +331,7 @@ public function executeStatement(): int
* @deprecated Use {@see executeQuery()} or {@see executeStatement()} instead.
*
* @return Result|int|string
* @psalm-return Result|int|numeric-string
*
* @throws Exception
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Tools/Console/Command/RunSqlCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,6 @@ private function runQuery(SymfonyStyle $io, Connection $conn, string $sql): void
*/
private function runStatement(SymfonyStyle $io, Connection $conn, string $sql): void
{
$io->success(sprintf('%d rows affected.', $conn->executeStatement($sql)));
$io->success(sprintf('%s rows affected.', $conn->executeStatement($sql)));
}
}

0 comments on commit b1f927f

Please sign in to comment.