execsqlclass.pas
来自「程序採用了无状态连接池的三层结构」· PAS 代码 · 共 82 行
PAS
82 行
unit Execsqlclass;
interface
uses
sysutils,ADODB;
type
TexecsqlEvent=procedure(sender:Tobject;Qty:Tadoquery) of object;
type
Texecsql=class
private
Fadoconnection:Tadoconnection;
Fadoquery:Tadoquery;
Fcons:String;
Fsql:String;
FexecsqlException:Exception;
FexecsqlEvent:TexecsqlEvent;
protected
procedure ExecsqlError;
public
procedure Execute;
constructor Create(Fadoc:Tadoconnection;
fadoq:Tadoquery;
fconstring:string;
tmpsql:string);virtual;
destructor destroy();override;
property ExecsqlEvent:TexecsqlEvent read FexecsqlEvent write FexecsqlEvent;
end;
implementation
{ Texecsql }
constructor Texecsql.Create(Fadoc: Tadoconnection; fadoq: Tadoquery;
fconstring, tmpsql: string);
begin
Fadoconnection:=Fadoc;
Fadoquery:=Fadoq;
Fcons:=Fconstring;
Fsql:=tmpsql;
end;
destructor Texecsql.destroy;
begin
{do nothing};
inherited;
end;
procedure Texecsql.ExecsqlError;
begin
Abort;
end;
procedure Texecsql.Execute;
begin
try
fadoquery.Close;
fadoquery.SQL.Clear;
fadoquery.SQL.Add(' Begin transaction ');
fadoquery.SQL.Add(fsql);
fadoquery.SQL.Add(' commit transaction ');
fadoquery.ExecSQL;
if assigned(FexecsqlEvent) then
begin
FexecSqlEvent(self,Fadoquery);
end;
except
Fadoquery.Close;
Fadoquery.SQL.Clear;
Fadoquery.SQL.Add(' Rollback transaction ');
Fadoquery.ExecSQL;
FexecsqlException:=Exceptobject as Exception;
Execsqlerror;
end;
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?