querythread.pas
来自「著名的SecureBlackBox控件完整源码」· PAS 代码 · 共 60 行
PAS
60 行
unit QueryThread;
interface
uses
Classes, SqlExpr, SysUtils;
type
TQueryThread = class(TThread)
private
FSQLConnection : TSQLConnection;
FSQLDataSet : TSQLDataSet;
FRowCount : integer;
public
constructor Create(const DBName, Username, Password, Query: string);
destructor Destroy; override;
procedure Execute; override;
property DataSet : TSQLDataSet read FSQLDataSet;
property RowCount : integer read FRowCount;
end;
implementation
constructor TQueryThread.Create(const DBName, Username, Password, Query: string);
begin
inherited Create(true);
FSQLConnection := TSQLConnection.Create(nil);
FSQLDataSet := TSQLDataSet.Create(nil);
FSQLConnection.DriverName := 'MySQL';
FSQLConnection.LibraryName := 'dbexpmysql.dll';
FSQLConnection.VendorLib := 'LIBMYSQL.dll';
FSQLDataSet.SQLConnection := FSQLConnection;
FSQLConnection.Params.Values['User_Name'] := Username;
FSQLConnection.Params.Values['Password'] := Password;
FSQLConnection.Params.Values['Database'] := DBName;
FSQLConnection.Params.Values['HostName'] := '127.0.0.1';
FSQLConnection.Params.Values['DriverName'] := 'MySQL';
FSQLConnection.Params.Values['BlobSize'] := '-1';
FSQLConnection.Params.Values['LocaleCode'] := '0001';
FSQLConnection.LoginPrompt := false;
FSQLConnection.GetDriverFunc := 'getSQLDriverMYSQL';
FSQLDataSet.CommandText := Query;
FRowCount := 0;
end;
destructor TQueryThread.Destroy;
begin
FreeAndNil(FSQLConnection);
FreeAndNil(FSQLDataSet);
inherited;
end;
procedure TQueryThread.Execute;
begin
FSQLDataSet.Active := true;
FRowCount := FSQLDataSet.RecordCount;
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?