Am 03.04.2013 23:11, schrieb Tiago Rodrigues:

I'm writing a small simulation app and for it I would like to use SQLite3
as an application file format,  ...
> ...
For that, the simplest idea would be to use the online backup family of
functions, calling sqlite3_backup_init() and sqlite3_backup_step() on the
database, calling COMMIT on the backup and ROLLBACK on the original.
Naturally, that doesn't work, as you can't back up a database in the middle
of a transaction -- sqlite3_backup_step() returns SQLITE_BUSY.

That being said, has anyone on the list encountered (and hopefully solved)
this particular problem?

Don't know why you want to hold "a session open" on your original
(initial) DB-File for that long...

One can open ones own "Application-Format-File" from a FileDB-
Template - or from any (already written, existing) "Document-File"
on Disk - by just "touching" those FileDBs (those need to be open
only for a very short moment)...

Meaning, "your current-working-set" (the DB you work against)
could always be an InMemory-DB - but you can write the current
content of this MemDB at any time (to any FileName on Disk),
over the Backup-API.

And as said, in the opposite direction, you can use the Backup-API
as well, to open from any File(Template) already existing on Disk.

Read-direction:
- Open FileDB-Connection
- use the Backup-API to create a copy as a MemDB-Connection
- Close the FileDB-Connection immediately after that...

Time needed for that "Copy-Over" ... (just tested here against
an about 1.3MB large File-DB -> NWind.db - with 15 Tables or so):
about 10msec.

Write-Direction has about the same Performance.

Since the Backup-API works Page-based, you can expect
the Read/Write-throughput of the Disk - and for smaller
Files in the range of about 50kB to 2MB, this just makes
"blink" (allowing even "naive" Undo/Redo-scenarios (where
you read/write the whole DB to and from Memory) ...with a
depth of e.g. 15-30, when your "AppDB" is not that large
(there's a lot of App-Data which fits into DBs, smaller
than 1MB).

Olaf







_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to