Repository navigation
Conversation
Oracle has no last ID of a session, so lastInsertId($name) returns CURRVAL of the sequence, e.g. ISEQ$$_123 of an identity column. The name can't be bound in SELECT, so it is bound in a PL/SQL block, checked by DBMS_ASSERT.QUALIFIED_SQL_NAME() and selected by EXECUTE IMMEDIATE. lastInsertId() without a name still fails with IM001. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
|
The CI failures are pre-existing: the new |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PDO_OCI has no
last_idhandler, soPDO::lastInsertId()always fails with IM001 "driver does not support lastInsertId()", even when it is given the name of a sequence. Applications and libraries have to queryCURRVALthemselves, and for an identity column they first have to find its system sequence (ISEQ$$_123) inUSER_TAB_IDENTITY_COLS.This implements
lastInsertId($name)asCURRVALof the named sequence in the current session, the same aspdo_pgsqldoes withSELECT CURRVAL($1). Without a name, it still fails with IM001: Oracle has no last ID of a session, only of a sequence.The name of a sequence can't be a bind variable in
SELECT, so it is bound in a PL/SQL block instead, checked byDBMS_ASSERT.QUALIFIED_SQL_NAME()and selected byEXECUTE IMMEDIATE:That keeps the validation of identifiers (unquoted, quoted, schema-qualified) in Oracle instead of the driver, and the errors are Oracle's own: ORA-08002 before the first
NEXTVALin the session, ORA-02289 for a missing sequence, ORA-44004 for anything that isn't a name. The block is executed withOCI_DEFAULT, so it never commits.DBMS_ASSERTexists since Oracle 10g R2.The new test
pdo_oci_last_insert_id.phptuses a plain sequence, so it runs on Oracle 11 as well, and covers no name,CURRVALbeforeNEXTVAL, lowercase, uppercase, quoted and schema-qualified names, an injection attempt, a missing sequence and the silent error mode.Tested on Windows 11 x64 with PHP 8.5.12 NTS VS17 x64 and Oracle Database 21c Express Edition, with the extension built from this branch with the PHP 8.5.12 devel pack. The new test passes; with the released 1.2.0 DLL it fails. The rest of
tests/gives the same results with both DLLs.