Skip to content

Commit

Permalink
Merge pull request #5909 from phansys/last_insert_id
Browse files Browse the repository at this point in the history
Fix type assumptions about `Connection::lastInsertId()`
  • Loading branch information
derrabus authored Feb 7, 2023
2 parents c84d330 + aec9b17 commit 1295b5f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
2 changes: 0 additions & 2 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -878,8 +878,6 @@ public function getTransactionNestingLevel(): int
*
* If the underlying driver does not support identity columns, an exception is thrown.
*
* @return int|string The last insert ID, as an integer or a numeric string.
*
* @throws Exception
*/
public function lastInsertId(): int|string
Expand Down
8 changes: 3 additions & 5 deletions src/Driver/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,16 @@ public function exec(string $sql): int|string;
/**
* Returns the ID of the last inserted row.
*
* This method returns an integer or a numeric string representing the value of the auto-increment column
* This method returns an integer or a string representing the value of the auto-increment column
* from the last row inserted into the database, if any, or throws an exception if a value cannot be returned,
* in particular when:
*
* - the driver does not support identity columns;
* - the last statement dit not return an identity (caution: see note below).
*
* Note: if the last statement was not an INSERT to an autoincrement column, this method MAY return an ID from a
* previous statement. DO NOT RELY ON THIS BEHAVIOR which is driver-dependent: always use getLastInsertId() right
* after executing an INSERT statement.
*
* @return int|string The last insert ID, as an integer or a numeric string.
* previous statement. DO NOT RELY ON THIS BEHAVIOR which is driver-dependent: always call this method right after
* executing an INSERT statement.
*
* @throws Exception
*/
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 @@ -77,7 +77,7 @@ public function exec(string $sql): int|string
return db2_num_rows($stmt);
}

public function lastInsertId(): int|string
public function lastInsertId(): string
{
$lastInsertId = db2_last_insert_id($this->connection);

Expand Down

0 comments on commit 1295b5f

Please sign in to comment.