Re: Transaction-handling issues
Ed Pasma <[email protected]>
| Newsgroups | gmane.comp.python.db.pysqlite.user |
|---|---|
| Message-ID | <[email protected]> |
Ed Pasma wrote:
> Now I like to know if the following proposal makes sense.
>
> To make PySQLite handle commit as an SQL-statement equally to the
> method. The only distinction would be that the method nay be called
> also if there are no changes to commit.
>
> Secondly, but this may be more dificult, to allow a transaction to be
> explicitly started using BEGIN also when in the default operating
> mode. The interface should then be aware of the new transaction state.
Just in case I did not make myself clear enough, here is the changes
to the code (that appears to be less text). I'll be happy to live
without it, but it definitely makes the mechanism more robust.
In cursor.h, STATEMENT_BEGIN, STATEMENT_COMMIT and STATEMENT_ROLLBACK
are added to the list of statement types.
In cursor.c processing for the new types is added at three places:
71a72,77
> } else if (!strcmp(buf, "begin")) {
> return STATEMENT_BEGIN;
> } else if (!strcmp(buf, "commit")) {
> return STATEMENT_COMMIT;
> } else if (!strcmp(buf, "rollback")) {
> return STATEMENT_ROLLBACK;
534a541,544
> case STATEMENT_BEGIN:
> case STATEMENT_COMMIT:
> case STATEMENT_ROLLBACK:
> break; /* comes after step is succeeded */
696a707,713
> break;
> case STATEMENT_BEGIN:
> self->connection->inTransaction = 1;
> break;
> case STATEMENT_COMMIT:
> case STATEMENT_ROLLBACK:
> self->connection->inTransaction = 0;
The usage manual may leave out the restriction for not to use commit
or rollback now, only the restriction for ON CONFLICT ROLLBACK remains.