An assertion failure only triggers in JDBC driver with -DSQLITE_DEBUG=1 compile option
(1) By ChiZhang on 2023-03-23 07:43:05 [source]
Consider the following program:
PRAGMA encoding = 'UTF-16';
CREATE TABLE t0 (c1 TEXT );
INSERT INTO t0 VALUES ('');
CREATE INDEX i0 ON t0(c1);
ANALYZE;
SELECT * FROM t0 WHERE t0.c1 BETWEEN '' AND (ABS(''));
The following assertion failure triggers with this program only in JDBC driver which is compiled with -DSQLITE_DEBUG=1
option. It executes normally in CLI.
java: target/sqlite-3.41.2-Linux-x86_64/sqlite3.c:81897: valueFromFunction: Assertion `enc==pVal->enc || (pVal->flags & MEM_Str)==0 || db->mallocFailed' failed.
I write a Java program to reproduce this assertion failure:
package reproduce;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
public class reproduce {
private static final String DRIVER_NAME = "org.sqlite.JDBC";
private static final String URL = "jdbc:sqlite:test.db";
private static Connection connection;
public static void main(String[] args) throws Exception {
try {
Class.forName(DRIVER_NAME);
connection = DriverManager.getConnection(URL);
} catch (Exception e) {
e.printStackTrace();
connection = null;
}
List<String> program = new ArrayList<>();
program.add("PRAGMA encoding = 'UTF-16';");
program.add("CREATE TABLE t0 (c1 TEXT );");
program.add("INSERT INTO t0 VALUES ('');");
program.add("CREATE INDEX i0 ON t0(c1);");
program.add("ANALYZE;");
program.add("SELECT * FROM t0 WHERE t0.c1 BETWEEN '' AND (ABS(''));");
try (Statement statement = connection.createStatement()){
for(String script: program) {
try {
statement.execute(script);
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}catch (Exception e) {
e.printStackTrace();
}
}
}
(2) By Donal Fellows (dkfellows) on 2023-03-23 09:33:44 in reply to 1 [link] [source]
Which SQLite driver for Java are you using (and replacing the SQLite implementation within with a debug build)? The Xerial one?
(3.1) By ChiZhang on 2023-03-23 11:22:41 edited from 3.0 in reply to 2 [link] [source]
Hi Donal Fellows,
Yes, I download the sqlite-jdbc sorce code from https://github.com/xerial/sqlite-jdbc, and add -DSQLITE_DEBUG=1
option at this line.