AutoCommit enables or disables AutoCommit mode.
In AutoCommit mode Zeos will do an implicit commit to the database after each write operation. For databases that do support auto commit on their own (Firebird, MS SQL, ...) Zeos will leave it to the database when to do a commit operation. Usually one would do that kind of thing, if you display some data to your user and any change should be committed to the database immediately. If you ocassionally need a transaction where you want to do multiple operations in one transaction and need to fully be in control of when to commit, you can start an explicit transaction by calling StartTransaction. In that case StartTransaction temporarily disables AutoCommit until you call Rollback or Commit. Either one of them will bring you back to the AutoCommit mode.
Beware: There are cases where Zeos will not be able to identify a write operation and possibly doesn't do a commit. That can happen if you have a stored procedure that changes data and also returns records. In that case your sql probably looks similar to this:
select * from someprocedure;
or
select * from someprocedure(:param1, :param2);
In some of these cases Zeos might think you are only doing a read and doesn't commit immediately afterwards.
If you always want to be in control when to commit, then AutoCommit mode probably isn't for you. In That case set AutoCommit to false. Zeos will start a transaction for you immediately after you connect to the database. Calling Commit or Rollback will end that transaction and immediately start a new transaction. Zeos will never do a commit or rollback on its own.
Maybe there should be
FConnection.StartTransaction
line?Hello Fr0st,
TZAbstractConnection.StartTransaction
is doingAutoCommit := False;
. Imho this callsTZAbstractConnection.SetAutoCommit
which in turn informs the driver about the change by callingFConnection.SetAutoCommit
. For some drivers this is the hint to start an explicit transaction (PostgreSQL). For others it is the hint to stop their emulation of AutoCommit (Oracle, Firebird). I dislike Firebird being in the latter list but that is the current implementation.Well, for FB it really does nothing... seem like forgotten override. As FB's internal autocommit is not used anyway
I guess the override should be added with explicit transaction start.