WIESEN Bruno <[EMAIL PROTECTED]>
wrote:
INSERT INTO Account VALUES (1,"8888"); --> OK
INSERT INTO Account VALUES (2,"8888"); --> error 19
BEGIN TRANSACTION;
INSERT INTO Account VALUES (1,"8888");
INSERT INTO Account VALUES (2,"8888");
COMMIT; --> no error
Why doesn't the commit raise an exception?
Why should it? The error has already happened at INSERT. If you want,
you can react to that error and rollback the transaction.
See also http://sqlite.org/lang_conflict.html . If you want any failure
to automatically roll back the whole transaction, you can create your
table like this:
CREATE TABLE Account (accountPk INTEGER PRIMARY KEY NOT NULL,
number CHAR(10) UNIQUE ON CONFLICT ROLLBACK);
You don't need a separate index, UNIQUE constraint will automatically
create one.
Alternatively, you can add conflict resolution clause to each individual
INSERT statement:
INSERT OR ROLLBACK INTO Account VALUES (2,"8888");
How can we know that
something has failed in a transaction?
You look for errors from each individual statement.
Igor Tandetnik
-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------