[SQLiteJDBC] No ResultSet for PRAGMA incremental_vacuum

Brain N brainn at gmail.com
Thu Dec 17 16:55:05 EST 2009


I've ran into an interesting problem when trying to execute the
incremental_vacuum pragma.  It doesn't work with executeUpdate, and
executeQuery tells you that it doesn't contain a result set.  When you use
the plain execute function, it only deallocates a single page, even if you
tell it to free more.

It turns out that executing this pragma in the C api works like this.  When
you execute "PRAGMA incremental_vacuum(10);"

1.  prepare statement returns SQLITE_OK
2.  step returns SQLITE_ROW the next 10 times you call it
3.  step returns SQLITE_DONE

So basically, it acts like it returned a result set.  Every time you step
through the result set, a free page is vacuumed.

So the next question is, why doesn't sqlitejdbc let me run it as a query and
return me a result set?  It should return me a ResultSet and let me step
through the results.  It turns out when looking at the code that everywhere
it checks for a result set, it checks to see if the column count is
non-zero.  We need to return a ResultSet in both of these 2 cases:

1.  All normal queries will have columns.  But sometimes they have no rows.
2.  incremental_vacuum returns rows, but no columns.

So I think that everywhere that we check for a result set, we need to change
 "column_count != 0" to "column_count != 0 || resultsWaiting".  I've tried
this and it doesn't break any of the unit tests.

I've hacked mine together and got incremental_vacuum to work fine by
stepping through the ResultSet it returns.  Unfortunately I don't have a
nice patch that I can give yet.  I'll make one soon.

If anyone has any comments, let me know.  Does the actual package maintainer
still read these?


More information about the SQLiteJDBC mailing list