1 |
tony |
381 |
program myudrtestbed;
|
2 |
|
|
|
3 |
|
|
{$APPTYPE CONSOLE}
|
4 |
|
|
|
5 |
|
|
{$R *.res}
|
6 |
|
|
|
7 |
|
|
uses
|
8 |
|
|
Classes,
|
9 |
|
|
FBUDRController,
|
10 |
|
|
FBUdrPlugin,
|
11 |
|
|
IB,
|
12 |
|
|
udr_myrowcount in '..\udrlibrary\udr_myrowcount.pas';
|
13 |
|
|
|
14 |
|
|
procedure TestRowCount(UDRPlugin: TFBUdrPluginEmulator);
|
15 |
|
|
var MyRowCount: TExternalFunctionWrapper;
|
16 |
|
|
Transaction: ITransaction;
|
17 |
|
|
Rows: integer;
|
18 |
|
|
begin
|
19 |
|
|
{Get the emulator wrapper for the row_count function, declared as MyRowCount}
|
20 |
|
|
MyRowCount := UDRPlugin.makeFunction('MYROWCOUNT', {Name of Function in database - case sensitive}
|
21 |
|
|
'', {package name is empty}
|
22 |
|
|
'myudrlibrary!row_count' {entry point}
|
23 |
|
|
);
|
24 |
|
|
try
|
25 |
|
|
writeln('Row Count for Employee');
|
26 |
|
|
{set the input parameter to the EMPLOYEE table}
|
27 |
|
|
MyRowCount.InputParams[0].AsString := 'EMPLOYEE';
|
28 |
|
|
|
29 |
|
|
Transaction := UDRPlugin.Attachment.StartTransaction([isc_tpb_read,isc_tpb_nowait,isc_tpb_concurrency],taCommit);
|
30 |
|
|
{invoke the function and print the result}
|
31 |
|
|
writeln('Employee Row Count = ',MyRowCount.Execute(Transaction).AsInteger);
|
32 |
|
|
writeln;
|
33 |
|
|
finally
|
34 |
|
|
MyRowCount.Free
|
35 |
|
|
end;
|
36 |
|
|
end;
|
37 |
|
|
|
38 |
|
|
procedure RunTest;
|
39 |
|
|
var Attachment: IAttachment;
|
40 |
|
|
DPB: IDPB;
|
41 |
|
|
UDRPlugin: TFBUdrPluginEmulator;
|
42 |
|
|
begin
|
43 |
|
|
{Open a connection with the example employee database. Amend database parameters
|
44 |
|
|
as needed.}
|
45 |
|
|
DPB := FirebirdAPI.AllocateDPB;
|
46 |
|
|
DPB.Add(isc_dpb_user_name).setAsString('SYSDBA');
|
47 |
|
|
DPB.Add(isc_dpb_password).setAsString('masterkey');
|
48 |
|
|
DPB.Add(isc_dpb_lc_ctype).setAsString('UTF8');
|
49 |
|
|
DPB.Add(isc_dpb_set_db_SQL_dialect).setAsByte(3);
|
50 |
|
|
Attachment := FirebirdAPI.OpenDatabase('localhost:employee',DPB);
|
51 |
|
|
try
|
52 |
|
|
UDRPlugin := TFBUdrPluginEmulator.Create(FBUDRControllerOptions.ModuleName);
|
53 |
|
|
try
|
54 |
|
|
{initialize the emulator with the database connection}
|
55 |
|
|
UDRPlugin.Attachment := Attachment;
|
56 |
|
|
TestRowCount(UDRPlugin);
|
57 |
|
|
finally
|
58 |
|
|
UDRPlugin.Free;
|
59 |
|
|
end;
|
60 |
|
|
finally
|
61 |
|
|
Attachment.Disconnect(true);
|
62 |
|
|
end;
|
63 |
|
|
end;
|
64 |
|
|
|
65 |
|
|
begin
|
66 |
|
|
with FBUDRControllerOptions do
|
67 |
|
|
begin
|
68 |
|
|
ModuleName := 'myudrlibrary';
|
69 |
|
|
AllowConfigFileOverrides := true;
|
70 |
|
|
LogFileNameTemplate := '$LOGDIR$MODULE.log';
|
71 |
|
|
LogOptions := [loLogFunctions, loLogProcedures, loLogTriggers, loDetails];
|
72 |
|
|
end;
|
73 |
|
|
RunTest;
|
74 |
|
|
readln; {force console window to stay open}
|
75 |
|
|
end.
|