sqlite-jdbc icon indicating copy to clipboard operation
sqlite-jdbc copied to clipboard

java.sql.SQLException: Query returns results when execute DDL statement

Open nikialeksey opened this issue 5 years ago • 6 comments

Enviroment:

  • Java 1.8
  • org.xerial:sqlite-jdbc:3.31.1

Code:

import org.junit.Test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

public class SqliteBug {
    @Test
    public void bug() throws Exception {
        final Connection c = DriverManager.getConnection(
            "jdbc:sqlite::memory:"
        );

        final PreparedStatement stmt1 = c.prepareStatement(
            "CREATE TABLE t (t TEXT)"
        );
        stmt1.executeUpdate();
        stmt1.close();

        final PreparedStatement stmt2 = c.prepareStatement(
            "ALTER TABLE t RENAME TO t2"
        );
        stmt2.executeUpdate(); // java.sql.SQLException: Query returns results
        stmt2.close();
    }
}
Query returns results
java.sql.SQLException: Query returns results
	at org.sqlite.jdbc3.JDBC3PreparedStatement.executeUpdate(JDBC3PreparedStatement.java:92)
	at com.example.SqliteBug.bug(SqliteBug.java:31)
	...

nikialeksey avatar Jun 12 '20 11:06 nikialeksey

What type of result?

michael-o avatar Jun 13 '20 16:06 michael-o

@michael-o I've jist updated the description. I think It should work without any exception.

nikialeksey avatar Jun 14 '20 01:06 nikialeksey

That's interesting. Does it work with filebased DBs too? I assume that the create table statement returns 1 for the column created and that value is retained for the second run: https://github.com/xerial/sqlite-jdbc/blob/d28a8aaa4e1ca6d0795a2926b918d7c22c21cc2b/src/main/java/org/sqlite/core/CorePreparedStatement.java#L47

michael-o avatar Jun 14 '20 09:06 michael-o

@michael-o Yes, for filebased DBs the same exception

nikialeksey avatar Jun 14 '20 09:06 nikialeksey

That actually interesting, I am dumping a subset of an Oracle DB into SQLite with create table statements, but don't do any alter table.

michael-o avatar Jun 14 '20 09:06 michael-o

This test works fine with h2 driver

nikialeksey avatar Jun 14 '20 16:06 nikialeksey

Just tried the code above and it works on the latest master. I will close this.

gotson avatar Aug 30 '22 09:08 gotson

Thanks!

nikialeksey avatar Aug 30 '22 10:08 nikialeksey