Why not just test the status returned by sqlite3_step? Use sqlite3_prepare_v2 to make the returned status give more information.

When you get an error just finalize your COMMIT statement and move your pointer from the prepared COMMIT statement to a ROLLBACK and shortcut the transaction. Instead of committing you will rollback.

arbalest06 wrote:
good day!

i think its really a good solution to this problem. However, im required to
implement the c apis of sqlite..so i need to use the sqlite3_commit_hook and
sqlite3_rollback_hook..im doing some prototyping to see their
functionalities but i really cant make it work..and i also cant find some C
sample source code using these apis..if it is possible, can someone post
some c code using these apis?..

thank you and more power!

God bless!..


John Stanton-3 wrote:
All you need to do is to test the returned status of your sqlite3_step calls and if you get an error launch an SQL statement "ROLLBACK" and bail out of the transaction. If there are no errors you complete your transaction with an SQL "COMMIT".

    sqlite_prepare_v2 SQL statements

    exec BEGIN

    count = 0;
    while ((count < MAX) && !error) {
      rc = sqlite3_step SQL statement[count++];
      if (rc != SQLITE_OK) {
        error = TRUE;
      }
    }
    if (error) exec ROLLBACK
    else exec COMMIT

d_maniger06 wrote:
good day!..

i have a list of records that i want to insert in my database..if ever an
error occurred ( e.g. insert was not successful ), i want to undo all the
previous inserts that i have done..to do this, i have read that i would
need
to use sqlite3_commit_hook and sqlite3_rollback_hook..i have read their
descriptions in the sqlite site, but i really can't understand it..im
just a
newbie in sqlite by the way..i also have tried searching sample c codes
that
does these things but i really cant find any..

i would just like to request a simple sample code demonstrating on how to
use these two apis..if it is ok also, please leave a very brief
explanation
on what happened in the code..

thank you and God bless!.. :working:

-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------






-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to