Threaded Insert Records
Posted: Thu 29 May 2008 17:55
I have a threaded application that i wrote a while back in Delphi and ADO. I purchased a copy of mydac std - latest. I would like to port this application to Delphi/mysql (am running sql 5).
The application processes many records and creates a thread for each record to insert details in table i.e its same as running a loop 1000 times and each time you create a thread to insert records. Below find the code that actually does the insert into my database.
In ADO, i have to use coinitialize.... and then connect to the db, make my insert and thats it.
How do i achieve this same thing when my application using mysql - do i use same connection for each thread? Please give me a code snippet that i can use quickly.
Also, anyone with a better way to do what i am trying to do below
My Code:
procedure Tinsert.Execute;
begin
{ Place thread code here }
Coinitialize(nil);
try
with TADOCOmmand.Create(nil) do
begin
//frmmain.cxMemo1.Lines.Add('Adding sms');
ConnectionString:=SQLSERVER CONNECTION STRING HERE; /
CommandText:='addnewrecord '+
QuotedStr(f_Destination)+','+
inttostr(f_DestTON)+','+
inttostr(f_DestNPI)+','+
QuotedStr(f_Originator)+','+
inttostr(f_OrigTON)+','+
inttostr(f_OrigNPI)+','+
QuotedStr(f_SMText)+','+
QuotedStr(GetEnumName(TypeInfo(TtcEncodingType), integer(f_Encoding)))+','+
QuotedStr(f_UserDataHeader)+','+
QuotedStr(f_OptionalParameters);
Execute;
Free;
end;
except
on E:Exception do
begin
frmmain.cxMemo1.Lines.Add('Database Error: ' + E.Message);
end;
end;
CoUninitialize;
end;
The application processes many records and creates a thread for each record to insert details in table i.e its same as running a loop 1000 times and each time you create a thread to insert records. Below find the code that actually does the insert into my database.
In ADO, i have to use coinitialize.... and then connect to the db, make my insert and thats it.
How do i achieve this same thing when my application using mysql - do i use same connection for each thread? Please give me a code snippet that i can use quickly.
Also, anyone with a better way to do what i am trying to do below
My Code:
procedure Tinsert.Execute;
begin
{ Place thread code here }
Coinitialize(nil);
try
with TADOCOmmand.Create(nil) do
begin
//frmmain.cxMemo1.Lines.Add('Adding sms');
ConnectionString:=SQLSERVER CONNECTION STRING HERE; /
CommandText:='addnewrecord '+
QuotedStr(f_Destination)+','+
inttostr(f_DestTON)+','+
inttostr(f_DestNPI)+','+
QuotedStr(f_Originator)+','+
inttostr(f_OrigTON)+','+
inttostr(f_OrigNPI)+','+
QuotedStr(f_SMText)+','+
QuotedStr(GetEnumName(TypeInfo(TtcEncodingType), integer(f_Encoding)))+','+
QuotedStr(f_UserDataHeader)+','+
QuotedStr(f_OptionalParameters);
Execute;
Free;
end;
except
on E:Exception do
begin
frmmain.cxMemo1.Lines.Add('Database Error: ' + E.Message);
end;
end;
CoUninitialize;
end;