netcharm / sqlite-jdbc

Automatically exported from code.google.com/p/sqlite-jdbc
Apache License 2.0
0 stars 0 forks source link

Setting "journal_mode" pragma through Properties fails #7

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
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;
  }

Original issue reported on code.google.com by sehar...@gmail.com on 7 Jul 2011 at 2:14

GoogleCodeExporter commented 8 years ago

Original comment by taroleo on 13 Jul 2011 at 1:46

GoogleCodeExporter commented 8 years ago
Thank you for posting the working solution.

Original comment by azmike12...@gmail.com on 21 Jul 2011 at 8:07

GoogleCodeExporter commented 8 years ago
> final 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.

Original comment by Grace.Ba...@gmail.com on 8 Sep 2012 at 4:58

GoogleCodeExporter commented 8 years ago
The change for this is done now.

Original comment by Grace.Ba...@gmail.com on 12 Sep 2012 at 1:06