1 |
(* Firebird UDR Support (fbudrtestbed). The fbudr components provide a set of
|
2 |
* Pascal language bindings for the Firebird API in support of server
|
3 |
* side User Defined Routines (UDRs). The fbudr package is an extension
|
4 |
* to the Firebird Pascal API.
|
5 |
*
|
6 |
* The contents of this file are subject to the Initial Developer's
|
7 |
* Public License Version 1.0 (the "License"); you may not use this
|
8 |
* file except in compliance with the License. You may obtain a copy
|
9 |
* of the License here:
|
10 |
*
|
11 |
* http://www.firebirdsql.org/index.php?op=doc&id=idpl
|
12 |
*
|
13 |
* Software distributed under the License is distributed on an "AS
|
14 |
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
15 |
* implied. See the License for the specific language governing rights
|
16 |
* and limitations under the License.
|
17 |
*
|
18 |
* The Initial Developer of the Original Code is Tony Whyman.
|
19 |
*
|
20 |
* The Original Code is (C) 2021 Tony Whyman, MWA Software
|
21 |
* (http://www.mwasoftware.co.uk).
|
22 |
*
|
23 |
* All Rights Reserved.
|
24 |
*
|
25 |
* Contributor(s): ______________________________________.
|
26 |
*
|
27 |
*)
|
28 |
unit Test03;
|
29 |
|
30 |
{$IFDEF MSWINDOWS}
|
31 |
{$DEFINE WINDOWS}
|
32 |
{$ENDIF}
|
33 |
|
34 |
{$IFDEF FPC}
|
35 |
{$mode delphi}
|
36 |
{$codepage utf8}
|
37 |
{$ENDIF}
|
38 |
|
39 |
interface
|
40 |
|
41 |
uses
|
42 |
Classes, SysUtils, TestApplication, FBUDRTestApp, IB, FBUdrPlugin;
|
43 |
|
44 |
type
|
45 |
|
46 |
{ TTest03 }
|
47 |
|
48 |
{Test 03 is used to perform client side testing (UDR engine emulation) for the
|
49 |
UDR Select procedure declared in udr_test03.pas.}
|
50 |
|
51 |
TTest03 = class(TFBUDRTestBase)
|
52 |
private
|
53 |
procedure DoQuery(Attachment: IAttachment);
|
54 |
protected
|
55 |
function GetTestID: AnsiString; override;
|
56 |
function GetTestTitle: AnsiString; override;
|
57 |
public
|
58 |
procedure RunTest(CharSet: AnsiString; SQLDialect: integer); override;
|
59 |
end;
|
60 |
|
61 |
implementation
|
62 |
|
63 |
{ TTest03 }
|
64 |
|
65 |
procedure TTest03.DoQuery(Attachment: IAttachment);
|
66 |
var MyTestProc: TExternalProcedureWrapper;
|
67 |
Transaction: ITransaction;
|
68 |
Results: IProcedureResults;
|
69 |
begin
|
70 |
UDRPlugin.Attachment := Attachment;
|
71 |
MyTestProc := UDRPlugin.GetExternalProcedure('MYSELECTPROC','','fbudrtests!select_proc');
|
72 |
try
|
73 |
writeln(OutFile,'List Employees, salaries and accumulated salary');
|
74 |
Transaction := Attachment.StartTransaction([isc_tpb_read,isc_tpb_nowait,isc_tpb_concurrency],taCommit);
|
75 |
Results := MyTestProc.Execute(Transaction);
|
76 |
while Results.FetchNext do
|
77 |
begin
|
78 |
write(OutFile,Results[0].AsString);
|
79 |
write(OutFile,', Salary = ',Results[1].AsString);
|
80 |
writeln(Outfile,' Acc Salary = $',Results[2].AsString);
|
81 |
end;
|
82 |
writeln(OutFile);
|
83 |
finally
|
84 |
MyTestProc.Free;
|
85 |
end;
|
86 |
end;
|
87 |
|
88 |
function TTest03.GetTestID: AnsiString;
|
89 |
begin
|
90 |
Result := '03';
|
91 |
end;
|
92 |
|
93 |
function TTest03.GetTestTitle: AnsiString;
|
94 |
begin
|
95 |
Result := 'UDR Select Procedure Test';
|
96 |
end;
|
97 |
|
98 |
const
|
99 |
DDL: array [0..0] of Ansistring = ('create or alter procedure MySelectProc () '+
|
100 |
'returns (FullName VarChar(36), '+
|
101 |
'Salary Numeric(10,2), AccSalary Numeric(10,2) ) as begin SUSPEND; end'
|
102 |
);
|
103 |
|
104 |
CleanUpDDL: array [0..0] of Ansistring = ('Drop procedure MySelectProc');
|
105 |
|
106 |
|
107 |
{The test is run using the employee database. Note that dummy versions of the
|
108 |
UDR Select Procedure must be declared in the database in order to generate the input
|
109 |
and output parameter metadata. These are always (re-)defined when the test is
|
110 |
started and removed at the end.
|
111 |
}
|
112 |
|
113 |
procedure TTest03.RunTest(CharSet: AnsiString; SQLDialect: integer);
|
114 |
var Attachment: IAttachment;
|
115 |
DPB: IDPB;
|
116 |
begin
|
117 |
DPB := FirebirdAPI.AllocateDPB;
|
118 |
DPB.Add(isc_dpb_user_name).setAsString(Owner.GetUserName);
|
119 |
DPB.Add(isc_dpb_password).setAsString(Owner.GetPassword);
|
120 |
DPB.Add(isc_dpb_lc_ctype).setAsString(CharSet);
|
121 |
DPB.Add(isc_dpb_set_db_SQL_dialect).setAsByte(SQLDialect);
|
122 |
Attachment := FirebirdAPI.OpenDatabase(Owner.GetEmployeeDatabaseName,DPB);
|
123 |
try
|
124 |
ApplyDDL(Attachment,DDL);
|
125 |
DoQuery(Attachment);
|
126 |
finally
|
127 |
ApplyDDL(Attachment,CleanUpDDL);
|
128 |
Attachment.Disconnect;
|
129 |
end;
|
130 |
end;
|
131 |
|
132 |
initialization
|
133 |
RegisterTest(TTest03);
|
134 |
end.
|
135 |
|