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
Constraint int to int<0, max>
  • Loading branch information
simPod committed Mar 25, 2022
1 parent 83f779b commit 0c50422
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 11 deletions.
11 changes: 11 additions & 0 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,7 @@ 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<0,max>|numeric-string
*
* @throws Exception
*/
Expand Down Expand Up @@ -661,6 +662,7 @@ public function close()
* @param int $level The level to set.
*
* @return int|string
* @psalm-return int<0,max>|numeric-string
*
* @throws Exception
*/
Expand Down Expand Up @@ -698,6 +700,7 @@ 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<0,max>|numeric-string
*
* @throws Exception
*/
Expand Down Expand Up @@ -733,6 +736,7 @@ 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<0,max>|numeric-string
*
* @throws Exception
*/
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<0,max>|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<0,max>|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<0,max>|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<0,max>|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
5 changes: 4 additions & 1 deletion src/Driver/IBMDB2/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ public function quote($value, $type = ParameterType::STRING)
return "'" . $value . "'";
}

public function exec(string $sql): int
/**
* {@inheritdoc}
*/
public function exec(string $sql)
{
$stmt = @db2_exec($this->connection, $sql);

Expand Down
5 changes: 4 additions & 1 deletion src/Driver/Middleware/AbstractConnectionMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ public function quote($value, $type = ParameterType::STRING)
return $this->wrappedConnection->quote($value, $type);
}

public function exec(string $sql): int
/**
* {@inheritdoc}
*/
public function exec(string $sql)
{
return $this->wrappedConnection->exec($sql);
}
Expand Down
5 changes: 4 additions & 1 deletion src/Driver/Mysqli/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ public function quote($value, $type = ParameterType::STRING)
return "'" . $this->connection->escape_string($value) . "'";
}

public function exec(string $sql): int
/**
* {@inheritdoc}
*/
public function exec(string $sql)
{
try {
$result = $this->connection->query($sql);
Expand Down
4 changes: 3 additions & 1 deletion src/Driver/OCI8/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,12 @@ public function quote($value, $type = ParameterType::STRING)
}

/**
* {@inheritdoc}
*
* @throws Exception
* @throws Parser\Exception
*/
public function exec(string $sql): int
public function exec(string $sql)
{
return $this->prepare($sql)->execute()->rowCount();
}
Expand Down
5 changes: 4 additions & 1 deletion src/Driver/PDO/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ public function __construct(PDO $connection)
$this->connection = $connection;
}

public function exec(string $sql): int
/**
* {@inheritdoc}
*/
public function exec(string $sql)
{
try {
$result = $this->connection->exec($sql);
Expand Down
5 changes: 4 additions & 1 deletion src/Driver/SQLSrv/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ public function quote($value, $type = ParameterType::STRING)
return "'" . str_replace("'", "''", $value) . "'";
}

public function exec(string $sql): int
/**
* {@inheritdoc}
*/
public function exec(string $sql)
{
$stmt = sqlsrv_query($this->connection, $sql);

Expand Down
5 changes: 4 additions & 1 deletion src/Logging/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ public function query(string $sql): Result
return parent::query($sql);
}

public function exec(string $sql): int
/**
* {@inheritDoc}
*/
public function exec(string $sql)
{
$this->logger->debug('Executing statement: {sql}', ['sql' => $sql]);

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<0,max>|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<0,max>|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 0c50422

Please sign in to comment.