On 23 Mar 2011, at 2:55am, BareFeetWare wrote:

> begin immediate;
> create temp table "My Table Backup" as select * from "My Table";
> drop table "My Table";
> create table "My Table" (<new definition here with foreign keys>);
> insert into "My Table" select * from "My Table Backup";
> drop table "My Table Backup";
> commit;
> 
> Unfortunately SQLite doesn't automatically rollback a transaction if the 
> create or drop statements fail. So you have to detect any errors and, if so, 
> issue a rollback (instead of commit).

If I may suggest an additional check, compare the number of rows in the 
original table and the replacement table.  If they don't match, something went 
wrong.

Last month I spent two days rescuing data on a problem which would have been 
caught by that test.  Fortunately I was being paid for it, but I had better 
things to do with the time.

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

Reply via email to