[Lazarus] SQLDB: how to use TSQLTransaction

Xiangrong Fang xrfang at gmail.com
Sat Apr 11 16:29:59 CEST 2015


2015-04-11 15:41 GMT+08:00 SPRL AFOR <aforsprl at gmail.com>:

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
>

​As a matter of fact, I think yours and Michael's reply both answered part
of my questions but not all. I am now clear about the meaning of
RowsAffected returning value -1, but I am still not clear about WHY
*sometime* I need to use Commit, but other times it is *not* necessary?

If the rule with SQLDB is that I always need to use Commit, fine, I am
perfectly fine with this rule. But, in my function, the Commit is not
necessary, even without it, the UPDATE takes effect.  That's why I am
confused: when must I use Commit, and when it is optional?  Please note
that:

1) I am using SQLDB without a form, so all properties are at their default
value, unless I explicitly change them -- I don't know there are options
like
sqoAutoCommit
​, and I didn't set any properties for sqldb components.​

2) I am using SQLite3, on Ubuntu 14.10 64bit.​


3) I even thought that Commit is necessary when using INSERT, but is
optional if you use UPDATE, but that logic seems weird...​


If you could explain why the behaviors are different that will be very
helpful.

​Thank you very much!​
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20150411/cc7eaaa9/attachment-0003.html>


More information about the Lazarus mailing list