2019獨角獸企業重金招聘Python工程師标準>>>
在系統開發是,有時我們需要連結不同的資料庫,連接配接MySQL同時需要連接配接MSSQL,在架構中按照下面方法設定。
打開 uDBConfig.pas 檔案
代碼如下,這裡進行使用資料庫的設定,如果有新資料庫連結,參考MYSQL 方式新聲明類型,建立,釋放,其中 類型參數名稱要與Config.json 配置中一緻。
unit uDBConfig;
interface
uses
DBSQLite, DBMySql;
type
TDBConfig = class
public
Default: TDBSQLite; //必須有Default成員變量名
MYSQL: TDBMySql;
constructor Create;
destructor Destroy; override;
end;
implementation
{ TDBConfig }
constructor TDBConfig.Create;
begin
Default := TDBSQLite.Create('SQLite');
MYSQL := TDBMySql.Create('MYSQL');
end;
destructor TDBConfig.Destroy;
begin
Default.Free;
MYSQL.Free;
inherited;
end;
end.
使用時按照下面方法
ret := Db.MYSQL.FindFirst('tb_users');//使用MYSQL資料庫
ret := Db.Default.FindFirst('tb_users');//使用 SQLite 資料庫
轉載于:https://my.oschina.net/delphimvc/blog/3041555