>>>>> "Stas" == Stas Bekman <[EMAIL PROTECTED]> writes:

    Stas> In general it is good practice to perform an explicit commit
    Stas> or rollback at the end of every script.  In order to avoid
    Stas> inconsistencies in the database in case C<AutoCommit> is
    Stas> I<Off> and the script finishes without an explicit rollback,
    Stas> the C<Apache::DBI> module uses a C<PerlCleanupHandler> to
    Stas> issue a rollback at the end of every request.

I believe this paragraph spells it out, to my satisfaction anyway.  If a
script exits without committing (or rolling back) a transaction that is
currently in progress, the database remains in the uncommitted state.
Thus any data modified by the script is not actually fully modified,
just ready to be modified.  Subsequent requests to the database would
return inconsistent views of this data, i.e. views of the data prior to
the transaction, but not necessarilly what the data will look like once
the transaction is committed.

The reasonable thing to do then, not knowing why a transaction might
still open at this point in the logic flow, is to clean up in a
non-destructive fashion when a script exists.  If for example
transaction still is open when a script exits, it is either a result of
programmer, design or logic error, or something unexpected has occurred
during the course of script execution which was not properly handled.
Therefore instead of committing the transaction that contains
potentially unknown consequences, get rid of it and put things back the
way they were.

In this case the idiom appears to be "better to do nothing now than to
try and later undo something that was done unexpectedly", and I guess I
would agree in this case.

Interesting behavior ... I did not know Apache::DBI did this!

Peace.

Reply via email to