зеос.
на формочке\тдатамодуле с именем dmdata лежит
delphi Код:
object SqlConnection: TZConnection
Protocol = 'mysql-4.1'
HostName = '192.168.0.1'
Port = 3306
Database = 'qqqq'
User = 'wwww'
Password = 'eeeee'
Catalog = 'mysql'
AutoCommit = False
end
есть класс прослойка.позволяющий юзать квери с любой нити без последствий.
delphi Код:
TZQueryWrapper = class
private
Z : TZQuery;
function getsql: tstrings;
procedure setsql(const Value: tstrings);
protected
Procedure SynchCreate;
Procedure SynchDestroy;
procedure SynchOpen;
procedure SynchClose;
procedure SynchExecSql;
procedure SynchNext;
public
procedure Open;
procedure Close;
procedure ExecSql;
procedure next;
Function RowsAffected : integer;
Function Eof : boolean;
function GetBlobFieldData(FieldNo: Integer; var Buffer: TBlobByteData): Integer;
Function FieldByName(const name : string):Tfield;
property sql : tstrings read getsql write setsql;
Constructor Create;
Destructor destroy; override;
end;
{ TZQueryWrapper }
procedure TZQueryWrapper.Close;
begin
if GetCurrentThreadId <> MainThreadID then
TThread.Synchronize(nil, SynchClose)
else
SynchClose;
end;
constructor TZQueryWrapper.Create;
begin
z := nil;
if GetCurrentThreadId <> MainThreadID then
TThread.Synchronize(nil, SynchCreate)
else
SynchCreate;
end;
destructor TZQueryWrapper.destroy;
begin
if GetCurrentThreadId <> MainThreadID then
TThread.Synchronize(nil, SynchDestroy)
else
SynchDestroy;
inherited;
end;
function TZQueryWrapper.Eof: boolean;
begin
result := z.Eof;
end;
procedure TZQueryWrapper.ExecSql;
begin
if GetCurrentThreadId <> MainThreadID then
TThread.Synchronize(nil, SynchExecSql)
else
SynchExecSql;
end;
function TZQueryWrapper.FieldByName(const name: string): Tfield;
begin
Result := z.FieldByName(name);
end;
function TZQueryWrapper.GetBlobFieldData(FieldNo: Integer;
var Buffer: TBlobByteData): Integer;
begin
result := z.GetBlobFieldData(FieldNo,Buffer);
end;
function TZQueryWrapper.getsql: tstrings;
begin
result := Z.SQL;
end;
procedure TZQueryWrapper.next;
begin
if GetCurrentThreadId <> MainThreadID then
TThread.Synchronize(nil, SynchNext)
else
SynchNext;
end;
procedure TZQueryWrapper.Open;
begin
if GetCurrentThreadId <> MainThreadID then
TThread.Synchronize(nil, SynchOpen)
else
SynchOpen;
end;
function TZQueryWrapper.RowsAffected: integer;
begin
Result := z.RowsAffected;
end;
procedure TZQueryWrapper.setsql(const Value: tstrings);
begin
Z.SQL := Value;
end;
procedure TZQueryWrapper.SynchClose;
begin
z.Close;
end;
procedure TZQueryWrapper.SynchCreate;
begin
if not dmDB.SqlConnection.Connected then
dmDB.SqlConnection.Connect;
Z := TZQuery.Create(nil);
z.Connection := dmDB.SqlConnection;
end;
procedure TZQueryWrapper.SynchDestroy;
begin
z.free;
end;
procedure TZQueryWrapper.SynchExecSql;
begin
z.ExecSQL;
end;
procedure TZQueryWrapper.SynchNext;
begin
z.Next;
end;
procedure TZQueryWrapper.SynchOpen;
begin
z.Open;
end;
есть глобально обьявленная функция.
delphi Код:
Function NewUpdateQuery(sQuesry : string):TZQueryWrapper;
begin
result := TZQueryWrapper.Create;
result.sql.Text := sQuesry;
end;
ну. и в итоге, юзаем как то так.
delphi Код:
with NewUpdateQuery(format('select id from build_parsers where buildnum = %d',[NewBuild])) do
begin
open;
while not eof do
begin
DeleteFile(pchar(format('%s\%d.bin',[OutputDir,FieldByName('id').AsInteger])));
next;
end;
Close;
Destroy;
end;