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

Fix type assumptions about Connection::lastInsertId() #5909

Merged
merged 1 commit into from
Feb 7, 2023
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
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