Performance with multiple inserts

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
miguelenguica
Posts: 18
Joined: Mon 11 Apr 2011 15:28

Performance with multiple inserts

Post by miguelenguica » Wed 09 May 2012 18:58

Hi. I'm porting some code into Delphi. I'm using UniDAC components to interface SQLite. At some point I have to perform an insert query for each item in a TStringList. The list can grow to several hundred thousand entries. The performance is poor if I need to perform ExecSQL for each line. Can anyone tell me how to do some kind of bulk insert or transaction for this. This is my code now:

Code: Select all

var
  myQuery : TUniQuery;
  (...)
begin
  myQuery:= TUniQuery.Create(nil);
  myQuery.Connection:= my_db;
  //
  for i := 0 to origin_2SL.Count-1 do
  begin
        myQuery.SQL.Text:= 'insert into mytable(a,b,c,d) values(:a,:b,:c,:d)');
        (...)//fill the params
        //execute query
        myQuery.ExecSQL
  end;
  //
  myQuery.Free;
end;
Can anyone tell me how to improve the performance?

Thanks!

bork
Devart Team
Posts: 649
Joined: Fri 12 Mar 2010 07:55

Re: Performance with multiple inserts

Post by bork » Fri 11 May 2012 13:34

Hello

You can use the TUniLoader component for loading a big amount of data to the database. TUniLoader provides the functionality for loading with maximum speed. You can find more detailed information about using TUniLoader in the "TUniLoader class" article of the UniDAC documentation. In addition, you can take a look at UniDAC demo project that demonstrates how TUniLoader works. The UniDAC demo project are located in the %UniDAC_Install_Directory%\Demos\UniDacDemo directory.

Also, we had a similar request about slow DB update (here: http://forums.devart.com/viewtopic.php?f=28&t=17621). You can try the solution that was suggested there.

Post Reply