Thanks for investigating.
There's code within DBD::SQLite's dbdimp.c which does
something like the FAQ snippet, but only at the
start of an execute, not after calling sqlite's finish
within the execute.
The SQL string and bind variables are already retained
but the DBD C code so it seems possible to transparently
re-prepare. There are even functions to help do this
in sqlite (transfer_bindings and reset or something).
Unfortunately, this application needs an ANALYZE after
inserting all the basic data in order to run queries
with a sane plan.
What's more, it's not only the ANALYZE that
causes the problems and I also add indexes after
bulk loading data. There are probably ways
to paper over the problem, something like pinging
after each troublesome action.
If it is indeed a
problem at the DBD level and can be addressed there
then that's my preferred solution.
I suspect that there may be a obstacles ahead though.
Update: The new version of
prepare
doesn't fail on schema changes. This may fully or partially
fix the problem.