1 |
tony |
323 |
(* |
2 |
|
|
* IBX Test suite. This program is used to test the IBX non-visual |
3 |
|
|
* components and provides a semi-automated pass/fail check for each test. |
4 |
|
|
* |
5 |
|
|
* The contents of this file are subject to the Initial Developer's |
6 |
|
|
* Public License Version 1.0 (the "License"); you may not use this |
7 |
|
|
* file except in compliance with the License. You may obtain a copy |
8 |
|
|
* of the License here: |
9 |
|
|
* |
10 |
|
|
* http://www.firebirdsql.org/index.php?op=doc&id=idpl |
11 |
|
|
* |
12 |
|
|
* Software distributed under the License is distributed on an "AS |
13 |
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or |
14 |
|
|
* implied. See the License for the specific language governing rights |
15 |
|
|
* and limitations under the License. |
16 |
|
|
* |
17 |
|
|
* The Initial Developer of the Original Code is Tony Whyman. |
18 |
|
|
* |
19 |
|
|
* The Original Code is (C) 2021 Tony Whyman, MWA Software |
20 |
|
|
* (http://www.mwasoftware.co.uk). |
21 |
|
|
* |
22 |
|
|
* All Rights Reserved. |
23 |
|
|
* |
24 |
|
|
* Contributor(s): ______________________________________. |
25 |
|
|
* |
26 |
|
|
*) |
27 |
tony |
315 |
unit Test16; |
28 |
|
|
|
29 |
|
|
{$mode objfpc}{$H+} |
30 |
|
|
|
31 |
|
|
{Test 16: TIBTable in master/detail relationship} |
32 |
|
|
|
33 |
|
|
{ Description |
34 |
|
|
Open two tables: DEPARATMENT (Master) and EMPLOYEE (Slave) from example |
35 |
|
|
database and navigate in a master/detail relationship. |
36 |
|
|
|
37 |
|
|
Update employee record to illustrate update returning. |
38 |
|
|
|
39 |
|
|
Insert employee record to illustrate insert returning and generator |
40 |
|
|
|
41 |
|
|
Delete Employee record |
42 |
|
|
|
43 |
|
|
Rollback transaction |
44 |
|
|
} |
45 |
|
|
|
46 |
|
|
interface |
47 |
|
|
|
48 |
|
|
uses |
49 |
|
|
Classes, SysUtils, TestApplication, IBXTestBase, DB, IB, IBTable, |
50 |
|
|
IBCustomDataset; |
51 |
|
|
|
52 |
|
|
const |
53 |
|
|
aTestID = '16'; |
54 |
|
|
aTestTitle = 'TIBTable in master/detail relationship'; |
55 |
|
|
|
56 |
|
|
type |
57 |
|
|
|
58 |
|
|
{ TTest16 } |
59 |
|
|
|
60 |
|
|
TTest16 = class(TIBXTestBase) |
61 |
|
|
private |
62 |
|
|
FDepartmentTable: TIBTable; |
63 |
|
|
FEmployeeTable: TIBTable; |
64 |
|
|
FDataSource: TDataSource; |
65 |
|
|
procedure HandleDeptOpen(aDataSet: TDataSet); |
66 |
|
|
protected |
67 |
|
|
procedure CreateObjects(Application: TTestApplication); override; |
68 |
|
|
function GetTestID: AnsiString; override; |
69 |
|
|
function GetTestTitle: AnsiString; override; |
70 |
|
|
procedure InitTest; override; |
71 |
|
|
public |
72 |
|
|
procedure RunTest(CharSet: AnsiString; SQLDialect: integer); override; |
73 |
|
|
end; |
74 |
|
|
|
75 |
|
|
|
76 |
|
|
implementation |
77 |
|
|
|
78 |
|
|
{ TTest16 } |
79 |
|
|
|
80 |
|
|
procedure TTest16.HandleDeptOpen(aDataSet: TDataSet); |
81 |
|
|
begin |
82 |
|
|
FEmployeeTable.Active := true; |
83 |
|
|
end; |
84 |
|
|
|
85 |
|
|
procedure TTest16.CreateObjects(Application: TTestApplication); |
86 |
|
|
begin |
87 |
|
|
inherited CreateObjects(Application); |
88 |
|
|
FDepartmentTable := TIBTable.Create(Application); |
89 |
|
|
with FDepartmentTable do |
90 |
|
|
begin |
91 |
|
|
Database := IBDatabase; |
92 |
|
|
TableName := 'DEPARTMENT'; |
93 |
|
|
IndexFieldNames := 'DEPT_NO'; |
94 |
|
|
ReadOnly := true; |
95 |
|
|
AfterOpen := @HandleDeptOpen; |
96 |
|
|
end; |
97 |
|
|
FDataSource := TDataSource.Create(Application); |
98 |
|
|
FDataSource.DataSet := FDepartmentTable; |
99 |
|
|
FEmployeeTable := TIBTable.Create(Application); |
100 |
|
|
with FEmployeeTable do |
101 |
|
|
begin |
102 |
|
|
Database := IBDatabase; |
103 |
|
|
TableName := 'EMPLOYEE'; |
104 |
|
|
MasterSource := FDataSource; |
105 |
|
|
IndexFieldNames := 'DEPT_NO'; |
106 |
|
|
MasterFields := 'DEPT_NO'; |
107 |
|
|
with GeneratorField do |
108 |
|
|
begin |
109 |
|
|
ApplyOnEvent := gaeOnNewRecord; |
110 |
|
|
Field := 'EMP_NO'; |
111 |
|
|
Generator := 'EMP_NO_GEN'; |
112 |
|
|
end; |
113 |
|
|
end; |
114 |
|
|
end; |
115 |
|
|
|
116 |
|
|
function TTest16.GetTestID: AnsiString; |
117 |
|
|
begin |
118 |
|
|
Result := aTestID; |
119 |
|
|
end; |
120 |
|
|
|
121 |
|
|
function TTest16.GetTestTitle: AnsiString; |
122 |
|
|
begin |
123 |
|
|
Result := aTestTitle; |
124 |
|
|
end; |
125 |
|
|
|
126 |
|
|
procedure TTest16.InitTest; |
127 |
|
|
begin |
128 |
|
|
inherited InitTest; |
129 |
|
|
IBDatabase.DatabaseName := Owner.GetEmployeeDatabaseName; |
130 |
|
|
ReadWriteTransaction; |
131 |
|
|
end; |
132 |
|
|
|
133 |
|
|
procedure TTest16.RunTest(CharSet: AnsiString; SQLDialect: integer); |
134 |
|
|
begin |
135 |
|
|
IBDatabase.Connected := true; |
136 |
|
|
IBTransaction.Active := true; |
137 |
|
|
try |
138 |
|
|
FDepartmentTable.Active := true; |
139 |
|
|
writeln(OutFile); |
140 |
|
|
writeln(OutFile,'Department No ',FDepartmentTable.FieldByName('DEPT_NO').AsString,' Selected'); |
141 |
|
|
PrintDataSet(FEmployeeTable); |
142 |
|
|
if FDepartmentTable.Locate('DEPT_NO','600',[]) then |
143 |
|
|
begin |
144 |
|
|
writeln(OutFile); |
145 |
|
|
writeln(OutFile,'Department No ',FDepartmentTable.FieldByName('DEPT_NO').AsString,' Selected'); |
146 |
|
|
PrintDataSet(FEmployeeTable); |
147 |
|
|
end |
148 |
|
|
else |
149 |
|
|
writeln(OutFile,'Unable to locate Dept 600'); |
150 |
|
|
if FDepartmentTable.Locate('DEPT_NO','621',[]) then |
151 |
|
|
begin |
152 |
|
|
writeln(OutFile); |
153 |
|
|
writeln(OutFile,'Department No ',FDepartmentTable.FieldByName('DEPT_NO').AsString,' Selected'); |
154 |
|
|
PrintDataSet(FEmployeeTable); |
155 |
|
|
end |
156 |
|
|
else |
157 |
|
|
writeln(OutFile,'Unable to locate Dept 621'); |
158 |
|
|
|
159 |
|
|
writeln(OutFile); |
160 |
|
|
writeln(OutFile,'Update Row with Computed Field'); |
161 |
|
|
with FEmployeeTable do |
162 |
|
|
begin |
163 |
|
|
Edit; |
164 |
|
|
FieldByName('FIRST_NAME').AsString := 'Boris'; |
165 |
|
|
Post; |
166 |
|
|
end; |
167 |
|
|
PrintDataSetRow(FEmployeeTable); |
168 |
|
|
finally |
169 |
|
|
IBTransaction.Rollback; |
170 |
|
|
IBDatabase.Connected := false; |
171 |
|
|
end; |
172 |
|
|
end; |
173 |
|
|
|
174 |
|
|
initialization |
175 |
|
|
RegisterTest(TTest16); |
176 |
|
|
|
177 |
|
|
end. |
178 |
|
|
|