Hello list

I am sometimes seeing the error SQLITE_CORRUPT with message "database disk 
image is malformed", when I attempt CREATE TEMP TRIGGER. My test spawns 5 
threads, each of which modifies and queries its own table in a common database 
(each thread uses a separate connection from sqlite3_open_v2() to the same 
filename with shared cache enabled). The error occurs when one thread attempts 
CREATE TEMP TRIGGER while another thread is closing its own database connection 
(I have proved this by protecting all calls except these with semaphores). 
Looking through the SQLite 3.6.12 amalgamation code I found the following 
comment in sqlite3VdbeExec():

  ** Although the mutex on the BtShared object that corresponds to
  ** database iDb (the database containing the sqlite_master table
  ** read by this instruction) is currently held, it is necessary to
  ** obtain the mutexes on all attached databases before checking if
  ** the schema of iDb is loaded. This is because, at the start of
  ** the sqlite3_exec() call below, SQLite will invoke 
  ** sqlite3BtreeEnterAll(). If all mutexes are not already held, the
  ** iDb mutex may be temporarily released to avoid deadlock. If 
  ** this happens, then some other thread may delete the in-memory 
  ** schema of database iDb before the SQL statement runs. The schema
  ** will not be reloaded becuase the db->init.busy flag is set. This
  ** can result in a "no such table: sqlite_master" or "malformed
  ** database schema" error being returned to the user.

Could this be the reason for the error I'm seeing? Is this a known issue or 
expected behaviour? Do I need to protect DDL calls on multiple connections to 
the same database, or this there some other way to protect against this 
possibility?

Cheers,
Dave.
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to