On 9/21/15, Dominique Devienne <ddevienne at gmail.com> wrote: > On Sun, Sep 20, 2015 at 4:10 PM, Igor Tandetnik <igor at tandetnik.org> wrote: > >> On 9/20/2015 9:55 AM, gwenn wrote: >> >>> If there is no way to know that the statement has been recompiled, I >>> guess that the column count should not be cached... >>> >> >> You could use sqlite3_prepare (no _v2), then you'd get an error on schema >> change. You would then re-prepare the statement and update your caches. > > > Could perhaps also use the change counter > https://www.sqlite.org/fileformat2.html#chngctr, if you're not using WAL > mode. > You'd get false positives I guess, since both DML and DDL changes would > increment it, and I'm not sure that's any different from checking the > column_count anyway, but just in case it's useful. --DD
PRAGMA schema_version (https://www.sqlite.org/pragma.html#pragma_schema_version) does what you want. But here the thing: It is probably far more expensive to run PRAGMA schema_version than it is to just rerun sqlite3_column_count(). I think this whole conversation is an exercise in premature optimization. Has anybody actually *measured* a performance problem with sqlite3_column_count()? -- D. Richard Hipp drh at sqlite.org