Iulian Popescu wrote:
I looked at the .dump feature implementation in shell.c as well as how
vacuum is implemented. Based on that an idea will be to iterate through the
metainformation on the SQLITE_MASTER table in order to recreate the new Db
schema and for each table run SQL statements that will transfer the content
from the old db into the new one. However, I was wondering if there is an
easier or computationally less expensive way to accomplish the same thing
(do it without going through each table) something like "cloning" the B-Tree
representing the database.
Iulian,
I looked through the vacuum code as well and that seems like the best
approach to me. I think you might be looking for optimizations that
aren't needed. The copy operation should be very quick with only two SQL
statements executed for each table, one to copy the schema, and one to
copy the contents. The data copy itself will be reading records from one
memory database and writing that record to the other memory database,
one record at a time, but without any conversion from the internal
record format. While not as fast as a direct memory copy, it should be
pretty quick.
I don't think there is any way to clone the B-trees that make up the
database. There is certainly no public API to access the B-trees, so
even if something works today, there is no guarantee that it will work
with the next version of SQLite.
If you really need to copy the database faster than the SQL copy allows,
you might want to talk to Richard Hipp about some paid support. He can
surely let you know if it is possible, and may be able to do it for you
for a reasonable fee.
HTH
Dennis Cote