On Wed, Apr 3, 2013 at 4:11 PM, Tiago Rodrigues <wtrm...@gmail.com> 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. Nico -- _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users