> I've got one application that writes to the database, and one that reads
> from it. When a table in the database has changed, the reading
> application needs to know that. Of course I can send a signal from the
You may be able to use sqlite_schema:
(From the FAQ)
(17) What is an SQLITE_SCHEMA error, and why am I getting one?
In version 3 of SQLite, an SQLITE_SCHEMA error is returned when a
prepared SQL statement is no longer valid and cannot be executed. When
this occurs, the statement must be recompiled from SQL using the
sqlite3_prepare() API. In SQLite 3, an SQLITE_SCHEMA error can only
occur when using the
sqlite3_prepare()/sqlite3_step()/sqlite3_finalize() API to execute
SQL, not when using the sqlite3_exec(). This was not the case in
version 2.
The most common reason for a prepared statement to become invalid
is that the schema of the database was modified after the SQL was
prepared (possibly by another process). The other reasons this can
happen are:
* A database was DETACHed.
* A user-function definition was deleted or changed.
* A collation sequence definition was deleted or changed.
* The authorization function was changed.
In all cases, the solution is to recompile the statement from SQL
and attempt to execute it again. Because a prepared statement can be
invalidated by another process changing the database schema, all code
that uses the sqlite3_prepare()/sqlite3_step()/sqlite3_finalize() API
should be prepared to handle SQLITE_SCHEMA errors. An example of one
approach to this follows:
int rc;
sqlite3_stmt *pStmt;
char zSql[] = "SELECT .....";
do {
/* Compile the statement from SQL. Assume success. */
sqlite3_prepare(pDb, zSql, -1, &pStmt, 0);
while( SQLITE_ROW==sqlite3_step(pStmt) ){
/* Do something with the row of available data */
}
/* Finalize the statement. If an SQLITE_SCHEMA error has
** occured, then the above call to sqlite3_step() will have
** returned SQLITE_ERROR. sqlite3_finalize() will return
** SQLITE_SCHEMA. In this case the loop will execute again.
*/
rc = sqlite3_finalize(pStmt);
} while( rc==SQLITE_SCHEMA );