Subject | RE: [IBO] How to commit an update from code? |
---|---|
Author | Eric Tishler |
Post date | 2004-04-05T12:03:56Z |
Thank you for making these distinctions Helen. I inherited a large base (over 50K lines of Delphi) to maintain and improve. I am stii a bit of a neophyte with IBO and Delphi, but help like yours certain speeds my process of coming up to speed.
Thank you for the clarifications.
Regards,
Eric
Eric Tishler
Software Architect
Resolute Partners, LLC
Phone: 203.271.1122
Fax: 203.271.1460
etishler@...
-----Original Message-----
From: Helen Borrie [mailto:helebor@...]
Sent: Friday, April 02, 2004 6:55 PM
To: IBObjects@yahoogroups.com
Subject: Re: [IBO] How to commit an update from code?
At 04:26 PM 2/04/2004 -0500, you wrote:
using Cache methods. Caching applies to datasets, not DML statements, and
it's rarely useful to use caching with IBO, anyway.
You don't need (and should avoid) a TIB_Query for DML. Use a TIB_Cursor or
a TIB_DSQL for any straight "execute" queries.
You EXECUTE DML statements, you OPEN datasets.
ib_transaction and ib_connection props appropriately.
It makes sense to apply a whole SQL statement in a single hit only if you
are gong to recycle this object for totally different statements. If you
plan to reuse it over and over for the same statement with simply different
SET and WHERE criteria, then do the SQL as an IDE property, as follows:
UPDATE "UserAccounts"
SET "Credits" = :iAmount
WHERE "AccountID" = :iUserID
The run-time stuff is like this (in the BeforeExecute event):
with MyDSQL do
begin
if not IB_Transaction.Started then
IB_Transaction.StartTransaction;
if not Prepared then Prepare;
ParamByName('"Credits").AsCurrency := iAmount;
ParamByName('"AccountID"').AsInteger := iUserID;
end;
On your button-click:
begin
MyDSQL.Execute;
MyDSQL.IB_Transaction.Commit;
end
You'll want to include a try..except block in your execute method, too, so
you can handle any exceptions.
With a DML statement, there is no dataset, so there is nothing to
"Refresh". You won't see what you want to see unless you have an object
capable of displaying the stuff. If you do, then that's the object you
have to refresh.
Helen
___________________________________________________________________________
IB Objects - direct, complete, custom connectivity to Firebird or InterBase
without the need for BDE, ODBC or any other layer.
___________________________________________________________________________
http://www.ibobjects.com - your IBO community resource for Tech Info papers,
keyword-searchable FAQ, community code contributions and more !
Yahoo! Groups Sponsor
ADVERTISEMENT
<http://rd.yahoo.com/SIG=12c8tca9s/M=290828.4766966.5935071.1261774/D=egroupweb/S=1705007183:HM/EXP=1081036499/A=1950448/R=0/SIG=124t85je5/*http://ashnin.com/clk/muryutaitakenattogyo?YH=4766966&yhad=1950448> click here
<http://us.adserver.yahoo.com/l?M=290828.4766966.5935071.1261774/D=egroupweb/S=:HM/A=1950448/rand=389393153>
_____
Yahoo! Groups Links
* To visit your group on the web, go to:
http://groups.yahoo.com/group/IBObjects/
* To unsubscribe from this group, send an email to:
IBObjects-unsubscribe@yahoogroups.com <mailto:IBObjects-unsubscribe@yahoogroups.com?subject=Unsubscribe>
* Your use of Yahoo! Groups is subject to the Yahoo! Terms of <http://docs.yahoo.com/info/terms/> Service.
[Non-text portions of this message have been removed]
Thank you for the clarifications.
Regards,
Eric
Eric Tishler
Software Architect
Resolute Partners, LLC
Phone: 203.271.1122
Fax: 203.271.1460
etishler@...
-----Original Message-----
From: Helen Borrie [mailto:helebor@...]
Sent: Friday, April 02, 2004 6:55 PM
To: IBObjects@yahoogroups.com
Subject: Re: [IBO] How to commit an update from code?
At 04:26 PM 2/04/2004 -0500, you wrote:
>I am running an update query in code. I construct the query manually andThe reason you are having problems getting DML to "take" is that you are
>then run it using ExecSQL. But the update never seems to take place
>
>This is my code (where qryTemp is a TIB_Query)
using Cache methods. Caching applies to datasets, not DML statements, and
it's rarely useful to use caching with IBO, anyway.
You don't need (and should avoid) a TIB_Query for DML. Use a TIB_Cursor or
a TIB_DSQL for any straight "execute" queries.
You EXECUTE DML statements, you OPEN datasets.
>With DataAccessMod.qryTemp doAll of that CommitAction (and also RefreshAction) stuff applies to datasets.
>Begin
> Active := False;
> SQL.Clear;
>
> // construct the query
> SQL.Add('UPDATE "UserAccounts" SET ');
> SQL.Add('"Credits" = ' + IntToStr(iAmount) + ' ');
> SQL.Add('WHERE "AccountID" = ' + IntToStr(iUserID));
>
> // run the query
> ExecSQL;
>
> // After doing this I have tried each of the following: (one at a time)
>
> ApplyUpdates;
>
> CommitAction := caRefresh;
>
> CommitAction := caClose;
>End;
>Can somebody help me?Here goes. Drop a TIB_DSQL onto your form or DM and hook up its
>
>Thank you,
ib_transaction and ib_connection props appropriately.
It makes sense to apply a whole SQL statement in a single hit only if you
are gong to recycle this object for totally different statements. If you
plan to reuse it over and over for the same statement with simply different
SET and WHERE criteria, then do the SQL as an IDE property, as follows:
UPDATE "UserAccounts"
SET "Credits" = :iAmount
WHERE "AccountID" = :iUserID
The run-time stuff is like this (in the BeforeExecute event):
with MyDSQL do
begin
if not IB_Transaction.Started then
IB_Transaction.StartTransaction;
if not Prepared then Prepare;
ParamByName('"Credits").AsCurrency := iAmount;
ParamByName('"AccountID"').AsInteger := iUserID;
end;
On your button-click:
begin
MyDSQL.Execute;
MyDSQL.IB_Transaction.Commit;
end
You'll want to include a try..except block in your execute method, too, so
you can handle any exceptions.
With a DML statement, there is no dataset, so there is nothing to
"Refresh". You won't see what you want to see unless you have an object
capable of displaying the stuff. If you do, then that's the object you
have to refresh.
Helen
___________________________________________________________________________
IB Objects - direct, complete, custom connectivity to Firebird or InterBase
without the need for BDE, ODBC or any other layer.
___________________________________________________________________________
http://www.ibobjects.com - your IBO community resource for Tech Info papers,
keyword-searchable FAQ, community code contributions and more !
Yahoo! Groups Sponsor
ADVERTISEMENT
<http://rd.yahoo.com/SIG=12c8tca9s/M=290828.4766966.5935071.1261774/D=egroupweb/S=1705007183:HM/EXP=1081036499/A=1950448/R=0/SIG=124t85je5/*http://ashnin.com/clk/muryutaitakenattogyo?YH=4766966&yhad=1950448> click here
<http://us.adserver.yahoo.com/l?M=290828.4766966.5935071.1261774/D=egroupweb/S=:HM/A=1950448/rand=389393153>
_____
Yahoo! Groups Links
* To visit your group on the web, go to:
http://groups.yahoo.com/group/IBObjects/
* To unsubscribe from this group, send an email to:
IBObjects-unsubscribe@yahoogroups.com <mailto:IBObjects-unsubscribe@yahoogroups.com?subject=Unsubscribe>
* Your use of Yahoo! Groups is subject to the Yahoo! Terms of <http://docs.yahoo.com/info/terms/> Service.
[Non-text portions of this message have been removed]