Subject | Re: [IBO] Update and IB_DSQL what am I doing wrong? |
---|---|
Author | Helen Borrie |
Post date | 2007-11-27T01:33:57Z |
At 10:36 AM 27/11/2007, you wrote:
Don't scrap the prepared SQL for each execution. Do this at the beginning:
with ModData.dsql_AnyUse do
begin
SQL.Clear; // this invalidates the entire statement so do it only once
SQl.Add('UPDATE Filters SET Filter_in_ToolBar = 1 ');
SQL.Add('WHERE Filter_ID = :filterid');
Prepare;
end;
Then, in BeforeExecute do this:
with ModData.dsql_AnyUse do
begin
if not Prepared then Prepare; // probably not needed but doesn't hurt
ParamByName('filterid').AsInteger := NodeData.ID;
end;
Then, just call Execute when you're ready, presumably during some kind of loop where you are walking through your NodeData set. Call Commit if you want to commit each execution one-by-one; or you can wait until the NodeData loop finishes.
Helen
>Hello:Can't tell from the info provided. However...
>
>Why doesn't the following work? By that I mean when I access the event
>that has this code several times in succession, only the last UPDATE is
>in the table. What happened to the other UPDATEs?
>
>I have been using a variation of below for about 4 years now without
>this recent problem. Sometimes I need UPDATERECORD to make the UPDATE
>stick and sometimes IB_TRANSACTION.COMMIT. I never know which and it
>turns out that one or the other will work, but not either in the cases
>where this comes up.
>
>Perhaps I'm just missing something?
Don't scrap the prepared SQL for each execution. Do this at the beginning:
with ModData.dsql_AnyUse do
begin
SQL.Clear; // this invalidates the entire statement so do it only once
SQl.Add('UPDATE Filters SET Filter_in_ToolBar = 1 ');
SQL.Add('WHERE Filter_ID = :filterid');
Prepare;
end;
Then, in BeforeExecute do this:
with ModData.dsql_AnyUse do
begin
if not Prepared then Prepare; // probably not needed but doesn't hurt
ParamByName('filterid').AsInteger := NodeData.ID;
end;
Then, just call Execute when you're ready, presumably during some kind of loop where you are walking through your NodeData set. Call Commit if you want to commit each execution one-by-one; or you can wait until the NodeData loop finishes.
Helen