Recent

Author Topic: Zeos + Mysql + Multi-thread INSERT  (Read 8085 times)

warcode

  • New Member
  • *
  • Posts: 36
Zeos + Mysql + Multi-thread INSERT
« on: January 31, 2011, 10:44:11 pm »
Hi all

i have a big probleme here i made a application that make insert query to a mysql 5 database using Zeos 7.0.0-dev.

The trouble is that i need to make something like this

for x:= 0 to 20000 do
begin
  query := 'INSERT INTO db_test (file) VALUE ( QuotedStr( 'c:\test.pas' ) )';
  zCon.ExecuteDirect( query );
end;

Yea 20000 insert query is pretty long !!! So i 'TRY' to convert this using Thread

i read  this

Multithreaded Application Tutorial
Example of multi-threaded application: array of threads

But im a bit lose, does i need to create a array [0..20000 ] of TThread  ?
Need help plz

Christian F

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1891
Re: Zeos + Mysql + Multi-thread INSERT
« Reply #1 on: January 31, 2011, 11:17:09 pm »
I wouldn't do that. It's probably not going to be a lot faster, but certainly a lot more complicated and prone to error.

If you just need to make your UI more responsive, call Application.Processmessages in the loop periodically.

marsianinek

  • Newbie
  • Posts: 1
Re: Zeos + Mysql + Multi-thread INSERT
« Reply #2 on: May 12, 2011, 03:36:58 pm »
No, wrong way. Problem isn't in ProcessMessages(), problem is in running thousands inserts into database. To make this faster use transaction:

zCon.StartTransaction();
query := 'INSERT INTO db_test (file) VALUE ( QuotedStr( 'c:\test.pas' ) )';
for x:= 0 to 20000 do
begin
  zCon.ExecuteDirect( query );
end;
zCon.Commit();

Look, I moved query line before for loop, because there is the same value saved in loop 20000 times, what for? There is one enough.

 

TinyPortal © 2005-2018