Subject Re: Insert Statement Taking Time With TimeStamp values
Author Svein Erling
--- In firebird-support@yahoogroups.com, Vishal Tiwari wrote:
> Hi Milan,
>
> Thanks for your reply.
>
> I am making the Insert sql and putting semicolon at the end of each
> Insert sql. And putting them into TStringList component.
>
> Then i am assigning this TStringList data to TIB_Script component
> as follows:
>
>
> var
> Script_Comp : TIB_Script;
> Str_List : TStringList;
> begin
> //after putting all Insert sql into "Str_List" TStringList
> //component, i am executing them as follows:
>
> Script_Comp.SQL := Str_List;
> Script_Comp.Execute;
> end;
>
> Am i missing something here?
>
> Thanks in advance
>
> Vishal

OK, so you're using IBO. Then try something like:

var
i1,
s1,
ts1,
ts2: TIB_Column;
begin
with TIB_DSQL.Create do
try
IB_Connection:=IB_Connection1;
IB_Transaction:=IB_Transaction1;
SQL.Add('Insert into MyTable(PK, MyString, MyTimestampFrom,
MyTimestampTo)
values (:PK, :MS, :MTSF, :MTST)');
Prepare;
i1:=ParamByName('PK');
s1:=ParamByName('MS');
ts1:=ParamByName('MTSF');
ts2:=ParamByName('MTST');
while not <whatever> do
begin
i1.AsInteger:=...;
s1.AsString:=...;
ts1.AsDateTime:=...;
ts2.AsDateTime:=...;
ExecSQL;
end;
finally
IB_Transaction1.Commit;
Free;
end;
end;

This should be considerably quicker than your script. Alternatively (about equally quick), you can use Params[<position>] as an alternative to the TIB_Columns (ParamByName within the loop is slower). The thing you're missing is (as others have mentioned) that when you put things within a script, then each statement has to be prepared and that is somewhat time consuming when done 2000 times. With one TIB_DSQL component and one statement executed repeatedly with different values, things should be quicker.

HTH,
Set