If one attempts to set the "journal_mode" pragma by using a Properties bag supplied to DriverManager#getConnection(), method SQLiteConfig#apply(Connection) fails.
Per the documentation for the "journal_mode" pragma
http://www.sqlite.org/pragma.html#pragma_journal_mode
when issuing the PRAGMA statement,
The new journal mode is returned. If the journal mode could not be changed, the original journal mode is returned.
This means that issuing this pragma bears a result set, but SQLiteConfig#apply() uses Statement#executeBatch(), which throws an exception if /any/ of the individual statements yielded a result set.
Method DB#executeUpdate() -- called on from Stmt#executeBatch() -- ensures that the executing the statements did not return SQLITE_ROW. Apparently issuing the "journal_mode" pragma does provoke this response.
Would it be possible to partition the known pragmas into those that are expected to yield no result and those that will, so that you can use a different and appropriate method to execute each set?
I see this using version 3.7.2 of the library on Windows XP.
To reproduce the problem, try the following:
final Properties p = new Properties();
p.setProperty("journal_mode", "WAL");
DriverManager.getConnection("jdbc:sqlite:file.db", p);
I've worked around the problem for now with the following function, applied to a freshly-created connection:
private static Connection configure(Connection conn) throws SQLException { final Statement statement = conn.createStatement(); statement.execute("PRAGMA journal_mode = WAL;"); statement.close(); return conn; }
Comment #1
Posted on Jul 13, 2011 by Helpful Cat(No comment was entered for this change.)
Comment #2
Posted on Jul 21, 2011 by Quick MonkeyThank you for posting the working solution.
Comment #3
Posted on Sep 8, 2012 by Quick Pandafinal Properties p = new Properties(); p.setProperty("journal_mode", "WAL"); DriverManager.getConnection("jdbc:sqlite:file.db", p);
A fix for this was pushed in the source code. Should work in the next release.
Comment #4
Posted on Sep 12, 2012 by Quick PandaThe change for this is done now.
Status: Fixed
Labels:
Type-Defect
Priority-Medium
AffectedVersion-3.7.2
FixedVersion-NA