ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/fbintf/testsuite/Test11.pas
Revision: 308
Committed: Sat Jul 18 10:26:30 2020 UTC (4 years, 5 months ago) by tony
Content type: text/x-pascal
File size: 8070 byte(s)
Log Message:
Fixes Merged

File Contents

# Content
1 unit Test11;
2 {$IFDEF MSWINDOWS}
3 {$DEFINE WINDOWS}
4 {$ENDIF}
5
6 {$IFDEF FPC}
7 {$mode delphi}
8 {$codepage utf8}
9 {$ENDIF}
10
11 {Test 11: Services API}
12
13 {
14 This test attaches to the Server Manager associated with the Employee Database
15 and then accesses and prints out:
16
17 Version Info
18 Config Params
19 Database Information
20 User Information
21 Statistics
22 Licence Info
23 Licence Mask Info
24 Capabilities
25 limbo transactions
26
27 Note that two exceptions are normal as Firebird does not provide licence info.
28 }
29
30 interface
31
32 uses
33 Classes, SysUtils, TestManager, IB;
34
35 type
36
37 { TTest11 }
38
39 TTest11 = class(TTestBase)
40 private
41 procedure GetStatistics(Service: IServiceManager; DBName: AnsiString);
42 procedure BackupRestore(Service: IServiceManager; DBName: AnsiString);
43 public
44 function TestTitle: AnsiString; override;
45 procedure RunTest(CharSet: AnsiString; SQLDialect: integer); override;
46 end;
47
48 implementation
49
50 { TTest11 }
51
52 procedure TTest11.GetStatistics(Service: IServiceManager; DBName: AnsiString);
53 var Req: ISRB;
54 Results: IServiceQueryResults;
55 begin
56 {Version Info}
57 Req := Service.AllocateSRB;
58 Req.Add(isc_info_svc_version);
59 Req.Add(isc_info_svc_server_version);
60 Req.Add(isc_info_svc_implementation);
61 Results := Service.Query(nil,Req);
62 WriteServiceQueryResult(Results);
63
64 {Config Params}
65 Req := Service.AllocateSRB;
66 Req.Add(isc_info_svc_get_env_lock);
67 Req.Add(isc_info_svc_get_config);
68 Req.Add(isc_info_svc_get_env_msg);
69 Req.Add(isc_info_svc_user_dbpath);
70 Results := Service.Query(nil,Req);
71 WriteServiceQueryResult(Results);
72
73 {Database Information}
74 Req := Service.AllocateSRB;
75 Req.Add(isc_info_svc_svr_db_info);
76 Results := Service.Query(nil,Req);
77 WriteServiceQueryResult(Results);
78
79 {User Information}
80 Req := Service.AllocateSRB;
81 Req.Add(isc_action_svc_display_user);
82 Service.Start(Req);
83 Req := Service.AllocateSRB;
84 Req.Add(isc_info_svc_get_users);
85 Results := Service.Query(nil,Req);
86 WriteServiceQueryResult(Results);
87
88 Service.Detach;
89 Service.Attach;
90
91 {Statistics}
92
93 if Owner.ShowStatistics then
94 begin
95 writeln(OutFile,'Get Statistics');
96 writeln(OutFile);
97 Req := Service.AllocateSRB;
98 Req.Add(isc_action_svc_db_stats);
99 Req.Add(isc_spb_dbname).SetAsString(DBName);
100 Req.Add(isc_spb_options).SetAsInteger(isc_spb_sts_data_pages or {
101 isc_spb_sts_hdr_pages or} isc_spb_sts_idx_pages or
102 isc_spb_sts_sys_relations);
103
104 try
105 Service.Start(Req);
106 Req := Service.AllocateSRB;
107 Req.Add(isc_info_svc_line);
108 repeat
109 Results := Service.Query(nil,Req);
110 until not WriteServiceQueryResult(Results);
111 except on E: Exception do
112 writeln(OutFile,'Statistics Service Start: ',E.Message);
113 end;
114 writeln(OutFile);
115 end;
116
117 {Licence Info}
118 Req := Service.AllocateSRB;
119 Req.Add(isc_info_svc_get_license);
120 Req.Add(isc_info_svc_get_licensed_users);
121 try
122 Results := Service.Query(nil,Req);
123 WriteServiceQueryResult(Results);
124 except on E: Exception do
125 writeln(OutFile,'Licence Info: ',E.Message);
126 end;
127 writeln(OutFile);
128
129 {Licence Mask Info}
130 Req := Service.AllocateSRB;
131 Req.Add(isc_info_svc_get_license_mask);
132 try
133 Results := Service.Query(nil,Req);
134 WriteServiceQueryResult(Results);
135 except on E: Exception do
136 writeln(OutFile,'Licence Mask Info: ',E.Message);
137 end;
138 writeln(OutFile);
139
140 {Capabilities}
141 Req := Service.AllocateSRB;
142 Req.Add(isc_info_svc_capabilities);
143 try
144 Results := Service.Query(nil,Req);
145 WriteServiceQueryResult(Results);
146 except on E: Exception do
147 writeln(OutFile,'Capabilities: ',E.Message);
148 end;
149 writeln(OutFile);
150
151 {limbo transactions}
152
153 writeln(OutFile,'Get Limbo transactions');
154 writeln(OutFile);
155 Req := Service.AllocateSRB;
156 Req.Add(isc_info_svc_limbo_trans);
157 try
158 Results := Service.Query(nil,Req);
159 WriteServiceQueryResult(Results);
160 except on E: Exception do
161 writeln(OutFile,'limbo transactions: ',E.Message);
162 end;
163 writeln(OutFile);
164 end;
165
166 procedure TTest11.BackupRestore(Service: IServiceManager; DBName: AnsiString);
167 var Req: ISRB;
168 Results: IServiceQueryResults;
169 BakFile: TFileStream;
170 QueryResultsItem: IServiceQueryResultItem;
171 ReqLength: integer;
172 SQPB: ISQPB;
173 bytesWritten: integer;
174 bytesAvailable: integer;
175 i: integer;
176 RestoreDBName: AnsiString;
177 Attachment: IAttachment;
178 DPB: IDPB;
179 begin
180 {Local Backup}
181
182 writeln(OutFile,'Local Backup');
183 Req := Service.AllocateSRB;
184 Req.Add(isc_action_svc_backup);
185 Req.Add(isc_spb_dbname).AsString := DBName;
186 Req.Add(isc_spb_bkp_file).AsString := 'stdout';
187 try
188 BakFile := TFileStream.Create(Owner.GetBackupFileName,fmCreate);
189 try
190 Service.Start(Req);
191 Req := Service.AllocateSRB;
192 Req.Add(isc_info_svc_to_eof);
193 repeat
194 bytesWritten := 0;
195 Results := Service.Query(Req);
196 QueryResultsItem := Results.Find(isc_info_svc_to_eof);
197 if QueryResultsItem <> nil then
198 bytesWritten := QueryResultsItem.CopyTo(BakFile,0);
199 until ((bytesWritten = 0) and (Results.Find(isc_info_svc_timeout) = nil))
200 or not WriteServiceQueryResult(Results);
201 writeln(OutFile,'Local Backup Complete');
202 finally
203 BakFile.Free;
204 end;
205 except on E: Exception do
206 writeln(OutFile,'Local Backup Service: ',E.Message);
207 end;
208 writeln(OutFile);
209
210 {Local Restore}
211 writeln(OutFile,'Local Restore');
212 RestoreDBName := ExtractDBName(Owner.GetNewDatabaseName);
213 i := Pos(':',RestoreDBName);
214 if i > 0 then
215 system.Delete(RestoreDBName,1,i);
216 Req := Service.AllocateSRB;
217 Req.Add(isc_action_svc_restore);
218 Req.Add(isc_spb_dbname).AsString := RestoreDBName;
219 Req.Add(isc_spb_verbose);
220 Req.Add(isc_spb_bkp_file).AsString := 'stdin';
221 Req.Add(isc_spb_res_access_mode).AsByte := isc_spb_prp_am_readwrite;
222 Req.Add(isc_spb_options).SetAsInteger(isc_spb_res_create);
223 BakFile := TFileStream.Create(Owner.GetBackupFileName,fmOpenRead);
224 try
225 bytesAvailable := BakFile.Size;
226 try
227 Service.Start(Req);
228 ReqLength := 0;
229 repeat
230 SQPB := Service.AllocateSQPB;
231 if ReqLength > 0 then
232 bytesWritten := SQPB.Add(isc_info_svc_line).CopyFrom(BakFile,ReqLength);
233 bytesAvailable := bytesAvailable - bytesWritten;
234 Req := Service.AllocateSRB;
235 Req.Add(isc_info_svc_stdin);
236 Req.Add(isc_info_svc_line);
237 Results := Service.Query(SQPB,Req);
238 QueryResultsItem := Results.Find(isc_info_svc_stdin);
239 if QueryResultsItem <> nil then
240 ReqLength := QueryResultsItem.AsInteger;
241 WriteServiceQueryResult(Results);
242 until (ReqLength = 0) ;
243 writeln(OutFile,'Local Restore Complete');
244 except on E: Exception do
245 writeln(OutFile,'Local Restore Service: ',E.Message);
246 end;
247 finally
248 BakFile.free;
249 end;
250 writeln(OutFile);
251 writeln(OutFile,'Open Database Check');
252 DPB := FirebirdAPI.AllocateDPB;
253 DPB.Add(isc_dpb_user_name).AsString := Owner.GetUserName;
254 DPB.Add(isc_dpb_password).AsString := Owner.GetPassword;
255 Attachment := FirebirdAPI.OpenDatabase(Owner.GetNewDatabaseName,DPB);
256 if Attachment <> nil then
257 writeln(OutFile,'Database OK');
258 Attachment.DropDatabase;
259 writeln(OutFile,'Database Dropped');
260 end;
261
262 function TTest11.TestTitle: AnsiString;
263 begin
264 Result := 'Test 11: Services API';
265 end;
266
267 procedure TTest11.RunTest(CharSet: AnsiString; SQLDialect: integer);
268 var SPB: ISPB;
269 Service: IServiceManager;
270 ServerName: AnsiString;
271 DBName: AnsiString;
272 begin
273 if not FirebirdAPI.HasServiceAPI then Exit;
274
275 DBName := ExtractDBName(Owner.GetEmployeeDatabaseName);
276 ServerName := Owner.Server;
277
278 SPB := FirebirdAPI.AllocateSPB;
279 SPB.Add(isc_spb_user_name).setAsString(Owner.GetUserName);
280 SPB.Add(isc_spb_password).setAsString(Owner.GetPassword);
281 Service := FirebirdAPI.GetServiceManager(ServerName,TCP,SPB);
282
283 GetStatistics(Service,DBName);
284 BackupRestore(Service,DBName);
285
286 end;
287
288 initialization
289 RegisterTest(TTest11);
290
291 end.
292