[Lazarus] SQLite database schema has changed

Luca Olivetti luca at wetron.es
Wed Dec 3 09:25:45 CET 2008


En/na Luiz Americo Pereira Camara ha escrit:

> Try to use the function sqlite3_enable_shared_cache with true as 
> parameter in the start of your application.
> 
> The function declaration:
> 
> function sqlite3_enable_shared_cache(Enable: Boolean): LongInt; cdecl; 
> external 'sqlite3';


I don't think it will help, sqlite will always return the error 
"database schema has changed" if you ALTER any table in the database.
There's a bunch of enhanced "v2" functions (see 
http://sqlite.org/c3ref/funclist.html) to avoid that class of problems, 
but their bindings, AFAIK, aren't available in fpc.

E.g., there's sqlite3_prepare_v2 and sqlite3_prepare16_v2

Quoting from http://sqlite.org/c3ref/prepare.html:

The sqlite3_prepare_v2() and sqlite3_prepare16_v2() interfaces are 
recommended for all new programs. The two older interfaces are retained 
for backwards compatibility, but their use is discouraged. In the "v2" 
interfaces, the prepared statement that is returned (the sqlite3_stmt 
object) contains a copy of the original SQL text. This causes the 
sqlite3_step() interface to behave a differently in two ways:

    1. If the database schema changes, instead of returning 
SQLITE_SCHEMA as it always used to do, sqlite3_step() will automatically 
recompile the SQL statement and try to run it again. If the schema has 
changed in a way that makes the statement no longer valid, 
sqlite3_step() will still return SQLITE_SCHEMA. But unlike the legacy 
behavior, SQLITE_SCHEMA is now a fatal error. Calling 
sqlite3_prepare_v2() again will not make the error go away. Note: use 
sqlite3_errmsg() to find the text of the parsing error that results in 
an SQLITE_SCHEMA return.

    2. When an error occurs, sqlite3_step() will return one of the 
detailed error codes or extended error codes. The legacy behavior was 
that sqlite3_step() would only return a generic SQLITE_ERROR result code 
and you would have to make a second call to sqlite3_reset() in order to 
find the underlying cause of the problem. With the "v2" prepare 
interfaces, the underlying reason for the error is returned immediately.


Bye
-- 
Luca Olivetti
Wetron Automatización S.A. http://www.wetron.es/
Tel. +34 93 5883004      Fax +34 93 5883007



More information about the Lazarus mailing list