-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Current sequence value should not be used for tracking last inserted ID #4687
Labels
Milestone
Comments
morozov
added a commit
to morozov/dbal
that referenced
this issue
Jun 23, 2021
morozov
added a commit
to morozov/dbal
that referenced
this issue
Jun 23, 2021
morozov
added a commit
to morozov/dbal
that referenced
this issue
Jun 23, 2021
morozov
added a commit
that referenced
this issue
Jun 25, 2021
[GH-4687] Deprecate Connection::lastInsertId($name)
morozov
added a commit
to morozov/dbal
that referenced
this issue
Jun 25, 2021
morozov
added a commit
to morozov/dbal
that referenced
this issue
Jun 25, 2021
morozov
added a commit
that referenced
this issue
Jun 26, 2021
[GH-4687] Remove support for Connection::lastInsertId($name)
This was referenced Jul 17, 2021
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Bug Report
Summary
DBAL replicates the PDO function
PDO::lastInsertId(string $name)
which will return the current value of the sequence$name
. As the function name implies, this should allow doing anINSERT
and then getting the value of an auto-increment column that is internally implemented via a sequence (e.g. on Oracle). The value is primarily meant to be used to reference the newly created row.While it may work, it's not safe in scenarios where multiple concurrent connections insert a row and then introspect the sequence.
Current behaviour
Unlike the identity column value which is scoped to a connection, the current sequence value is global (which is by design: the sequence value must be unique across all connections), so multiple concurrent connections get the same last inserted value.
How to reproduce
The following scenario was run on Oracle:
The issue is not reproducible on PostgreSQL because the return value of
CURRVAL(regclass)
is scoped to the current session (documentation).Additionally, some drivers that don't support sequences will just return the identity column value which is also unsafe:
dbal/src/Driver/Mysqli/Connection.php
Lines 135 to 138 in 8582d5c
dbal/src/Driver/IBMDB2/Connection.php
Lines 120 to 123 in 3c84585
Expected behavior
The sequence-based implementation has the same semantics as the one based on identity column (e.g. on MySQL):
The text was updated successfully, but these errors were encountered: