1 |
tony |
381 |
unit udr_myrowcount;
|
2 |
|
|
|
3 |
|
|
{$IFDEF MSWINDOWS}
|
4 |
|
|
{$DEFINE WINDOWS}
|
5 |
|
|
{$ENDIF}
|
6 |
|
|
|
7 |
|
|
{$IFDEF FPC}
|
8 |
|
|
{$mode delphi}
|
9 |
|
|
{$codepage UTF8}
|
10 |
|
|
{$interfaces COM}
|
11 |
|
|
{$ENDIF}
|
12 |
|
|
|
13 |
|
|
interface
|
14 |
|
|
|
15 |
|
|
uses
|
16 |
|
|
Classes, SysUtils, IB, FBUDRController, FBUDRIntf;
|
17 |
|
|
|
18 |
|
|
{ The DDL for this external function is
|
19 |
|
|
|
20 |
|
|
create or alter function MyRowCount (
|
21 |
|
|
table_name varchar(31)
|
22 |
|
|
) returns integer
|
23 |
|
|
external name 'fbudrtests!row_count'
|
24 |
|
|
engine udr;
|
25 |
|
|
}
|
26 |
|
|
|
27 |
|
|
type
|
28 |
|
|
TMyRowCountFunction = class(TFBUDRFunction)
|
29 |
|
|
public
|
30 |
|
|
function Execute(context: IFBUDRExternalContext;
|
31 |
|
|
ProcMetadata: IFBUDRProcMetadata;
|
32 |
|
|
InputParams: IFBUDRInputParams;
|
33 |
|
|
ResultSQLType: cardinal): variant; override;
|
34 |
|
|
end;
|
35 |
|
|
|
36 |
|
|
implementation
|
37 |
|
|
|
38 |
|
|
function TMyRowCountFunction.Execute(context: IFBUDRExternalContext;
|
39 |
|
|
ProcMetadata: IFBUDRProcMetadata; InputParams: IFBUDRInputParams;
|
40 |
|
|
ResultSQLType: cardinal): variant;
|
41 |
|
|
begin
|
42 |
|
|
with context do
|
43 |
|
|
begin
|
44 |
|
|
Result := GetAttachment.OpenCursorAtStart(GetTransaction,
|
45 |
|
|
'Select count(*) from ' + InputParams.ByName('table_name').AsString)[0].AsInteger;
|
46 |
|
|
end;
|
47 |
|
|
end;
|
48 |
|
|
|
49 |
|
|
Initialization
|
50 |
|
|
FBRegisterUDRFunction('row_count',TmyRowCountFunction);
|
51 |
|
|
|
52 |
|
|
end.
|
53 |
|
|
|