Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return number of affected rows greater than PHP_INT_MAX as string #5274

Merged
merged 1 commit into from
Feb 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Return number of affected rows greater than PHP_INT_MAX as string
  • Loading branch information
morozov committed Feb 13, 2022
commit 0218f59633598aa0ad2e0ebafc05d8e1d624a277
4 changes: 4 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ awareness about deprecated code.

# Upgrade to 4.0

# BC Break: The number of affected rows is returned as `int|string`

The signatures of the methods returning the number of affected rows changed as returning `int|string` instead of `int`.

# BC Break: Dropped support for `collate` option for MySQL

Use `collation` instead.
Expand Down
7 changes: 0 additions & 7 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,6 @@ parameters:
message: '~^Parameter #2 \$lockMode of method Doctrine\\DBAL\\Platforms\\AbstractPlatform\:\:appendLockHint\(\) expects 0\|1\|2\|4, 128 given\.$~'
path: tests/Platforms/AbstractPlatformTestCase.php

# Fixing the issue would cause a BC break.
# TODO: fix in 4.0.0
-
message: '~^Method Doctrine\\DBAL\\Driver\\Mysqli\\Connection::exec\(\) should return int but returns int\|string\.$~'
paths:
- src/Driver/Mysqli/Connection.php

# DriverManagerTest::testDatabaseUrl() should be refactored as it's too dynamic.
-
message: '~^Offset string does not exist on array{.+}\.$~'
Expand Down
18 changes: 9 additions & 9 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -482,11 +482,11 @@ private function addCriteriaCondition(
* @param array<string, mixed> $criteria Deletion criteria
* @param array<int, int|string|Type|null>|array<string, int|string|Type|null> $types Parameter types
*
* @return int The number of affected rows.
* @return int|string The number of affected rows.
*
* @throws Exception
*/
public function delete(string $table, array $criteria, array $types = []): int
public function delete(string $table, array $criteria, array $types = []): int|string
{
if (count($criteria) === 0) {
throw EmptyCriteriaNotAllowed::new();
Expand Down Expand Up @@ -551,11 +551,11 @@ public function getTransactionIsolation(): int
* @param array<string, mixed> $criteria Update criteria
* @param array<int, int|string|Type|null>|array<string, int|string|Type|null> $types Parameter types
*
* @return int The number of affected rows.
* @return int|string The number of affected rows.
*
* @throws Exception
*/
public function update(string $table, array $data, array $criteria, array $types = []): int
public function update(string $table, array $data, array $criteria, array $types = []): int|string
{
$columns = $values = $conditions = $set = [];

Expand Down Expand Up @@ -585,11 +585,11 @@ public function update(string $table, array $data, array $criteria, array $types
* @param array<string, mixed> $data Column-value pairs
* @param array<int, int|string|Type|null>|array<string, int|string|Type|null> $types Parameter types
*
* @return int The number of affected rows.
* @return int|string The number of affected rows.
*
* @throws Exception
*/
public function insert(string $table, array $data, array $types = []): int
public function insert(string $table, array $data, array $types = []): int|string
{
if (count($data) === 0) {
return $this->executeStatement('INSERT INTO ' . $table . ' () VALUES ()');
Expand Down Expand Up @@ -950,7 +950,7 @@ public function executeCacheQuery(string $sql, array $params, array $types, Quer
*
* @throws Exception
*/
public function executeStatement(string $sql, array $params = [], array $types = []): int
public function executeStatement(string $sql, array $params = [], array $types = []): int|string
{
$connection = $this->connect();

Expand Down Expand Up @@ -1496,7 +1496,7 @@ private function handleDriverException(
*
* @throws Exception
*/
public function executeUpdate(string $sql, array $params = [], array $types = []): int
public function executeUpdate(string $sql, array $params = [], array $types = []): int|string
{
return $this->executeStatement($sql, $params, $types);
}
Expand All @@ -1516,7 +1516,7 @@ public function query(string $sql): Result
*
* @deprecated This API is deprecated and will be removed after 2022
*/
public function exec(string $sql): int
public function exec(string $sql): int|string
{
return $this->executeStatement($sql);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Connections/PrimaryReadReplicaConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ protected function chooseConnectionConfiguration(string $connectionName, array $
/**
* {@inheritDoc}
*/
public function executeStatement(string $sql, array $params = [], array $types = []): int
public function executeStatement(string $sql, array $params = [], array $types = []): int|string
{
$this->ensureConnectedToPrimary();

Expand Down
2 changes: 1 addition & 1 deletion src/Driver/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function quote(string $value): string;
*
* @throws Exception
*/
public function exec(string $sql): int;
public function exec(string $sql): int|string;

/**
* Returns the ID of the last inserted row.
Expand Down
2 changes: 1 addition & 1 deletion src/Driver/IBMDB2/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function quote(string $value): string
return "'" . db2_escape_string($value) . "'";
}

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

Expand Down
2 changes: 1 addition & 1 deletion src/Driver/Middleware/AbstractConnectionMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function quote(string $value): string
return $this->wrappedConnection->quote($value);
}

public function exec(string $sql): int
public function exec(string $sql): int|string
{
return $this->wrappedConnection->exec($sql);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Driver/Mysqli/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function quote(string $value): string
return "'" . $this->connection->escape_string($value) . "'";
}

public function exec(string $sql): int
public function exec(string $sql): int|string
{
try {
$result = $this->connection->query($sql);
Expand Down
2 changes: 1 addition & 1 deletion src/Driver/OCI8/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function quote(string $value): string
* @throws Exception
* @throws Parser\Exception
*/
public function exec(string $sql): int
public function exec(string $sql): int|string
{
return $this->prepare($sql)->execute()->rowCount();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Driver/PDO/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct(PDO $connection)
$this->connection = $connection;
}

public function exec(string $sql): int
public function exec(string $sql): int|string
{
try {
$result = $this->connection->exec($sql);
Expand Down
2 changes: 1 addition & 1 deletion src/Driver/SQLSrv/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function quote(string $value): string
return "'" . str_replace("'", "''", $value) . "'";
}

public function exec(string $sql): int
public function exec(string $sql): int|string
{
$stmt = sqlsrv_query($this->connection, $sql);

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

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

Expand Down
4 changes: 2 additions & 2 deletions src/Query/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,11 @@ 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.
*
* @throws Exception
*/
public function executeStatement(): int
public function executeStatement(): int|string
{
return $this->connection->executeStatement($this->getSQL(), $this->params, $this->paramTypes);
}
Expand Down