如何使用FireDAC提取存储过程DDL
How to extract stored procedure DDL using FireDAC
我正在从 FIBPlus 更改为 FireDAC,我需要的大部分功能都在 FireDAC 中,我正在努力寻找与 TpFIBDBSchemaExtract 和 TpFIBScripter 等效的 FIBPlus,用于将存储过程提取为 DDL。
FireDAC 有办法从数据库中提取存储过程 DDL 吗?
例如,看起来像:
SET TERM ^ ;
CREATE PROCEDURE MY_PROC RETURNS (aParam INTEGER) AS
BEGIN
aParam = 10;
END^
FireDAC 不支持(统一)获取存储过程的 DDL 定义(目前)。因此,您需要自己从 RDB$PROCEDURES table、RDB$PROCEDURE_SOURCE 列中获取该 DDL。例如(虽然不是理想地设计为连接对象助手):
uses
FireDAC.Stan.Util;
type
TFDConnectionHelper = class helper for TFDConnection
public
function GetStoredProcCode(const AName: string): string;
end;
implementation
{ TFDConnectionHelper }
function TFDConnectionHelper.GetStoredProcCode(const AName: string): string;
var
Table: TFDDatSTable;
Command: IFDPhysCommand;
begin
CheckActive;
if RDBMSKind <> TFDRDBMSKinds.Firebird then
raise ENotSupportedException.Create('This feature is supported only for Firebird');
Result := '';
ConnectionIntf.CreateCommand(Command);
Command.CommandText := 'SELECT RDB$PROCEDURE_SOURCE FROM RDB$PROCEDURES WHERE RDB$PROCEDURE_NAME = :Name';
Command.Params[0].DataType := ftString;
Command.Params[0].Size := 31;
Command.Params[0].AsString := UpperCase(AName);
Table := TFDDatSTable.Create;
try
Command.Define(Table);
Command.Open;
Command.Fetch(Table);
if Table.Rows.Count > 0 then
Result := Table.Rows[0].GetData(0);
finally
FDFree(Table);
end;
end;
当时的用法(当您连接到 Firebird DBMS 时):
procedure TForm1.Button1Click(Sender: TObject);
var
S: string;
begin
S := FDConnection1.GetStoredProcCode('MyProcedure');
...
end;
我正在从 FIBPlus 更改为 FireDAC,我需要的大部分功能都在 FireDAC 中,我正在努力寻找与 TpFIBDBSchemaExtract 和 TpFIBScripter 等效的 FIBPlus,用于将存储过程提取为 DDL。
FireDAC 有办法从数据库中提取存储过程 DDL 吗?
例如,看起来像:
SET TERM ^ ;
CREATE PROCEDURE MY_PROC RETURNS (aParam INTEGER) AS
BEGIN
aParam = 10;
END^
FireDAC 不支持(统一)获取存储过程的 DDL 定义(目前)。因此,您需要自己从 RDB$PROCEDURES table、RDB$PROCEDURE_SOURCE 列中获取该 DDL。例如(虽然不是理想地设计为连接对象助手):
uses
FireDAC.Stan.Util;
type
TFDConnectionHelper = class helper for TFDConnection
public
function GetStoredProcCode(const AName: string): string;
end;
implementation
{ TFDConnectionHelper }
function TFDConnectionHelper.GetStoredProcCode(const AName: string): string;
var
Table: TFDDatSTable;
Command: IFDPhysCommand;
begin
CheckActive;
if RDBMSKind <> TFDRDBMSKinds.Firebird then
raise ENotSupportedException.Create('This feature is supported only for Firebird');
Result := '';
ConnectionIntf.CreateCommand(Command);
Command.CommandText := 'SELECT RDB$PROCEDURE_SOURCE FROM RDB$PROCEDURES WHERE RDB$PROCEDURE_NAME = :Name';
Command.Params[0].DataType := ftString;
Command.Params[0].Size := 31;
Command.Params[0].AsString := UpperCase(AName);
Table := TFDDatSTable.Create;
try
Command.Define(Table);
Command.Open;
Command.Fetch(Table);
if Table.Rows.Count > 0 then
Result := Table.Rows[0].GetData(0);
finally
FDFree(Table);
end;
end;
当时的用法(当您连接到 Firebird DBMS 时):
procedure TForm1.Button1Click(Sender: TObject);
var
S: string;
begin
S := FDConnection1.GetStoredProcCode('MyProcedure');
...
end;