-
Notifications
You must be signed in to change notification settings - Fork 632
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
Proper / secure way to receive last_insert_rowid #329
Comments
|
I was recently working to fix #330 and i stumbled upon this.
I agree with you on this, the generated keys should be related to the
This is not as simple though, as you can insert multiple values, and I see a few possible options:
|
I've been thinking about this, and I think option 2 would require to have a sql parser. We would need to be able to find out whether there is already a RETURNING clause, and also to find out what's the table name so that we can infer the generated keys too. |
SQLite does not provide a good way to retrieve generated keys in a reliable way BREAKING-CHANGE: getGeneratedKeys is not supported anymore Closes: #329
@b3nn0 in the next major version the driver will not support anymore |
Alright, makes sense. Closing this then. |
This will be closed automatically once merged |
🎉 This issue has been resolved in |
How is removing a feature resolved? Anyway it breaks Persism but I'm doing it the new way for SQLite and it's working so I'll put out an update soon. |
SQLite does not provide a good way to retrieve generated keys in a reliable way BREAKING-CHANGE: getGeneratedKeys is not supported anymore Closes: xerial#329
* Bump org.xerial:sqlite-jdbc from 3.36.0 to 3.43.2.2 Bumps [org.xerial:sqlite-jdbc](https://github.com/xerial/sqlite-jdbc) from 3.36.0 to 3.43.2.2. - [Release notes](https://github.com/xerial/sqlite-jdbc/releases) - [Changelog](https://github.com/xerial/sqlite-jdbc/blob/master/CHANGELOG) - [Commits](xerial/sqlite-jdbc@3.36.0...3.43.2.2) --- updated-dependencies: - dependency-name: org.xerial:sqlite-jdbc dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * Exclude all databased from regular tests * Disable upsert tests, as SQLite don't support it xerial/sqlite-jdbc#329 --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Marvin Froeder <velobr@gmail.com>
If I am reading this correctly, the ability to obtain the generated keys has been removed entirely with no "proper" way to do it? Those of us who were managing our connections and atomically doing single inserts and then immediately obtaining the generated keys were having no problem with the existing functionality because we understood that using it meant doing a single insert and before letting any other thread get your Simply removing this functionality because it did not work for those who did not understand how to do it safely seems like a non-fix but like crippling access to SQLite via JDBC. |
BINGO! You are so right. Somebody dropped the ball here. |
Hi,
right now there are multiple ways to retrieve the last inserted rowid of an insert.
None of them is very good.
Query for "SELECT last_insertrowid()":
-> Doesn't work in multithreaded applications
Add the select statement directly behind the INSERT query, e.g.
"INSERT INTO a VALUES('x'); SELECT last_insert_rowid()"
-> Doesn't work when the insert is a prepared statement. SQLite will only respect the first statement.
Call stmt.getGeneratedKeys()
-> Just as unreliable. It seems to do a lazy call to last_insert_rowid(), which is, in my opinion, a bug.
As SqliteJdbc seems to synchronize everything going to SQLite, it would be quite easy to fix.
To do so, the library simply would need to call sqlite3_last_insert_rowid() right after the query.
JDBC already provides the API, see Statement.RETURN_GENERATED_KEYS constant.
Implementing it should be quite simple...
I could potentially provide a patch, if it has the chance to be accepted.
The text was updated successfully, but these errors were encountered: