ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/testsuite/Test16.pas
Revision: 315
Committed: Thu Feb 25 11:56:36 2021 UTC (3 years, 8 months ago) by tony
Content type: text/x-pascal
File size: 3679 byte(s)
Log Message:
Updated for IBX 4 release

File Contents

# User Rev Content
1 tony 315 unit Test16;
2    
3     {$mode objfpc}{$H+}
4    
5     {Test 16: TIBTable in master/detail relationship}
6    
7     { Description
8     Open two tables: DEPARATMENT (Master) and EMPLOYEE (Slave) from example
9     database and navigate in a master/detail relationship.
10    
11     Update employee record to illustrate update returning.
12    
13     Insert employee record to illustrate insert returning and generator
14    
15     Delete Employee record
16    
17     Rollback transaction
18     }
19    
20     interface
21    
22     uses
23     Classes, SysUtils, TestApplication, IBXTestBase, DB, IB, IBTable,
24     IBCustomDataset;
25    
26     const
27     aTestID = '16';
28     aTestTitle = 'TIBTable in master/detail relationship';
29    
30     type
31    
32     { TTest16 }
33    
34     TTest16 = class(TIBXTestBase)
35     private
36     FDepartmentTable: TIBTable;
37     FEmployeeTable: TIBTable;
38     FDataSource: TDataSource;
39     procedure HandleDeptOpen(aDataSet: TDataSet);
40     protected
41     procedure CreateObjects(Application: TTestApplication); override;
42     function GetTestID: AnsiString; override;
43     function GetTestTitle: AnsiString; override;
44     procedure InitTest; override;
45     public
46     procedure RunTest(CharSet: AnsiString; SQLDialect: integer); override;
47     end;
48    
49    
50     implementation
51    
52     { TTest16 }
53    
54     procedure TTest16.HandleDeptOpen(aDataSet: TDataSet);
55     begin
56     FEmployeeTable.Active := true;
57     end;
58    
59     procedure TTest16.CreateObjects(Application: TTestApplication);
60     begin
61     inherited CreateObjects(Application);
62     FDepartmentTable := TIBTable.Create(Application);
63     with FDepartmentTable do
64     begin
65     Database := IBDatabase;
66     TableName := 'DEPARTMENT';
67     IndexFieldNames := 'DEPT_NO';
68     ReadOnly := true;
69     AfterOpen := @HandleDeptOpen;
70     end;
71     FDataSource := TDataSource.Create(Application);
72     FDataSource.DataSet := FDepartmentTable;
73     FEmployeeTable := TIBTable.Create(Application);
74     with FEmployeeTable do
75     begin
76     Database := IBDatabase;
77     TableName := 'EMPLOYEE';
78     MasterSource := FDataSource;
79     IndexFieldNames := 'DEPT_NO';
80     MasterFields := 'DEPT_NO';
81     with GeneratorField do
82     begin
83     ApplyOnEvent := gaeOnNewRecord;
84     Field := 'EMP_NO';
85     Generator := 'EMP_NO_GEN';
86     end;
87     end;
88     end;
89    
90     function TTest16.GetTestID: AnsiString;
91     begin
92     Result := aTestID;
93     end;
94    
95     function TTest16.GetTestTitle: AnsiString;
96     begin
97     Result := aTestTitle;
98     end;
99    
100     procedure TTest16.InitTest;
101     begin
102     inherited InitTest;
103     IBDatabase.DatabaseName := Owner.GetEmployeeDatabaseName;
104     ReadWriteTransaction;
105     end;
106    
107     procedure TTest16.RunTest(CharSet: AnsiString; SQLDialect: integer);
108     begin
109     IBDatabase.Connected := true;
110     IBTransaction.Active := true;
111     try
112     FDepartmentTable.Active := true;
113     writeln(OutFile);
114     writeln(OutFile,'Department No ',FDepartmentTable.FieldByName('DEPT_NO').AsString,' Selected');
115     PrintDataSet(FEmployeeTable);
116     if FDepartmentTable.Locate('DEPT_NO','600',[]) then
117     begin
118     writeln(OutFile);
119     writeln(OutFile,'Department No ',FDepartmentTable.FieldByName('DEPT_NO').AsString,' Selected');
120     PrintDataSet(FEmployeeTable);
121     end
122     else
123     writeln(OutFile,'Unable to locate Dept 600');
124     if FDepartmentTable.Locate('DEPT_NO','621',[]) then
125     begin
126     writeln(OutFile);
127     writeln(OutFile,'Department No ',FDepartmentTable.FieldByName('DEPT_NO').AsString,' Selected');
128     PrintDataSet(FEmployeeTable);
129     end
130     else
131     writeln(OutFile,'Unable to locate Dept 621');
132    
133     writeln(OutFile);
134     writeln(OutFile,'Update Row with Computed Field');
135     with FEmployeeTable do
136     begin
137     Edit;
138     FieldByName('FIRST_NAME').AsString := 'Boris';
139     Post;
140     end;
141     PrintDataSetRow(FEmployeeTable);
142     finally
143     IBTransaction.Rollback;
144     IBDatabase.Connected := false;
145     end;
146     end;
147    
148     initialization
149     RegisterTest(TTest16);
150    
151     end.
152