Can someone help me with my problem, some solution of advice?
My real application is Rest Service with connection to Oracle DB. Service must support many client connections, so it’s must handle all requests in separated threads.
My working thread got own TOraSession. When it’s get client request – it’s takes some pl/sql block (it’s can be anything, configurated by DB admin).
This thread must to:
1. Init and start execution of some pl/sql block
2. Wait until pl/sql block will be done or some amount of time (timeout)
- If was timeout – break execution and send special error to client.
- If was exception – send text of exception to client.
- If was executed fine – get value of out params and send it to client.
1. TOraScript, got OnError, but can’t run in NoBlockingMode
2. TOraQuery, got OnPostError, OnUpdateError (which does not call when you use pl\sql). When I try to handle exception with TOraSession.OnError – it’s run in MainThread of application, so starts classic "race condition". TOraQuery.Executing is false, but real Exception can be not processed yet.
3. TOraSQL – got very useful TOraSQL.WaitExecuting, but handling exceptions is same as for TOraQuery.
My source was like this:
Code: Select all
try
qr.NonBlocking := true;
qr.Session.OnError := OnSessionError;
FPostError := nil;
try
xStartExecTime := Now();
qr.ExecSQL();
while qr.Executing do
begin
FLastUsed := now;
Sleep(2);
if SecondsBetween(Now(), xStartExecTime) > C_WAIT_SECONDS then
begin
qr.BreakExec;
while qr.Executing do
begin
Sleep(2);
end { while };
raise Exception.Create('qr.ExecSQL too long! > ' +
C_WAIT_SECONDS.ToString);
end { if };
end { while };
if Assigned(FPostError) then
raise Exception.Create(FPostError.Message);
finally
qr.Session.OnError := nil;
end { try..finally };
except
on E: Exception do
begin
raise Exception.Create(E.Message)
end { on };
end { try };
https://drive.google.com/open?id=1psR0X ... CU3vGBBqIK