From e0850bfc7523059bb43e26ec8b6ae999e5179bae Mon Sep 17 00:00:00 2001 From: Simon Podlipsky Date: Thu, 10 Mar 2022 08:53:30 +0100 Subject: [PATCH] Return numeric-string instead of just string to represent row count --- src/Connection.php | 13 ++++++++++++- src/Driver/Connection.php | 5 ++++- src/Query/QueryBuilder.php | 6 ++++-- src/Tools/Console/Command/RunSqlCommand.php | 2 +- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/Connection.php b/src/Connection.php index 60ae3aa4ea0..21b080547bc 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -624,6 +624,7 @@ private function addCriteriaCondition( * @param array|array $types Parameter types * * @return int|string The number of affected rows. + * @psalm-return int|numeric-string * * @throws Exception */ @@ -661,6 +662,7 @@ public function close() * @param int $level The level to set. * * @return int|string + * @psalm-return int|numeric-string * * @throws Exception */ @@ -698,6 +700,7 @@ public function getTransactionIsolation() * @param array|array $types Parameter types * * @return int|string The number of affected rows. + * @psalm-return int|numeric-string * * @throws Exception */ @@ -733,10 +736,11 @@ public function update($table, array $data, array $criteria, array $types = []) * @param array|array $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 ()'); @@ -1126,6 +1130,7 @@ public function executeCacheQuery($sql, $params, $types, QueryCacheProfile $qcp) * @param array|array $types Parameter types * * @return int|string The number of affected rows. + * @psalm-return int|numeric-string * * @throws Exception */ @@ -1826,6 +1831,9 @@ private function handleDriverException( * * @param array $params The query parameters * @param array $types The parameter types + * + * @return int|string + * @psalm-return int|numeric-string */ public function executeUpdate(string $sql, array $params = [], array $types = []): int { @@ -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 { diff --git a/src/Driver/Connection.php b/src/Driver/Connection.php index 2f460fd1066..6b1f599d5f0 100644 --- a/src/Driver/Connection.php +++ b/src/Driver/Connection.php @@ -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. diff --git a/src/Query/QueryBuilder.php b/src/Query/QueryBuilder.php index 7f30a1287ca..5dce4d6b291 100644 --- a/src/Query/QueryBuilder.php +++ b/src/Query/QueryBuilder.php @@ -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); } @@ -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 */ diff --git a/src/Tools/Console/Command/RunSqlCommand.php b/src/Tools/Console/Command/RunSqlCommand.php index a9137206178..387dfa4c796 100644 --- a/src/Tools/Console/Command/RunSqlCommand.php +++ b/src/Tools/Console/Command/RunSqlCommand.php @@ -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))); } }