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

getGeneratedKeys() is deprecated #980

Closed
bardware opened this issue Sep 23, 2023 · 6 comments
Closed

getGeneratedKeys() is deprecated #980

bardware opened this issue Sep 23, 2023 · 6 comments
Labels
question Further information is requested

Comments

@bardware
Copy link

I'm just trying to use this JDBC driver from Adobe ColdFusion. I set up a datasource and now wanted to find out how I insert into a database and retrieve a value from an autoincrement column.
I looked into your jar file and see getGeneratedKeys() is deprecated.
There's the comment

@deprecated Not exactly sure what this function does, as it is not implementing any
     *     interface, and is not used anywhere in the code. Deprecated since 3.43.0.0.

There was this question on StackOverflow.
https://stackoverflow.com/questions/64901198/missing-generatedkey-from-query-result
A comment says ColdFusion calls this function, so it can return the value of the autoincrement column, automatically.

So I guess to retrieve the generated value I have to call SELECT last_insert_rowid(), manually.

Can you confirm?

@gotson
Copy link
Collaborator

gotson commented Sep 24, 2023

Or you can use RETURNING clauses, see #963 also

@gotson gotson added question Further information is requested and removed triage labels Sep 24, 2023
@Phoenix616
Copy link

Phoenix616 commented Sep 26, 2023

Well Statement#getGeneratedKeys is part of the jdbc API so not implementing that seems counter-intuitive? I would expect a jdbc-driver to actually implement jdbc specification, not some other API?

The specification even goes as far to say "If the columns which represent the auto-generated keys were not specified, the JDBC driver implementation will determine the columns which best represent the auto-generated keys." meaning that the driver needs to absolutely make sure to return something here if it's even closely possible, no matter if it's a good idea or not.

@gotson
Copy link
Collaborator

gotson commented Sep 27, 2023

https://docs.oracle.com/javase/8/docs/api/java/sql/DatabaseMetaData.html#supportsGetGeneratedKeys-- seem to indicate otherwise.

In addition, the link you mentioned explicitly says :

SQLFeatureNotSupportedException - if the JDBC driver does not support this method

@gotson gotson closed this as completed Sep 27, 2023
@Phoenix616
Copy link

But if SQLite supports that functionality, why would a driver not support it? The link I provided also says:

Note:If the columns which represent the auto-generated keys were not specified, the JDBC driver implementation will determine the columns which best represent the auto-generated keys.

Which indicates that a best-effort approach here is fine and that anyone using the API should not expect it to be 100% accurate. Hence I don't see the need to remove that. If anything the shortcomings in the driver should be documented, not important functionality removed.

@gotson
Copy link
Collaborator

gotson commented Sep 27, 2023

But if SQLite supports that functionality, why would a driver not support it? The link I provided also says:

Note:If the columns which represent the auto-generated keys were not specified, the JDBC driver implementation will determine the columns which best represent the auto-generated keys.

Which indicates that a best-effort approach here is fine and that anyone using the API should not expect it to be 100% accurate. Hence I don't see the need to remove that. If anything the shortcomings in the driver should be documented, not important functionality removed.

Basic support means it should return keys for all the rows inserted, which sqlite cannot do. At best it can only get the ID of a single row.

@gotson
Copy link
Collaborator

gotson commented Sep 27, 2023

See #329 for explanations on previous behavior and its shortcomings.

Repository owner deleted a comment from prrvchr Feb 9, 2024
Repository owner locked as resolved and limited conversation to collaborators Feb 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants