[Lazarus] SQLDB: how to use TSQLTransaction

SPRL AFOR aforsprl at gmail.com
Sat Apr 11 09:41:05 CEST 2015


Le 11/04/2015 03:53, Xiangrong Fang a écrit :

The transaction process depends upon the DBMS used. In a general way, 
all DBMS execute SQL statement under the control of a transaction. Some 
of the DBMS (MS SQL Server) use to have "automatic" transaction control 
as default and some others (Firebird) need explicit Start and Commits. 
Using Oracle definition a transaction "is a logical, atomic unit of work 
that contains one or more SQL statements". I'm used to always work with 
fine tuned transaction control. This way I know what the DBMS is doing 
with data.
>
> 1. How to control the use of transactions in SQLDB? Sometime I do NOT 
> want transaction, but want the DDL/DML statement to be executed 
> immediately. Why sometime SQLDB's ExecSQL won't take effect if not 
> followed by a Commit? BTW, I tried to set tr.Active to true/false 
> before execute the sql, but it seems not making a difference?
>
Michael's comments do not need further explanation

If you want an Sql statement be executed immediately attach an 
TSqlTransaction to a DB component, attach the TSqlQuery  to the 
transaction and enclose it between a StartTransaction and a Commit.

TR.StartTransaction;
qr.ExecSql;
TR.Commit;

The Commit matters as well

Working with DBMS since a long time, I always use the same rules: Start 
a transaction, do whatever Sql statements have to be done all together, 
Commit the transaction. This way I control how data is goes to and from 
the databsase.
> Xiangrong
>
>
> --
> _______________________________________________
> Lazarus mailing list
> Lazarus at lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus



---
L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel antivirus Avast.
http://www.avast.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20150411/cfe313a7/attachment-0003.html>


More information about the Lazarus mailing list