type
TSQLThread = class(TThread)
private
protected
procedure Execute; override;
public
ConnStr : WideString;
SQLString : WideString;
IsNotice : Boolean;
IsSelect : Boolean;
sIRCDest : String;
Output : TIdIRC;
Priority: TThreadPriority;
end;
function RunThread(ConnectionString: WideString; SQLString: WideString; Output: TIdIRC; isNotice: Boolean; isSelect: Boolean; sIRCDest: String; Priority: TThreadPriority): TSQLThread;
implementation
uses Main;
function RunThread(ConnectionString: WideString; SQLString: WideString; Output: TIdIRC; isNotice: Boolean; isSelect: Boolean; sIRCDest: String; Priority: TThreadPriority): TSQLThread;
var
SQLThread : TSQLThread;
begin
SQLThread := TSQLThread.Create(True) ;
SQLThread.FreeOnTerminate := True;
SQLThread.ConnStr := ConnectionString;
SQLThread.SQLString := SQLString;
SQLThread.Output := Output;
SQLThread.IsSelect := IsSelect;
SQLThread.isNotice := isNotice;
SQLThread.sIRCDest := sIRCDest;
SQLThread.Priority := Priority;
SQLThread.Resume;
Result := SQLThread;
end;
procedure TSQLThread.Execute;
var
Qry : TADOQuery;
k : integer;
Temp : String;
begin
inherited;
CoInitialize(nil);
Qry := TADOQuery.Create(nil);
try
Qry.ConnectionString := ConnStr;
Qry.CursorLocation := clUseServer;
Qry.LockType := ltReadOnly;
Qry.CursorType := ctOpenForwardOnly;
Qry.SQL.Text := SQLString;
Qry.Open;
If IsSelect Then
begin
If IsNotice Then
begin
Output.Notice(sIRCDest,'Query Executed.');
end
Else
begin
Output.Say(sIRCDest,'Query Executed.');
end;
end
Else
begin
while NOT Qry.Eof and NOT Terminated do
begin
Temp := '';
For K := 0 To Qry.FieldCount - 1 Do
begin
Temp := Temp + '[' + Qry.Fields[K].FieldName + ': ' + Qry.Fields[K].AsString + '] ';
end;
If IsNotice Then
begin
Output.Notice(sIRCDest,Temp);
end
Else
begin
Output.Say(sIRCDest,Temp);
end;
Qry.Next;
end;
end;
Qry.Free;
except
If IsNotice Then
begin
Output.Notice(sIRCDest,'Query Failed.');
end
Else
begin
Output.Say(sIRCDest,'Query Failed.');
end;
Qry.Free;
end;
CoUninitialize() ;
end;