ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/branches/udr/udr/testsuite/udrlib/udr_test02.pas
Revision: 386
Committed: Tue Jan 18 12:05:35 2022 UTC (2 years, 3 months ago) by tony
Content type: text/x-pascal
File size: 4470 byte(s)
Log Message:
Silent exceptions bug fixed

File Contents

# Content
1 (*
2 * Firebird UDR Support (fbudrtested). The fbudr components provide a set of
3 * Pascal language bindings for the Firebird API in support of server
4 * side User Defined Routines (UDRs). The fbudr package is an extension
5 * to the Firebird Pascal API.
6 *
7 * The contents of this file are subject to the Initial Developer's
8 * Public License Version 1.0 (the "License"); you may not use this
9 * file except in compliance with the License. You may obtain a copy
10 * of the License here:
11 *
12 * http://www.firebirdsql.org/index.php?op=doc&id=idpl
13 *
14 * Software distributed under the License is distributed on an "AS
15 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
16 * implied. See the License for the specific language governing rights
17 * and limitations under the License.
18 *
19 * The Initial Developer of the Original Code is Tony Whyman.
20 *
21 * The Original Code is (C) 2021 Tony Whyman, MWA Software
22 * (http://www.mwasoftware.co.uk).
23 *
24 * All Rights Reserved.
25 *
26 * Contributor(s): ______________________________________.
27 *
28 *)
29 unit udr_test02;
30
31 {$IFDEF MSWINDOWS}
32 {$DEFINE WINDOWS}
33 {$ENDIF}
34
35 {$IFDEF FPC}
36 {$mode delphi}
37 {$codepage UTF8}
38 {$interfaces COM}
39 {$ENDIF}
40
41 interface
42
43 uses
44 Classes, SysUtils, IB, FBUDRController, FBUDRIntf;
45
46 {This unit provides the implementation of selected number of UDR Execute
47 procedures used to test out various aspects of the TFBUDRExecuteProcedure class.
48 Note that each class is registered with the FBUDRController at initialization time.}
49
50 type
51 {TMyTestProcedure is a simple Execute procedure to demonstrate use of the
52 UDR library. The Employee database is assumed. The input parameter selects a
53 row in the EMPLOYEE table and the procedure returns the salary and full name
54 of the selected employee.
55
56 create or alter procedure MyTestProc (
57 EMP_NO SMALLINT
58 ) returns (Salary Numeric(10,2), FullName VarChar(36))
59 external name 'fbudrtests!test_proc'
60 engine udr;
61 }
62
63 TMyTestProcedure = class(TFBUDRExecuteProcedure)
64 public
65 procedure Execute(context: IFBUDRExternalContext;
66 ProcMetadata: IFBUDRProcMetadata;
67 InputParams: IFBUDRInputParams;
68 OutputData: IFBUDROutputData); override;
69 end;
70
71 {TMyErrorProc is intended to test out error handling for various error conditions}
72
73 {
74 Create or Alter procedure MyErrorProc (
75 ErrorCase Smallint)
76 external name 'fbudrtests!error_proc'
77 engine udr;
78 }
79
80 TMyErrorProc = class(TFBUDRExecuteProcedure)
81 public
82 procedure Execute(context: IFBUDRExternalContext;
83 ProcMetadata: IFBUDRProcMetadata;
84 InputParams: IFBUDRInputParams;
85 OutputData: IFBUDROutputData); override;
86 end;
87
88 implementation
89
90 { TMyErrorProc }
91
92 procedure TMyErrorProc.Execute(context: IFBUDRExternalContext;
93 ProcMetadata: IFBUDRProcMetadata; InputParams: IFBUDRInputParams;
94 OutputData: IFBUDROutputData);
95 var aResult: integer;
96 begin
97 with context do
98 case InputParams.ByName('ErrorCase').AsInteger of
99 0:
100 {DDL error - duplicate table name}
101 begin
102 GetAttachment.ExecImmediate([isc_tpb_write, isc_tpb_nowait, isc_tpb_read_committed],
103 'Create Global Temporary Table TestMe(EMP_NO Integer)');
104 GetAttachment.ExecImmediate([isc_tpb_write, isc_tpb_nowait, isc_tpb_read_committed],
105 'Create Global Temporary Table TestMe(EMP_NO Integer)');
106 end;
107
108 1:
109 {General Exception handling}
110 raise Exception.Create('You have a bug');
111
112 2:
113 {arithmetic exception - divide by zero}
114 begin
115 aResult := 0;
116 aResult := Round(100/aResult);
117 end;
118
119 end;
120 end;
121
122 { TMyTestProcedure }
123
124 procedure TMyTestProcedure.Execute(context: IFBUDRExternalContext;
125 ProcMetadata: IFBUDRProcMetadata; InputParams: IFBUDRInputParams;
126 OutputData: IFBUDROutputData);
127 var Results: IResultSet;
128 begin
129 with context do
130 begin
131 Results := GetAttachment.OpenCursorAtStart(GetTransaction,
132 'Select Salary, Full_Name From EMPLOYEE Where EMP_NO = ?',
133 [InputParams.ByName('EMP_NO').AsInteger]);
134 OutputData.ByName('SALARY').AsCurrency := Results.ByName('Salary').AsCurrency;
135 OutputData.ByName('FULLNAME').AsString := Results.ByName('Full_Name').AsString;
136
137 end;
138 end;
139
140 Initialization
141 FBRegisterUDRProcedure('test_proc',TMyTestProcedure);
142 FBRegisterUDRProcedure('error_proc',TMyErrorProc);
143
144 end.
145

Properties

Name Value
svn:eol-style native