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

Support multiple queries in a single statement

Open necouchman opened this issue 8 years ago • 2 comments

I'm using this JDBC driver in the Apache Incubator Guacamole project, with MyBatis and Guice, to try to make the SQLite database available as an authentication back-end for the product. In a couple of places in the code (1, 2), there are prepared statements passed to the JDBC drivers that contain multiple select statements from different tables, each terminated by a semicolon. This allows the Java code to make a single method call that runs both queries and returns a single result map, and keeps the code simple. It works perfectly fine for MySQL, PostgreSQL, and SQL Server, but generates this ArrayIndexOutOfBoundsException when used with this SQLite JDBC driver.

When the batch array is allocated in the CorePreparedStatement class, it's allocated based on the number of parameters. However, when multiple select statements are used that expect the same parameters to be passed, there will be x * y number of positions, where x is the parameter count and y is the number of SELECT statements, which is what results in the index out of bounds exception.

I'm not sure if batch needs to be dynamically allocated or resized, or if the size that it needs to be can be computed from other available parameters to get the total position count, but the current method does not allow for multiple statements to be prepared properly.

necouchman avatar Oct 13 '17 16:10 necouchman

~~Is this still happening on the latest version?~~

gotson avatar Jul 29 '22 05:07 gotson

Just checked this a bit more, it's not supported in the driver.

It seems it would be possible from the SQLite C API, which can return the unused portion of the SQL query.

gotson avatar Sep 20 '22 03:09 gotson