2009/6/2 Kees Nuyt <k.n...@zonnet.nl>:
> On Tue, 2 Jun 2009 10:35:12 -0300, Karl Brandt
> <brandk...@gmail.com> wrote:
>>
>>Let me explain the complete picture so someone can help me.
>>
>>I develop a wrapper around sqlite that tracks the changed records and
>>than save the changes to the database by building and executing a SQL
>>query (a transaction).
>>
>>Currently it executes the SQL and check the return value.
>>If the return value is different from SQLITE_OK it executes a
>>separated ROLLBACK command so another transaction can be started.
>>
>>The problem is that after the ROLLBACK command, sqlite3_errmsg will
>>return "no error", giving the user no clues of what happened.
>>
>>I tried INSERT OR ROLLBACK syntax but it will work only for
>>SQLITE_CONSTRAINT. I would need to handle also SQLITE_ERROR.
>>
>>So there's a way to check if a transaction failed (for constraint or
>>another error) and than rollback without clearing the error message
>>returned by sqlite3_errmsg?
>
> After a ROLLBACK; there is no error (ROLLBACK is succesful),
> so the error message will be cleared.
>
> You can use INSERT .... ON CONFLICT ABORT ... ;
> Catch the constraint error, fetch the sqlite3_errmsg() and
> ROLLBACK yourself.
>

Thanks.
I'm aware of this solution. The problem is that storing the
sqlite3_errmsg result is not doable because i expose the return (or
error) message in a separated function, so i'd need to store the msg
in the other functions where a sql is executed leading to poor
performance (not always the user check for the return string).

It works like that:

ApplyUpdates executes the query
ReturnString returns the return/error string by calling sqlite3_errmsg

call ApplyUpdates
if something got wrong check ReturnString value

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

Reply via email to