Hello, I happily migrated a big project in D2007 from FIB to Unidac last year and most of the database related problems have disappeared. Now having done a even bigger (since Unicode) migration to Delphi XE6 this year I discovered Firedac with the great feature easily to run longer lasting queries in the background without having to fiddle around with threads. My questions:
- Are similar features planned for Unidac (I would like to stay with it)?
- Can I mimic that background execution with threads (since it is only relvant for the longer lasting queries), Unidac and Firebird (currently still 1.56, going towards 2.5x)?
- Is there a kind of "easy template" for those who are not so much used to using threads, perhaps by a thread-pro?
Thanks in advance,
Michael
Background execution, Threads, Firebird
Re: Background execution, Threads, Firebird
Unfortunately, at the moment UniDAC doesn't support this functionality. If you want us to implement this functionality, please post it at our user voice forum: http://devart.uservoice.com/forums/1046 ... 939-unidac
If the suggestion gets a lot of votes, we will consider the possibility to implement it.
If the suggestion gets a lot of votes, we will consider the possibility to implement it.
Re: Background execution, Threads, Firebird
[quote="michaschumann"]..
- Can I mimic that background execution with threads (since it is only relvant for the longer lasting queries)
I tested this using a simple thread spawn, no feedback just spawn and let it run. If you need feedback you should look into TThread and periodically synch to see what's going on in your thread.
procedure TForm1.Button1Click(Sender: TObject);
procedure ThreadFunc( p : pointer);
var
id : integer absolute p;
begin
with TUniConnection.Create(nil) do
try
ProviderName := 'InterBase';
Database := '/var/lib/firebird/2.5/data/Data.fdb';
Username := 'SYSDBA';
Server := '192.168.1.6';
LoginPrompt := False;
Password := EncodeDecode('“l;k;¹¬Ûü‰ÖÅ');
Connected := True;
ExecSQL(Format('Delete from client where ID = %d',[ID])) ;
Beep;
finally
Free;
end
end;
begin
SpawnThread(@ThreadFunc, Pointer(-1), false);
end;
requires this:
(* SpawnThread: Spawn and forget *)
type
PSpawnThreadRec = ^TSpawnThreadRec;
TSpawnThreadRec = record
Handle: Thandle;
ThreadID: DWORD;
Data: Pointer;
ThreadFunc: TThreadFunc;
end;
function SpawnThreadProc(SpawnThreadRec: PSpawnThreadRec): integer;
begin
Result := 0;
try
Result := SpawnThreadRec.ThreadFunc(SpawnThreadRec.Data);
finally
EndThread(Result);
Dispose(SpawnThreadRec);
end;
end;
function SpawnThread(ThreadFunc: TThreadFunc; Data: Pointer; WaitFor: Boolean = False): boolean;
var
SpawnThreadRec : PSpawnThreadRec;
begin
New(SpawnThreadRec);
SpawnThreadRec.ThreadFunc := ThreadFunc;
SpawnThreadRec.Data := Data;
SpawnThreadRec.Handle := BeginThread(nil, 0, @SpawnThreadProc, Pointer(SpawnThreadRec), 0, SpawnThreadRec.ThreadID);
Result := SpawnThreadRec.Handle <> 0;
if Result and WaitFor then
WaitForSingleObject(SpawnThreadRec.Handle, INFINITE);
end;
- Can I mimic that background execution with threads (since it is only relvant for the longer lasting queries)
I tested this using a simple thread spawn, no feedback just spawn and let it run. If you need feedback you should look into TThread and periodically synch to see what's going on in your thread.
procedure TForm1.Button1Click(Sender: TObject);
procedure ThreadFunc( p : pointer);
var
id : integer absolute p;
begin
with TUniConnection.Create(nil) do
try
ProviderName := 'InterBase';
Database := '/var/lib/firebird/2.5/data/Data.fdb';
Username := 'SYSDBA';
Server := '192.168.1.6';
LoginPrompt := False;
Password := EncodeDecode('“l;k;¹¬Ûü‰ÖÅ');
Connected := True;
ExecSQL(Format('Delete from client where ID = %d',[ID])) ;
Beep;
finally
Free;
end
end;
begin
SpawnThread(@ThreadFunc, Pointer(-1), false);
end;
requires this:
(* SpawnThread: Spawn and forget *)
type
PSpawnThreadRec = ^TSpawnThreadRec;
TSpawnThreadRec = record
Handle: Thandle;
ThreadID: DWORD;
Data: Pointer;
ThreadFunc: TThreadFunc;
end;
function SpawnThreadProc(SpawnThreadRec: PSpawnThreadRec): integer;
begin
Result := 0;
try
Result := SpawnThreadRec.ThreadFunc(SpawnThreadRec.Data);
finally
EndThread(Result);
Dispose(SpawnThreadRec);
end;
end;
function SpawnThread(ThreadFunc: TThreadFunc; Data: Pointer; WaitFor: Boolean = False): boolean;
var
SpawnThreadRec : PSpawnThreadRec;
begin
New(SpawnThreadRec);
SpawnThreadRec.ThreadFunc := ThreadFunc;
SpawnThreadRec.Data := Data;
SpawnThreadRec.Handle := BeginThread(nil, 0, @SpawnThreadProc, Pointer(SpawnThreadRec), 0, SpawnThreadRec.ThreadID);
Result := SpawnThreadRec.Handle <> 0;
if Result and WaitFor then
WaitForSingleObject(SpawnThreadRec.Handle, INFINITE);
end;