You will have to use transactions and put all your database writing commandinside that transaction. So when you call commit everything is stored or you canroolback...