简体   繁体   中英

Unidac / MyDac / SQL - I have problem with fast insert about 1000 rows

I use unidac components. And i have problem with fast insert about 1000 rows.

var
  query: TUniquery;
begin
  query.SQL.Add('INSERT INTO Table (field1,field2,field3) VALUES (:b0,:b1,:b2);');
  for I := 0 to 1000 do
  begin
   Query.ParamByName('b0').AsInteger := 1;  
   Query.ParamByName('b1').AsInteger := 2;
   Query.ParamByName('b2').AsInteger := Random(100);
   Query.Prepare;
   Query.Execute;  //1000 times is very slow
end;

It is faster

var
  query: TUniquery;
begin
  for I := 0 to 1000 do
    Query.SQL.Add('INSERT INTO Table (field1,field2,field3) VALUES (1,2,Random(100));');
  end;
  Query.Execute;  //1 times - is fast add 
end;

But, I would like to use the first format with the procedure Query.ParamByName('b1').AsInteger:= 2; because it is clearer and with a large number of columns I find myself easier to find.

Do you have any ideas on how to solve this?

Maybe you have some other ways to quickly insert a large number of rows with different data?

If you need to quickly insert a large number of records, you should use batch updates. You can read more about batch inserting into MySQL using UniDAC (or MyDAC) in their blog

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM