uconndatabase.pas
来自「用DELPH写的DAO访问模块.有连接池.应用了各种模块,把数据库操作」· PAS 代码 · 共 112 行
PAS
112 行
{*******************************************************}
{ }
{ 数据库连接对象基类 }
{ }
{ 版权所有 (C) 2009 大道网络 }
{ }
{*******************************************************}
unit uConnDatabase;
interface
uses
Classes, SysUtils, Windows, ADODB, DB, uDatabasePublic;
type
//==============================================================================
// 抽象数据库基本接口
//==============================================================================
IConnDatabase = interface(IUnknown)
['{D9E176DD-F38C-4AE8-8E00-7E8686C1CCB0}']
function getDBConnection: TCustomConnection; //通过该接口取得数据库的Connection
function ConnfigDBConnection :Boolean; //配置Connection连接参数
function getConnDBKind: TDBKind; //数据库类型
procedure setConnDBConfig(pConnDBConfig :TDBConfig); //通过该类设置Connection参数
end;
//==============================================================================
// 抽象数据库连接对象基类
//==============================================================================
TConnDatabase = class(TPersistent,IConnDatabase)
private
fConnDBKind: TDBKind; //数据库连接方式
fConnDBConfig: TDBConfig; //数据库配置参数类
protected
FRefCount: Integer;
pDBConn: TCustomConnection;
//接口必须实现部分
function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
function _AddRef: Integer; stdcall;
function _Release: Integer; stdcall;
//接口
function getDBConnection: TCustomConnection; virtual; abstract;
function ConnfigDBConnection: Boolean; virtual; abstract;
procedure setConnDBKind(pConnDBKind :TDBKind);
function getConnDBKind: TDBKind;
procedure setConnDBConfig(pConnDBConfig :TDBConfig);
function getConnDBConfig: TDBConfig;
public
destructor Destroy; override;
published
property DBConnection: TCustomConnection read getDBConnection;
property ConnDBKind: TDBKind read getConnDBKind write setConnDBKind;
property ConnDBConfig: TDBConfig read getConnDBConfig write setConnDBConfig;
end;
implementation
function TConnDatabase.QueryInterface(const IID: TGUID; out Obj): HResult;
begin
if GetInterface(IID, Obj) then
Result := 0
else
Result := E_NOINTERFACE;
end;
function TConnDatabase._AddRef: Integer;
begin
Result := InterlockedIncrement(FRefCount);
end;
function TConnDatabase._Release: Integer;
begin
Result := InterlockedDecrement(FRefCount);
if Result = 0 then
Destroy;
end;
procedure TConnDatabase.setConnDBKind(pConnDBKind :TDBKind);
begin
ConnDBKind := pConnDBKind;
end;
function TConnDatabase.getConnDBKind: TDBKind;
begin
Result := ConnDBKind;
end;
procedure TConnDatabase.setConnDBConfig(pConnDBConfig :TDBConfig);
begin
fConnDBConfig := pConnDBConfig;
end;
function TConnDatabase.getConnDBConfig: TDBConfig;
begin
Result := fConnDBConfig;
end;
destructor TConnDatabase.Destroy;
begin
inherited Destroy;
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?