On 4/3/13 2:18 PM, "Nico Williams" <[email protected]> wrote:
>On Wed, Apr 3, 2013 at 4:11 PM, Tiago Rodrigues <[email protected]> wrote: >> I'm writing a small simulation app and for it I would like to use >>SQLite3 >> as an application file format, as suggested by the "Appropriate uses for >> SQLite" page in sqlite.org. More specifically, the page suggests >>calling >> BEGIN TRANSACTION when opening a file and calling COMMIT when saving it >> again, or ROLLBACK if closing it without saving. Simple enough, up >>until >> the point where I want to implement a "Save As..." menu option, where >>the >> current state of the application is saved to a new file (new database) >>with >> the changes, while the changes in the current file are rolled back. >> >> 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. > >So COMMIT first, then backup. Just as "Save" == COMMIT, "Save As..." >== COMMIT then backup to new name (or, if you were working with a temp >DB using a temp filename, maybe rename it into place, but the backup >approach is safest. Presumably you're not racing against another >instance of the same application starting a new transaction on the >same DB (since you seem to keep long-lived transactions anyways), so >this should just work. I've got exactly this use case. I've found it most useful to keep my document files and my run-time DB separate. When my app starts, it opens a temp DB; and when you open a document file it copies the tables individually into the temp DB. On save it does the opposite. Works quite well. Will > >Nico >-- >_______________________________________________ >sqlite-users mailing list >[email protected] >http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users _______________________________________________ sqlite-users mailing list [email protected] http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

