Problems with multi-thread application
Posted: 05.11.2014, 07:37
Hello guys >.< !
Well, after trying everything with no success, I resolved to request some help here.
I don't know why, but no matter what library I use for the thread pool, no matter how I execute the querys in database, Im still getting the same errors. Seems the querys of one thread blends with others. Check this error log:
I'm using the OmniThreadLibrary for the thread pool, and the connection pool unit coded by <I Don't remeber who created, lol>. Im creating 10 threads in each pool (the thread pool and the connection pool (so, each thread have his own TZConnection)). In the first app, the connection pool was returning TZConnection object, so I changed the pool to return TMyDataBase object. Nothing has changed, Im still get the same errors.
Here is the sample function:
Im using Delphi XE6 with Zeos 7.2 beta. I will build a simple test case and post here, I really need to solve this problem .
Sorry for the English ^^.
Well, after trying everything with no success, I resolved to request some help here.
I don't know why, but no matter what library I use for the thread pool, no matter how I execute the querys in database, Im still getting the same errors. Seems the querys of one thread blends with others. Check this error log:
Code: Select all
-----------------------
function: procCountById() <--the function. Ok!
Arg value: 55 <--parameter received. Ok!
MyQuery: SELECT COUNT(*) FROM clients WHERE ID = 55 <--MyQuery = string variable, in the next line of code I will execute this query!. Ok!
Error Message: SQL Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'dbname.clients LIKE '%'' at line 1 <--Fail. The executed query isn't the same query of MyQuery variable.
------------------------
-----------------------------------------------
Function: UpdateClientProcCount() <--the function. Ok!
Arg Value: 185 <--parameter received. Ok!
MyQuery: UPDATE clients SET NumProcs = 2 WHERE ID = 185 <--MyQuery = string variable, in the next line of code I will execute this query!. Ok!
Error Message: SQL Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'D = 185' at line 1 <--Same error. The query just broke here, I don't know why
-----------------------------------------------
Here is the sample function:
Code: Select all
procedure TMyDataBase.SetProcessFlag(ProcessID: Integer; Flag: Integer = PROC_OK);
var
Query: TZQuery;
eMsg: string;
begin
try
//Probably, you are thinking: Why you're creating one TZQuery for each procedure ? Well, Doesn't matter if I create one TZQuery in private section of my object, or create one in each procedure/function, this erros still happens.
Query:=TZQuery.Create(nil);
Query.Connection:=ZCon;
//Using Format or ParamByName, the error still occur. ---
MyQuery:=Format('UPDATE process SET Stats = 1, Flag = %d WHERE ID = %d', [Flag, ProcessID]);
Query.SQL.Add(MyQuery);
//Im getting this errors using transaction with ExecuteDirect too, I have no ideia how to solve this...
Query.ExecSQL;
Query.Free;
except
On E:Exception do
begin
eMsg:=' '+sLineBreak;
eMsg:=eMsg + '-----------------------------------------------'+sLineBreak;
eMsg:=eMsg + 'Function: SetProcessFlag()'+sLineBreak;
eMsg:=eMsg + 'Arg Value: '+IntToStr(ProcessID)+' -- '+IntToStr(Flag)+sLineBreak;
eMsg:=eMsg + 'MyQuery: '+MyQuery+sLineBreak;
eMsg:=eMsg + 'Error Message: '+E.Message+sLineBreak;
eMsg:=eMsg + '-----------------------------------------------';
debugWrite(eMsg);
end;
end;
end;
Sorry for the English ^^.