MikeW <[EMAIL PROTECTED]> wrote:
> I presume I'm not allowed to do this:
>
> // apply updates on first db - start Transaction
> ret = sqlite3_exec(
>                    first_db,
>                    "BEGIN; UPDATE " FIRST_DB_TABLE
>                    " SET " FIRST_DB_COLUMN "=1 "
>                    " WHERE " FIRST_DB_COLUMN " NOT NULL;",
>                     NULL, NULL, NULL));
> // returns SQLITE_OK
>
> // delete updates from second db - commit Transaction
> ret = sqlite3_exec(
>                    second_db,
>                    "UPDATE " SECOND_DB_TABLE
>                    " SET " SECOND_DB_COLUMN "= NULL "
>                    " WHERE " SECOND_DB_COLUMN " NOT NULL; END;",
>                     NULL, NULL, NULL));
> // returns SQLITE_INTERNAL

Do the two DB connection handles (first_db and second_db) refer to the 
same file? However, in this case I would expect SQLITE_BUSY, not 
SQLITE_INTERNAL. There must be some other problem, in the code you don't 
show.

> Still, I would like to be able to run the Transaction over these two
> calls

You can't. A transaction is a property of a connection. You can't have a 
single transaction spanning multiple connections.

You can, however, have the same connection refer to more than one 
database file. See ATTACH statement. This way, you can update several 
files within a single transaction.

> ... What's the best way, given I have two separate handles ?
> Make them separate Transactions and do a ROLLBACK on the first if the
> second exec fails, possibly ?

That's unreliable. E.g., you run the first transaction but keep it open 
(so you can roll it back). You run the second transaction - it succeeds. 
But before you have a chance to commit the first one, there's a power 
failure. When your program is restarted, the first transaction will be 
rolled back, and you will end up with an inconsistent state.

Igor Tandetnik 



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

Reply via email to