#1 2017-02-16 16:22:28

AntonE
Member
Registered: 2012-02-03
Posts: 74

ZEOS 7.2.1, TSQBDBConnectionProperties & multi-thread

Hi,
I'm busy migrating a legacy app and need to access some Firebird data in multiple threads.
First time Synopse library use for direct Firebird access.

(Very) Stripped down code is:

function GetUsageTotal(DB:TSQLDBConnectionProperties;DataParams:TDataParams):Int64;  (*Global function in a unit*)
var RES : ISQLDBROWS;
begin
  RES:=DB.Execute(SQL.Text,[]);
  if RES.Step
     then Result:=RES['Tot']
     else Result:=0;
end;

Type TCheckThread = class(TThread);

procedure TCheckThread.Execute;
begin
 DBCP:= TSQLDBZEOSConnectionProperties.Create(TSQLDBZEOSConnectionProperties.URI(dFirebird,IP),DB,UN,PW);
 while not Terminated do
  begin
    (* some other stuff, fetch task, back-off yield/sleep, etc *)
    Tot:=GetUsageTotal(DBCP,DataParams);
    (* some other stuff *)
  end;
 DBCP.Free;
end;

Is this in principle correct?
I initially had all threads share one TSQLDBZEOSConnectionProperties but got this error, so I made a copy for each thread and still get the issue.
If I run it in 1 thread there is no problem, but if I run multiple threads then I periodically get 'corrupt' results.
Error in ZDbcInterbase6Utils line 829, e.g. errors converting from DateTime '022/12/2016' or '02/16/201717'. (no typos)
I have other less-intensive simultaneous threads running with also TSQLDBConnectionProperties but they access different tables, this is the only place where I simultaneously need to access the same database table (many GBs big).

I have {$DEFINE ZEOS72UP} in zeos.inc but not sure if other changes need to be made there.

Using latest Zeos 7.2.1 & mORMot downloaded about two weeks ago. Firebird 3.0.1

If there is nothing obviously wrong here then I'll write a test case to try replicate it outside my code.

Thank you
AntonE

Offline

Board footer

Powered by FluxBB