On 2015-09-05 10:18 PM, Petr L?z?ovsk? wrote: > Have some shell scripts working with sqlite. Receiving incoming payments from > bank via HTTP API and pushing it into database. This script will start > periodically, every single hour. > > Want to prevent situation only few payments are written and script failed for > some reason. Have read about sqlite transactions and understood so I should > start every writing sequence with BEGIN; statement, than made all inserts and > than COMMIT; statement. Is this all how it is working? Should I do something > more to prevent such unwanted situation?
It is indeed all you need. If the transaction fails an error will write to stdout (assuming you use the SQlite3.exe or other CLI) - it might be prudent in your scripts to watch for errors and call ROLLBACK (as opposed to COMMIT). Note that not all errors need to roll-back, You can specify in the schema the error handling, and some within the SQL statements. On the other hand you might wish to roll back in special cases even on non-error circumstances. See: http://www.sqlite.org/syntax/conflict-clause.html in conjunction with: http://www.sqlite.org/lang_createtable.html and other constraint specifications. Cheers, Ryan