Randall Fox wrote:
I believe VACUUM changes the schema version numbering. After you VACUUM, your sqlite3 struct holds information about your previous database version. Solution: reopen the database and SQLite will pick up the new changes. After that, INSERT will not report an error (until you VACUUM again, that is.)


This sounds like a major bug.  I use Sqlite embedded in my app and an
error like that could be catastrophic.  Should I close and reopen the
DB every time after a vacuum?

Is there a fix?

I was not able to recreate the error but I just upgraded to v3 today
so I am still testing..


The steps SQLite uses to process a single statement of SQL are roughly as follows:

   1)  Parse the SQL statement
   2)  Generte virtual machine code to execute the statement
   3)  Open the database file
   4)  Execute the virtual machine code
   5)  Close the database files

Step (2) is based on the last known schema for the database.  When
step (4) begins, the first thing it does is make sure that the schema
used in step (2) is the same as the current schema.  If the schema has
changed, then the generate virtual machine code might be incorrect
so execution aborts with an SQLITE_SCHEMA error.  It also sets a flag
so that the schema will be automatically reread from the database
file prior to doing another parse.

Note that the parser cannot check to see if it has the current
schema because at the time the parser and code generator are
running, the database file is not yet open.

In SQLite version 3.0, when a schema change occurs, SQLite automatically
goes back to step 1, rereads the schema, and tries again.  So you should
never get an SQLITE_SCHEMA error in version 3.0.  Back in version 2.8,
you could get an SQLITE_SCHEMA error in some circumstances.  When you
do, all you have to do is retry the command and it should work.

So to answer your questions:

  No, this is not a serious bug.  You just need to be prepared to
  reissue any SQL statement that returns SQLITE_SCHEMA.

  Yes, this issue is fixed in version 3.0.

--
D. Richard Hipp -- [EMAIL PROTECTED] -- 704.948.4565



Reply via email to