-
Notifications
You must be signed in to change notification settings - Fork 595
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
SQLException: The prepared statement has been finalized #731
Comments
I'm wondering why you would execute a single command containing only |
It may be randomly generated by my application when converting external data to SQL query. |
I just tried the following: @Test
public void issue731() throws Exception {
Connection conn = getConnection();
Statement stmt = conn.createStatement();
stmt.executeUpdate(";");
stmt.close();
conn.close();
} And i don't get any exception. Can you try with the latest snapshot version to confirm on your side? |
@bajinsheng - I think you made a mistake in your test case that fails - I think you intended to call I think the bug here is that we throw the wrong error from the wrong place. Internally, sqlite3 gives us a null pointer from sqlite3_prepare_v2 (https://www.sqlite.org/draft/c3ref/prepare.html) when we create this query. Oddly enough, I don't get an error from the return code from this function. I don't see that the sqlite3 documentation defines the return code for this scenario, but it's definitely possible that I am missing something. From the docs:
Anyways, the exception is thrown because the pointer is set to null with a successful return code. When we try to use it, we check whether it's null first, and throw the already closed exception if it is. @gotson - I think the issue here is that we should be checking for null in the prepared statement made with sqlite3_prepare_v2. If it is null, we should throw an SQLException that ";" is an invalid query, rather than bombing later. Alternatively we could return a empty ResultSet. What do you think? I haven't seen anything within the JDBC spec for what to do when a noop query is run. |
@pyckle i was thinking that in doubt we should check what's the behaviour with another JDBC driver, maybe the PostgreSQL one. What do you think? I know SQLite itself is usually following the PG implementation. |
Hi, when I execute the query ";" in the JDBC and get the "The prepared statement has been finalized" error, but there is no error when I execute the query ";" in the cli.
Reproducible test case:
The stack trace:
SQLite3 JDBC version:
3.36.0.3
Is it expected?
The text was updated successfully, but these errors were encountered: