ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/branches/udr/udr/testsuite/udrlib/udr_test04.pas
Revision: 371
Committed: Wed Jan 5 15:21:22 2022 UTC (2 years, 3 months ago) by tony
Content type: text/x-pascal
File size: 3061 byte(s)
Log Message:
Beta Release 0.1

File Contents

# User Rev Content
1 tony 371 (*
2     * Firebird UDR Support (fbudrtestbed). 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_test04;
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 a UDR trigger and is used
47     to test out various aspects of the TFBUDRTrigger class. Note that each class is
48     registered with the FBUDRController at initialization time.}
49    
50     type
51     {This test adds an extra column to EMPLOYEE table to work with with an update before trigger.
52     This is OLD_PHONE_EXT. The trigger checks to see if the Phone_Ext has been updated and, if so, the old
53     value is saved in OLD_PHONE_EXT.
54    
55     Alter Table EMPLOYEE Add PREVIOUS_PHONE_EXT VarChar(4);
56    
57     Create or Alter Trigger MyEmployeeUpdate Active Before Update On EMPLOYEE
58     external name 'fbudrtests!my_employee_update'
59     engine udr;
60     }
61    
62     { TMyEmployeeUpdateTrigger }
63    
64     TMyEmployeeUpdateTrigger = class(TFBUDRTrigger)
65     public
66     procedure BeforeTrigger(context: IFBUDRExternalContext;
67     TriggerMetaData: IFBUDRTriggerMetaData;
68     action: TFBUDRTriggerAction;
69     OldParams: IFBUDRInputParams;
70     NewParams: IFBUDROutputData); override;
71     end;
72    
73     implementation
74    
75     { TMyEmployeeUpdateTrigger }
76    
77     procedure TMyEmployeeUpdateTrigger.BeforeTrigger(
78     context: IFBUDRExternalContext; TriggerMetaData: IFBUDRTriggerMetaData;
79     action: TFBUDRTriggerAction; OldParams: IFBUDRInputParams;
80     NewParams: IFBUDROutputData);
81     begin
82     if (TriggerMetaData.getTriggerType <> ttBefore) or (action <> taUpdate) then
83     raise Exception.CreateFmt('%s should be an update before trigger',[Name]);
84    
85     if OldParams.ByName('PHONE_EXT').AsString <> NewParams.ByName('PHONE_EXT').AsString then
86     NewParams.ByName('PREVIOUS_PHONE_EXT').AsString := OldParams.ByName('PHONE_EXT').AsString;
87     end;
88    
89     initialization
90     FBRegisterUDRTrigger('my_employee_update', TMyEmployeeUpdateTrigger);
91    
92     end.
93