BareFeetWare
2010-12-23 04:10:30 UTC
Hi all,
I want to dynamically construct SQL queries that rollback if any part of the transaction fails. For instance, my app constructs the SQL needed to replace a trigger definition, such as:
begin immediate;
drop trigger if exists "My Trigger";
create trigger "My Trigger"
... new definition
;
commit;
If the new definition fails, I want to rollback so that the old definition remains.
I was under the impression that if any error occurred in the transaction that SQLite would rollback, but it seems that it only does this in some cases. According to:
http://www.sqlite.org/lang_transaction.html
Is there a way to do this in pure SQL, without my application code having to check for errors along the way and then interrogate the SQL to look for a "commit" type line and replace it? This seems pretty error prone and convoluted.
Thanks,
Tom
BareFeetWare
--
Comparison of SQLite GUI tools:
http://www.barefeetware.com/sqlite/compare/?ml
I want to dynamically construct SQL queries that rollback if any part of the transaction fails. For instance, my app constructs the SQL needed to replace a trigger definition, such as:
begin immediate;
drop trigger if exists "My Trigger";
create trigger "My Trigger"
... new definition
;
commit;
If the new definition fails, I want to rollback so that the old definition remains.
I was under the impression that if any error occurred in the transaction that SQLite would rollback, but it seems that it only does this in some cases. According to:
http://www.sqlite.org/lang_transaction.html
Response To Errors Within A Transaction
• SQLITE_FULL: database or disk full
• SQLITE_IOERR: disk I/O error
• SQLITE_BUSY: database in use by another process
• SQLITE_NOMEM: out or memory
• SQLITE_INTERRUPT: processing interrupted by application request
For all of these errors, SQLite attempts to undo just the one statement it was working on and leave changes from prior statements within the same transaction intact and continue with the transaction. However, depending on the statement being evaluated and the point at which the error occurs, it might be necessary for SQLite to rollback and cancel the entire transaction.
So, it seems I have to, in my application code, step through each command in the SQL transaction, note any error, then when it gets to a "commit" command, replace it instead with a "rollback".• SQLITE_FULL: database or disk full
• SQLITE_IOERR: disk I/O error
• SQLITE_BUSY: database in use by another process
• SQLITE_NOMEM: out or memory
• SQLITE_INTERRUPT: processing interrupted by application request
For all of these errors, SQLite attempts to undo just the one statement it was working on and leave changes from prior statements within the same transaction intact and continue with the transaction. However, depending on the statement being evaluated and the point at which the error occurs, it might be necessary for SQLite to rollback and cancel the entire transaction.
Is there a way to do this in pure SQL, without my application code having to check for errors along the way and then interrogate the SQL to look for a "commit" type line and replace it? This seems pretty error prone and convoluted.
Thanks,
Tom
BareFeetWare
--
Comparison of SQLite GUI tools:
http://www.barefeetware.com/sqlite/compare/?ml