1 |
tony |
315 |
unit Test12; |
2 |
|
|
|
3 |
|
|
{$mode objfpc}{$H+} |
4 |
|
|
|
5 |
|
|
{Test 12 Test use of Services Connection} |
6 |
|
|
|
7 |
|
|
{ Tests out the Services Interface for functions: |
8 |
|
|
1. Show Server Properties |
9 |
|
|
2. Show Database Stats |
10 |
|
|
3. Show Server Log |
11 |
|
|
4. Validate Database |
12 |
|
|
5. Database Sweep |
13 |
|
|
6. User List Handling (Show users, create user, Edit user, Delete User) |
14 |
|
|
7. Shutdown DB and bring back online |
15 |
|
|
8. Client side backup/restore |
16 |
|
|
9. Server Side Backup/restore |
17 |
|
|
10. Limbo Transaction Resolution. |
18 |
|
|
11. Show Database Properties |
19 |
|
|
12. Update Database Properties |
20 |
|
|
13. Create, Remove and Activate a Shadow File. |
21 |
|
|
} |
22 |
|
|
|
23 |
|
|
interface |
24 |
|
|
|
25 |
|
|
uses |
26 |
|
|
Classes, SysUtils, TestApplication, IBXTestBase, DB, IB, IBXServices, |
27 |
|
|
IBDatabaseInfo, IBQuery, IBSQL, IBDatabase; |
28 |
|
|
|
29 |
|
|
const |
30 |
|
|
aTestID = '12'; |
31 |
|
|
aTestTitle = 'Test use of Services Connection'; |
32 |
|
|
|
33 |
|
|
type |
34 |
|
|
|
35 |
|
|
{ TTest12 } |
36 |
|
|
|
37 |
|
|
TTest12 = class(TIBXTestBase) |
38 |
|
|
private |
39 |
|
|
FIBConfigService: TIBXConfigService; |
40 |
|
|
FIBXServicesConnection: TIBXServicesConnection; |
41 |
|
|
FIBLogService: TIBXLogService; |
42 |
|
|
FIBOnlineValidationService: TIBXOnlineValidationService; |
43 |
|
|
FIBServerProperties: TIBXServerProperties; |
44 |
|
|
FIBStatisticalService: TIBXStatisticalService; |
45 |
|
|
FIBValidationService: TIBXValidationService; |
46 |
|
|
FIBXSecurityService: TIBXSecurityService; |
47 |
|
|
FUserList: TIBXServicesUserList; |
48 |
|
|
FBackupService: TIBXClientSideBackupService; |
49 |
|
|
FRestoreService: TIBXClientSideRestoreService; |
50 |
|
|
FSSBackupService: TIBXServerSideBackupService; |
51 |
|
|
FSSRestoreService: TIBXServerSideRestoreService; |
52 |
|
|
FLimboTransactionsList: TIBXServicesLimboTransactionsList; |
53 |
|
|
FLimboTransResolutionService: TIBXLimboTransactionResolutionService; |
54 |
|
|
FIBDatabaseInfo: TIBDatabaseInfo; |
55 |
|
|
FIBShadowDatabase: TIBDatabase; |
56 |
|
|
function IsDatabaseOnline (DBName: AnsiString): boolean; |
57 |
|
|
function IsShadowDatabase(DBName: AnsiString): boolean; |
58 |
|
|
procedure ShowServerProperties; |
59 |
|
|
procedure ShowStatistics; |
60 |
|
|
procedure ShowServerLog; |
61 |
|
|
procedure ValidateDatabase; |
62 |
|
|
procedure UserListHandling; |
63 |
|
|
procedure DBUpDown; |
64 |
|
|
procedure DatabaseSweepDB; |
65 |
|
|
procedure BackupRestore; |
66 |
|
|
procedure SSBackupRestore; |
67 |
|
|
procedure LimboTransactionResolution; |
68 |
|
|
procedure DatabasePropertiesTests; |
69 |
|
|
procedure ShowDatabaseProperties; |
70 |
|
|
procedure CreateShadow; |
71 |
|
|
procedure RemoveShadow; |
72 |
|
|
procedure ShowShadowFiles; |
73 |
|
|
procedure ActivateShadow; |
74 |
|
|
protected |
75 |
|
|
procedure CreateObjects(Application: TTestApplication); override; |
76 |
|
|
function GetTestID: AnsiString; override; |
77 |
|
|
function GetTestTitle: AnsiString; override; |
78 |
|
|
procedure InitTest; override; |
79 |
|
|
procedure ProcessResults; override; |
80 |
|
|
public |
81 |
|
|
destructor Destroy; override; |
82 |
|
|
procedure RunTest(CharSet: AnsiString; SQLDialect: integer); override; |
83 |
|
|
end; |
84 |
|
|
|
85 |
|
|
|
86 |
|
|
implementation |
87 |
|
|
|
88 |
|
|
uses IBUtils; |
89 |
|
|
|
90 |
|
|
const First2 = 2; |
91 |
|
|
|
92 |
|
|
{ TTest12 } |
93 |
|
|
|
94 |
|
|
function TTest12.IsDatabaseOnline(DBName: AnsiString): boolean; |
95 |
|
|
var Lines: TStringList; |
96 |
|
|
i: integer; |
97 |
|
|
line: string; |
98 |
|
|
begin |
99 |
|
|
{Scan header page to see if database is online } |
100 |
|
|
Result := true; |
101 |
|
|
with TIBXStatisticalService.Create(nil) do |
102 |
|
|
try |
103 |
|
|
ServicesConnection := FIBXServicesConnection; |
104 |
|
|
DatabaseName := DBName; |
105 |
|
|
Options := [HeaderPages]; |
106 |
|
|
Lines := TStringList.Create; |
107 |
|
|
try |
108 |
|
|
Execute(Lines); |
109 |
|
|
for i := 0 to Lines.Count - 1 do |
110 |
|
|
begin |
111 |
|
|
line := Lines[i]; |
112 |
|
|
if (Pos('Attributes',Line) <> 0) and ((Pos('database shutdown',Line) <> 0) |
113 |
|
|
or (Pos('multi-user maintenance',Line) <> 0)) then |
114 |
|
|
begin |
115 |
|
|
Result := false; |
116 |
|
|
break; |
117 |
|
|
end; |
118 |
|
|
|
119 |
|
|
end; |
120 |
|
|
finally |
121 |
|
|
Lines.Free; |
122 |
|
|
end |
123 |
|
|
finally |
124 |
|
|
Free |
125 |
|
|
end; |
126 |
|
|
end; |
127 |
|
|
|
128 |
|
|
function TTest12.IsShadowDatabase(DBName: AnsiString): boolean; |
129 |
|
|
var Lines: TStringList; |
130 |
|
|
i: integer; |
131 |
|
|
line: string; |
132 |
|
|
begin |
133 |
|
|
{Scan header page to see if database is a shadow} |
134 |
|
|
Result := false; |
135 |
|
|
with TIBXStatisticalService.Create(nil) do |
136 |
|
|
try |
137 |
|
|
ServicesConnection := FIBXServicesConnection; |
138 |
|
|
DatabaseName := DBName; |
139 |
|
|
Options := [HeaderPages]; |
140 |
|
|
Lines := TStringList.Create; |
141 |
|
|
try |
142 |
|
|
Execute(Lines); |
143 |
|
|
for i := 0 to Lines.Count - 1 do |
144 |
|
|
begin |
145 |
|
|
line := Lines[i]; |
146 |
|
|
if (Pos('Attributes',Line) <> 0) and (Pos('shadow',Line) <> 0) then |
147 |
|
|
begin |
148 |
|
|
Result := true; |
149 |
|
|
break; |
150 |
|
|
end; |
151 |
|
|
|
152 |
|
|
end; |
153 |
|
|
finally |
154 |
|
|
Lines.Free; |
155 |
|
|
end |
156 |
|
|
finally |
157 |
|
|
Free |
158 |
|
|
end; |
159 |
|
|
end; |
160 |
|
|
|
161 |
|
|
procedure TTest12.ShowServerProperties; |
162 |
|
|
var i: integer; |
163 |
|
|
begin |
164 |
|
|
with FIBServerProperties, FIBXServicesConnection do |
165 |
|
|
begin |
166 |
|
|
writeln(OutFile,'Firebird Library PathName = ' + FirebirdAPI.GetFBLibrary.GetLibraryFilePath); |
167 |
|
|
writeln(OutFile,'Connect String = ',FIBXServicesConnection.ConnectString); |
168 |
|
|
writeln(OutFile,'Server Version = ' + VersionInfo.ServerVersion); |
169 |
|
|
writeln(OutFile,'Server Implementation = ' + VersionInfo.ServerImplementation); |
170 |
|
|
writeln(OutFile,'Service Version = ' + IntToStr(VersionInfo.ServiceVersion)); |
171 |
|
|
writeln(OutFile,Format('Firebird Release = %d.%d.%d (Build no. %d)',[ServerVersionNo[1], |
172 |
|
|
ServerVersionNo[2], |
173 |
|
|
ServerVersionNo[3], |
174 |
|
|
ServerVersionNo[4]])); |
175 |
|
|
writeln(OutFile,'No. of attachments = ' + IntToStr(DatabaseInfo.NoOfAttachments)); |
176 |
|
|
writeln(OutFile,'No. of databases = ' + IntToStr(DatabaseInfo.NoOfDatabases)); |
177 |
|
|
for i := 0 to DatabaseInfo.NoOfDatabases - 1 do |
178 |
|
|
writeln(OutFile,'DB Name = ' + DatabaseInfo.DbName[i]); |
179 |
|
|
writeln(OutFile,'Base Location = ' + ConfigParams.BaseLocation); |
180 |
|
|
writeln(OutFile,'Lock File Location = ' + ConfigParams.LockFileLocation); |
181 |
|
|
writeln(OutFile,'Security Database Location = ' + ConfigParams.SecurityDatabaseLocation); |
182 |
|
|
writeln(OutFile,'Message File Location = ' + ConfigParams.MessageFileLocation); |
183 |
|
|
for i := Low(ConfigParams.ConfigFileParams) to High(ConfigParams.ConfigFileParams) do |
184 |
|
|
writeln(OutFile,ConfigParams.ConfigFileParams[i]); |
185 |
|
|
for i := Low(ConfigParams.ConfigFileData.ConfigFileKey) to High(ConfigParams.ConfigFileData.ConfigFileKey) do |
186 |
|
|
writeln(OutFile,Format('%d=%s',[ConfigParams.ConfigFileData.ConfigFileKey[i],ConfigParams.ConfigFileData.ConfigFileValue[i]])); |
187 |
|
|
end; |
188 |
|
|
end; |
189 |
|
|
|
190 |
|
|
procedure TTest12.ShowStatistics; |
191 |
|
|
var S: TStringList; |
192 |
|
|
begin |
193 |
|
|
writeln(OutFile,'Database Statistics for ' + FIBStatisticalService.DatabaseName); |
194 |
|
|
S := TStringList.Create; |
195 |
|
|
try |
196 |
|
|
FIBStatisticalService.Execute(S); |
197 |
|
|
WriteStrings(S); |
198 |
|
|
finally |
199 |
|
|
S.Free; |
200 |
|
|
end; |
201 |
|
|
end; |
202 |
|
|
|
203 |
|
|
procedure TTest12.ShowServerLog; |
204 |
|
|
var S: TStringList; |
205 |
|
|
begin |
206 |
|
|
writeln(OutFile,'Server Log'); |
207 |
|
|
S := TStringList.Create; |
208 |
|
|
try |
209 |
|
|
FIBLogService.Execute(S); |
210 |
|
|
WriteStrings(S,First2); |
211 |
|
|
finally |
212 |
|
|
S.Free; |
213 |
|
|
end; |
214 |
|
|
end; |
215 |
|
|
|
216 |
|
|
procedure TTest12.ValidateDatabase; |
217 |
|
|
var S: TStringList; |
218 |
|
|
begin |
219 |
|
|
S := TStringList.Create; |
220 |
|
|
try |
221 |
|
|
writeln(OutFile,'Online Validation'); |
222 |
|
|
FIBOnlineValidationService.Execute(S); |
223 |
|
|
WriteStrings(S); |
224 |
|
|
S.Clear; |
225 |
|
|
writeln(OutFile,'Normal Validation'); |
226 |
|
|
FIBConfigService.ShutDownDatabase(Forced,0); |
227 |
|
|
try |
228 |
|
|
FIBValidationService.Options := [ValidateFull]; |
229 |
|
|
FIBValidationService.Execute(S); |
230 |
|
|
finally |
231 |
|
|
FIBConfigService.BringDatabaseOnline; |
232 |
|
|
end; |
233 |
|
|
WriteStrings(S); |
234 |
|
|
finally |
235 |
|
|
S.Free; |
236 |
|
|
end; |
237 |
|
|
writeln(OutFile,'Validation Completed'); |
238 |
|
|
end; |
239 |
|
|
|
240 |
|
|
procedure TTest12.UserListHandling; |
241 |
|
|
begin |
242 |
|
|
writeln(Outfile,' Current User List'); |
243 |
|
|
FUserList.Active := true; |
244 |
|
|
PrintDataSet(FUserList); |
245 |
|
|
writeln(Outfile,'Add user'); |
246 |
|
|
with FUserList do |
247 |
|
|
begin |
248 |
|
|
Append; |
249 |
|
|
FieldByName('SEC$USER_NAME').AsString := 'Test12Tester'; |
250 |
|
|
FieldByName('SEC$PASSWORD').AsString := 'LetMeIn'; |
251 |
|
|
FieldByName('SEC$LAST_NAME').AsString := 'Tester'; |
252 |
|
|
Post; |
253 |
|
|
end; |
254 |
|
|
writeln(Outfile,'Updated User List'); |
255 |
|
|
PrintDataSet(FUserList); |
256 |
|
|
writeln(Outfile,'Close and re-open user list'); |
257 |
|
|
FUserList.Active := false; |
258 |
|
|
FUserList.Active := true; |
259 |
|
|
PrintDataSet(FUserList); |
260 |
|
|
writeln(Outfile,'Modify the new user'); |
261 |
|
|
if FUserList.Locate('SEC$USER_NAME','Test12Tester',[loCaseInsensitive]) then |
262 |
|
|
with FUserList do |
263 |
|
|
begin |
264 |
|
|
Edit; |
265 |
|
|
FieldByName('SEC$FIRST_NAME').AsString := 'The'; |
266 |
|
|
Post; |
267 |
|
|
PrintDataSet(FUserList); |
268 |
|
|
writeln(Outfile,'Close and re-open user list'); |
269 |
|
|
Active := false; |
270 |
|
|
Active := true; |
271 |
|
|
PrintDataSet(FUserList); |
272 |
|
|
end |
273 |
|
|
else |
274 |
|
|
writeln(Outfile,'Added user not found'); |
275 |
|
|
writeln(Outfile,'Now delete the new user'); |
276 |
|
|
if FUserList.Locate('SEC$USER_NAME','Test12Tester',[loCaseInsensitive]) then |
277 |
|
|
FUserList.Delete; |
278 |
|
|
FUserList.Active := false; |
279 |
|
|
FUserList.Active := true; |
280 |
|
|
writeln(Outfile,'Updated User List'); |
281 |
|
|
PrintDataSet(FUserList); |
282 |
|
|
FUserList.Active := false; |
283 |
|
|
end; |
284 |
|
|
|
285 |
|
|
procedure TTest12.DBUpDown; |
286 |
|
|
begin |
287 |
|
|
writeln(OutFile,'Employee Database is Online = ',IsDatabaseOnline(FIBConfigService.DatabaseName)); |
288 |
|
|
FIBConfigService.ShutDownDatabase(Forced,0); |
289 |
|
|
writeln(OutFile,'Employee Database is Online = ',IsDatabaseOnline(FIBConfigService.DatabaseName)); |
290 |
|
|
FIBConfigService.BringDatabaseOnline; |
291 |
|
|
writeln(OutFile,'Employee Database is Online = ',IsDatabaseOnline(FIBConfigService.DatabaseName)); |
292 |
|
|
end; |
293 |
|
|
|
294 |
|
|
procedure TTest12.DatabaseSweepDB; |
295 |
|
|
var S: TStringList; |
296 |
|
|
begin |
297 |
|
|
writeln(OutFile,'Database Sweep'); |
298 |
|
|
FIBValidationService.Options := [SweepDB]; |
299 |
|
|
S := TStringList.Create; |
300 |
|
|
try |
301 |
|
|
FIBValidationService.Execute(S); |
302 |
|
|
WriteStrings(S); |
303 |
|
|
finally |
304 |
|
|
S.Free; |
305 |
|
|
end; |
306 |
|
|
writeln(OutFile,'Database Swept'); |
307 |
|
|
end; |
308 |
|
|
|
309 |
|
|
procedure TTest12.BackupRestore; |
310 |
|
|
var BackupCount: integer; |
311 |
|
|
S: TStringList; |
312 |
|
|
begin |
313 |
|
|
writeln(OutFile); |
314 |
|
|
writeln(OutFile,'Starting Backup'); |
315 |
|
|
FBackupService.BackupToFile(Owner.GetBackupFileName,BackupCount); |
316 |
|
|
writeln(OutFile,Format('Backup Completed - File Size = %d bytes',[BackupCount])); |
317 |
|
|
writeln(OutFile,'Restore Started'); |
318 |
|
|
S := TStringList.Create; |
319 |
|
|
try |
320 |
|
|
FRestoreService.RestoreFromFile(Owner.GetBackupFileName,S); |
321 |
|
|
WriteStrings(S); |
322 |
|
|
finally |
323 |
|
|
S.Free; |
324 |
|
|
end; |
325 |
|
|
writeln(Outfile,'Restore Completed'); |
326 |
|
|
DeleteFile(Owner.GetBackupFileName); |
327 |
|
|
end; |
328 |
|
|
|
329 |
|
|
procedure TTest12.SSBackupRestore; |
330 |
|
|
var S: TStringList; |
331 |
|
|
ServerDatabase: TIBDatabase; |
332 |
|
|
ServerTransaction: TIBTransaction; |
333 |
|
|
ServerQuery: TIBQuery; |
334 |
|
|
begin |
335 |
|
|
writeln(OutFile); |
336 |
|
|
writeln(OutFile,'Starting Server Side Backup'); |
337 |
|
|
S := TStringList.Create; |
338 |
|
|
try |
339 |
|
|
FSSBackupService.BackupFiles.Add(GetSSBackupFile); |
340 |
|
|
FSSBackupService.Verbose := true; |
341 |
|
|
FSSBackupService.Execute(S); |
342 |
|
|
WriteStrings(S); |
343 |
|
|
writeln(OutFile,'Backup Completed'); |
344 |
|
|
writeln(OutFile,'Restore Started'); |
345 |
|
|
FSSRestoreService.BackupFiles.Assign(FSSBackupService.BackupFiles); |
346 |
|
|
FSSRestoreService.Execute(S); |
347 |
|
|
WriteStrings(S); |
348 |
|
|
finally |
349 |
|
|
S.Free; |
350 |
|
|
end; |
351 |
|
|
writeln(Outfile,'Restore Completed'); |
352 |
|
|
ServerDatabase := TIBDatabase.Create(Owner); |
353 |
|
|
ServerTransaction := TIBTransaction.Create(Owner); |
354 |
|
|
ServerQuery := TIBQuery.Create(Owner); |
355 |
|
|
try |
356 |
|
|
with FIBXServicesConnection do |
357 |
|
|
ServerDatabase.DatabaseName := MakeConnectString(ServerName,FSSRestoreService.DatabaseFiles[0],Protocol,PortNo); |
358 |
|
|
ServerDatabase.FirebirdLibraryPathName := Owner.ClientLibraryPath; |
359 |
|
|
ServerDatabase.LoginPrompt := false; |
360 |
|
|
ServerDatabase.Params.Assign(IBDatabase.Params); |
361 |
|
|
ServerTransaction.DefaultDatabase := ServerDatabase; |
362 |
|
|
ServerTransaction.Params.Assign(IBTransaction.Params); |
363 |
|
|
ServerDatabase.DefaultTransaction := ServerTransaction; |
364 |
|
|
ServerQuery.Database := ServerDatabase; |
365 |
|
|
ServerQuery.SQL.Text := 'Select * From EMPLOYEE Order by EMP_NO'; |
366 |
|
|
ServerDatabase.Connected := true; |
367 |
|
|
try |
368 |
|
|
ServerTransaction.Active := true; |
369 |
|
|
ServerQuery.Active := true; |
370 |
|
|
writeln(OutFile,'Show the EMPLOYEE Table from the restored database'); |
371 |
|
|
PrintDataset(ServerQuery); |
372 |
|
|
finally |
373 |
|
|
ServerDatabase.DropDatabase; |
374 |
|
|
end; |
375 |
|
|
finally |
376 |
|
|
ServerQuery.Free; |
377 |
|
|
ServerTransaction.Free; |
378 |
|
|
ServerDatabase.Free; |
379 |
|
|
end; |
380 |
|
|
end; |
381 |
|
|
|
382 |
|
|
procedure TTest12.LimboTransactionResolution; |
383 |
|
|
var S: TStrings; |
384 |
|
|
begin |
385 |
|
|
writeln(Outfile,'Show Limbo Transactions'); |
386 |
|
|
S := TStringList.Create; |
387 |
|
|
try |
388 |
|
|
FLimboTransactionsList.Active := true; |
389 |
|
|
PrintDataSet(FLimboTransactionsList); |
390 |
|
|
writeln(Outfile,'Call Fix Limbo transactions'); |
391 |
|
|
FLimboTransactionsList.FixErrors(CommitGlobal,S); |
392 |
|
|
WriteStrings(S); |
393 |
|
|
finally |
394 |
|
|
S.Free; |
395 |
|
|
end; |
396 |
|
|
end; |
397 |
|
|
|
398 |
|
|
procedure TTest12.DatabasePropertiesTests; |
399 |
|
|
begin |
400 |
|
|
writeln(Outfile,'Update properties for ',IBDatabase.DatabaseName); |
401 |
|
|
IBDatabase.Connected := false; |
402 |
|
|
with FIBConfigService do |
403 |
|
|
begin |
404 |
|
|
SetNoLinger; |
405 |
|
|
SetSweepInterval(10000); |
406 |
|
|
SetDBSqlDialect(1); |
407 |
|
|
SetPageBuffers(1024); |
408 |
|
|
SetAsyncMode(true); |
409 |
|
|
SetReserveSpace(false); |
410 |
|
|
SetReadOnly(true); |
411 |
|
|
end; |
412 |
|
|
IBDatabase.Connected := true; |
413 |
|
|
ShowDatabaseProperties; |
414 |
|
|
end; |
415 |
|
|
|
416 |
|
|
procedure TTest12.ShowDatabaseProperties; |
417 |
|
|
var Linger, |
418 |
|
|
ForcedWrites, |
419 |
|
|
ReserveSpace: TField; |
420 |
|
|
begin |
421 |
|
|
with FIBDatabaseInfo do |
422 |
|
|
begin |
423 |
|
|
writeln(Outfile,'Database Properties for ',DBFileName ); |
424 |
|
|
writeln(OutFile,'ODS Minor Version = ' + IntToStr(ODSMinorVersion)); |
425 |
|
|
writeln(OutFile,'ODS Major Version = ' + IntToStr(ODSMajorVersion)); |
426 |
|
|
writeln(OutFile,'DB SQLDialect = ' + IntToStr(DBSQLDialect)); |
427 |
|
|
writeln(OutFile,'Page Size = ' + IntToStr(PageSize)); |
428 |
|
|
writeln(OutFile,'Number of Buffers = ' + IntToStr(NumBuffers)); |
429 |
|
|
writeln(OutFile,'Version = ' + Version); |
430 |
|
|
ShowBoolValue(ForcedWrites,'Forced Writes Enabled','Forced Writes Disabled'); |
431 |
|
|
writeln(OutFile,'Sweep Interval = ' + IntToStr(SweepInterval)); |
432 |
|
|
ShowBoolValue(ReadOnly,'Database is Read Only','Database is Read/Write'); |
433 |
|
|
writeln(Outfile,'Database Online = ',IsDatabaseOnline(DBFileName)); |
434 |
|
|
writeln(Outfile,'Database is Shadow = ',IsShadowDatabase(DBFileName)); |
435 |
|
|
end; |
436 |
|
|
with TIBQuery.Create(nil) do |
437 |
|
|
try |
438 |
|
|
Database := FIBDatabaseInfo.Database; |
439 |
|
|
Transaction := IBTransaction; |
440 |
|
|
Transaction.Active := true; |
441 |
|
|
SQL.Text := 'Select * From RDB$Database, MON$Database'; |
442 |
|
|
Active := true; |
443 |
|
|
Linger := FindField('RDB$LINGER'); |
444 |
|
|
if Linger <> nil then |
445 |
|
|
begin |
446 |
|
|
if Linger.IsNull then |
447 |
|
|
writeln(Outfile,'Linger = 0') |
448 |
|
|
else |
449 |
|
|
writeln(Outfile,'Linger = ',Linger.AsString); |
450 |
|
|
end |
451 |
|
|
else |
452 |
|
|
writeln(OutFile,'Linger not found'); |
453 |
|
|
ForcedWrites := FindField('MON$FORCED_WRITES'); |
454 |
|
|
if ForcedWrites <> nil then |
455 |
|
|
ShowBoolValue(ForcedWrites.AsInteger,'Database in Synchronous Mode','Database in Asynchronous Mode') |
456 |
|
|
else |
457 |
|
|
writeln(Outfile,'Sync State unknown'); |
458 |
|
|
ReserveSpace := FieldByName('MON$RESERVE_SPACE'); |
459 |
|
|
if ReserveSpace <> nil then |
460 |
|
|
writeln(Outfile,'Reserve Space = ',ReserveSpace.AsBoolean) |
461 |
|
|
else |
462 |
|
|
writeln(Outfile,'Reserve Space unknown'); |
463 |
|
|
finally |
464 |
|
|
Free |
465 |
|
|
end; |
466 |
|
|
end; |
467 |
|
|
|
468 |
|
|
procedure TTest12.CreateShadow; |
469 |
|
|
var ShadowFileName: AnsiString; |
470 |
|
|
begin |
471 |
|
|
ShadowFileName := GetTempFileName; |
472 |
|
|
with TIBSQL.Create(nil) do |
473 |
|
|
try |
474 |
|
|
Database := IBDatabase; |
475 |
|
|
Transaction := IBTransaction; |
476 |
|
|
ReadWriteTransaction; |
477 |
|
|
SQL.Text := 'Create Shadow 1 AUTO ''' + ShadowFileName + ''''; |
478 |
|
|
Transaction.Active := true; |
479 |
|
|
ExecQuery; |
480 |
|
|
Transaction.Commit; |
481 |
|
|
finally |
482 |
|
|
Free |
483 |
|
|
end; |
484 |
|
|
FIBShadowDatabase.DatabaseName := MakeConnectString('',ShadowFileName,inet); |
485 |
|
|
end; |
486 |
|
|
|
487 |
|
|
procedure TTest12.RemoveShadow; |
488 |
|
|
begin |
489 |
|
|
with TIBSQL.Create(nil) do |
490 |
|
|
try |
491 |
|
|
Database := IBDatabase; |
492 |
|
|
Transaction := IBTransaction; |
493 |
|
|
ReadWriteTransaction; |
494 |
|
|
SQL.Text := 'Drop Shadow 1 PRESERVE FILE'; |
495 |
|
|
Transaction.Active := true; |
496 |
|
|
ExecQuery; |
497 |
|
|
Transaction.Commit; |
498 |
|
|
finally |
499 |
|
|
Free |
500 |
|
|
end; |
501 |
|
|
end; |
502 |
|
|
|
503 |
|
|
procedure TTest12.ShowShadowFiles; |
504 |
|
|
var Qry: TIBQuery; |
505 |
|
|
begin |
506 |
|
|
Qry := TIBQuery.Create(nil); |
507 |
|
|
with Qry do |
508 |
|
|
try |
509 |
|
|
Database := IBDatabase; |
510 |
|
|
Transaction := IBTransaction; |
511 |
|
|
SQl.Text := 'Select * From RDB$Files Where RDB$Shadow_Number <> 0 '+ |
512 |
|
|
'Order by RDB$Shadow_Number, RDB$FILE_SEQUENCE'; |
513 |
|
|
Transaction.Active := true; |
514 |
|
|
Active := true; |
515 |
|
|
writeln(Outfile,'Shadow Files'); |
516 |
|
|
PrintDataSet(Qry); |
517 |
|
|
Transaction.Commit; |
518 |
|
|
finally |
519 |
|
|
Free |
520 |
|
|
end; |
521 |
|
|
end; |
522 |
|
|
|
523 |
|
|
procedure TTest12.ActivateShadow; |
524 |
|
|
begin |
525 |
|
|
FIBConfigService.DatabaseName := FIBShadowDatabase.DatabaseName; |
526 |
|
|
writeln(Outfile,'Activating Shadow'); |
527 |
|
|
FIBConfigService.ActivateShadow; |
528 |
|
|
end; |
529 |
|
|
|
530 |
|
|
procedure TTest12.CreateObjects(Application: TTestApplication); |
531 |
|
|
begin |
532 |
|
|
inherited CreateObjects(Application); |
533 |
|
|
FIBXServicesConnection := TIBXServicesConnection.Create(Application); |
534 |
|
|
FIBConfigService := TIBXConfigService.Create(Application); |
535 |
|
|
FIBConfigService.ServicesConnection := FIBXServicesConnection; |
536 |
|
|
FIBLogService := TIBXLogService.Create(Application); |
537 |
|
|
FIBLogService.ServicesConnection := FIBXServicesConnection; |
538 |
|
|
FIBOnlineValidationService := TIBXOnlineValidationService.Create(Application); |
539 |
|
|
FIBOnlineValidationService.ServicesConnection := FIBXServicesConnection; |
540 |
|
|
FIBServerProperties := TIBXServerProperties.Create(Application); |
541 |
|
|
FIBServerProperties.ServicesConnection := FIBXServicesConnection; |
542 |
|
|
FIBStatisticalService := TIBXStatisticalService.Create(Application); |
543 |
|
|
FIBStatisticalService.ServicesConnection := FIBXServicesConnection; |
544 |
|
|
FIBValidationService := TIBXValidationService.Create(Application); |
545 |
|
|
FIBValidationService.ServicesConnection := FIBXServicesConnection; |
546 |
|
|
FIBXSecurityService := TIBXSecurityService.Create(Application); |
547 |
|
|
FIBXSecurityService.ServicesConnection := FIBXServicesConnection; |
548 |
|
|
FUserList := TIBXServicesUserList.Create(Application); |
549 |
|
|
FUserList.Source := FIBXSecurityService; |
550 |
|
|
FBackupService := TIBXClientSideBackupService.Create(Application); |
551 |
|
|
FBackupService.ServicesConnection := FIBXServicesConnection; |
552 |
|
|
FRestoreService := TIBXClientSideRestoreService.Create(Application); |
553 |
|
|
FRestoreService.ServicesConnection := FIBXServicesConnection; |
554 |
|
|
FSSBackupService := TIBXServerSideBackupService.Create(Application); |
555 |
|
|
FSSBackupService.ServicesConnection := FIBXServicesConnection; |
556 |
|
|
FSSRestoreService := TIBXServerSideRestoreService.Create(Application); |
557 |
|
|
FSSRestoreService.ServicesConnection := FIBXServicesConnection; |
558 |
|
|
FLimboTransResolutionService := TIBXLimboTransactionResolutionService.Create(Application); |
559 |
|
|
FLimboTransResolutionService.ServicesConnection := FIBXServicesConnection; |
560 |
|
|
FLimboTransactionsList := TIBXServicesLimboTransactionsList.Create(Application); |
561 |
|
|
FLimboTransactionsList.Source := FLimboTransResolutionService; |
562 |
|
|
FIBDatabaseInfo := TIBDatabaseInfo.Create(Application); |
563 |
|
|
FIBShadowDatabase := TIBDatabase.Create(Application); |
564 |
|
|
end; |
565 |
|
|
|
566 |
|
|
function TTest12.GetTestID: AnsiString; |
567 |
|
|
begin |
568 |
|
|
Result := aTestID; |
569 |
|
|
end; |
570 |
|
|
|
571 |
|
|
function TTest12.GetTestTitle: AnsiString; |
572 |
|
|
begin |
573 |
|
|
Result := aTestTitle; |
574 |
|
|
end; |
575 |
|
|
|
576 |
|
|
procedure TTest12.InitTest; |
577 |
|
|
begin |
578 |
|
|
IBDatabase.DatabaseName := Owner.GetNewDatabaseName; |
579 |
|
|
IBQuery.SQL.Text := 'Select * From EMPLOYEE Order by EMP_NO'; |
580 |
|
|
FIBXServicesConnection.ServerName := Owner.Server; |
581 |
|
|
FIBXServicesConnection.Protocol := TCP; |
582 |
|
|
FIBXServicesConnection.PortNo := Owner.PortNo; |
583 |
|
|
FIBXServicesConnection.Params.Values['user_name'] := Owner.GetUserName; |
584 |
|
|
FIBXServicesConnection.Params.Values['password'] := Owner.GetPassword; |
585 |
|
|
FIBXServicesConnection.FirebirdLibraryPathName := Owner.ClientLibraryPath; |
586 |
|
|
FIBStatisticalService.Options := [DataPages]; |
587 |
|
|
FIBStatisticalService.DatabaseName := ExtractDBName(Owner.GetEmployeeDatabaseName); |
588 |
|
|
FIBOnlineValidationService.DatabaseName := ExtractDBName(Owner.GetEmployeeDatabaseName); |
589 |
|
|
FIBValidationService.DatabaseName := ExtractDBName(Owner.GetEmployeeDatabaseName); |
590 |
|
|
FIBConfigService.DatabaseName := ExtractDBName(Owner.GetEmployeeDatabaseName); |
591 |
|
|
FBackupService.DatabaseName := ExtractDBName(Owner.GetEmployeeDatabaseName); |
592 |
|
|
FBackupService.Options := [IgnoreLimbo]; |
593 |
|
|
FRestoreService.DatabaseFiles.Add(ExtractDBName(Owner.GetNewDatabaseName)); |
594 |
|
|
FRestoreService.StatisticsRequested := [bsTotalTime]; |
595 |
|
|
FSSBackupService.DatabaseName := ExtractDBName(Owner.GetEmployeeDatabaseName); |
596 |
|
|
FSSBackupService.Options := [IgnoreLimbo]; |
597 |
|
|
FSSRestoreService.DatabaseFiles.Add(ExtractDBName(Owner.GetNewDatabaseName)); |
598 |
|
|
FSSRestoreService.StatisticsRequested := [bsTotalTime]; |
599 |
|
|
FLimboTransResolutionService.DatabaseName := ExtractDBName(Owner.GetEmployeeDatabaseName); |
600 |
|
|
FIBDatabaseInfo.Database := IBDatabase; |
601 |
|
|
ReadOnlyTransaction; |
602 |
|
|
FIBShadowDatabase.Params.Assign(IBDatabase.Params); |
603 |
|
|
end; |
604 |
|
|
|
605 |
|
|
procedure TTest12.ProcessResults; |
606 |
|
|
begin |
607 |
|
|
inherited ProcessResults; |
608 |
|
|
FIBShadowDatabase.Connected := false; |
609 |
|
|
FIBXServicesConnection.Connected := false; |
610 |
|
|
end; |
611 |
|
|
|
612 |
|
|
destructor TTest12.Destroy; |
613 |
|
|
begin |
614 |
|
|
if FIBShadowDatabase <> nil then |
615 |
|
|
FIBShadowDatabase.Connected := false; |
616 |
|
|
if FIBXServicesConnection <> nil then |
617 |
|
|
FIBXServicesConnection.Connected := false; |
618 |
|
|
inherited Destroy; |
619 |
|
|
end; |
620 |
|
|
|
621 |
|
|
procedure TTest12.RunTest(CharSet: AnsiString; SQLDialect: integer); |
622 |
|
|
begin |
623 |
|
|
FIBXServicesConnection.Connected := true; |
624 |
|
|
try |
625 |
|
|
ShowServerProperties; |
626 |
|
|
ShowStatistics; |
627 |
|
|
ShowServerLog; |
628 |
|
|
ValidateDatabase; |
629 |
|
|
DatabaseSweepDB; |
630 |
|
|
UserListHandling; |
631 |
|
|
DBUpDown; |
632 |
|
|
BackupRestore; |
633 |
|
|
writeln(OutFile,'Show the EMPLOYEE Table from the restored database'); |
634 |
|
|
IBDatabase.Connected := true; |
635 |
|
|
try |
636 |
|
|
IBTransaction.Active := true; |
637 |
|
|
IBQuery.Active := true; |
638 |
|
|
PrintDataset(IBQuery); |
639 |
|
|
finally |
640 |
|
|
IBDatabase.DropDatabase; |
641 |
|
|
end; |
642 |
|
|
SSBackupRestore; |
643 |
|
|
exit; |
644 |
|
|
LimboTransactionResolution; |
645 |
|
|
IBDatabase.DatabaseName := Owner.GetNewDatabaseName; |
646 |
|
|
FIBConfigService.DatabaseName := IBDatabase.DatabaseName; |
647 |
|
|
FIBXServicesConnection.Connected := false; |
648 |
|
|
writeln(Outfile,'Creating an empty database ',IBDatabase.DatabaseName); |
649 |
|
|
IBDatabase.CreateDatabase; |
650 |
|
|
try |
651 |
|
|
FIBXServicesConnection.Connected := true; |
652 |
|
|
ShowDatabaseProperties; |
653 |
|
|
DatabasePropertiesTests; |
654 |
|
|
finally |
655 |
|
|
IBDatabase.DropDatabase; |
656 |
|
|
end; |
657 |
|
|
writeln(Outfile,'Create and activate a shadow file'); |
658 |
|
|
IBDatabase.CreateDatabase; |
659 |
|
|
try |
660 |
|
|
CreateShadow; |
661 |
|
|
ShowShadowFiles; |
662 |
|
|
RemoveShadow; |
663 |
|
|
IBDatabase.Connected := false; |
664 |
|
|
writeln(Outfile,FIBShadowDatabase.DatabaseName,' Is Shadow Database = ',IsShadowDatabase(FIBShadowDatabase.DatabaseName)); |
665 |
|
|
ActivateShadow; |
666 |
|
|
writeln(Outfile,FIBShadowDatabase.DatabaseName,' Is Shadow Database = ',IsShadowDatabase(FIBShadowDatabase.DatabaseName)); |
667 |
|
|
finally |
668 |
|
|
IBDatabase.DropDatabase; |
669 |
|
|
FIBShadowDatabase.DropDatabase; |
670 |
|
|
end; |
671 |
|
|
finally |
672 |
|
|
FIBXServicesConnection.Connected := false; |
673 |
|
|
end; |
674 |
|
|
end; |
675 |
|
|
|
676 |
|
|
initialization |
677 |
|
|
RegisterTest(TTest12); |
678 |
|
|
|
679 |
|
|
end. |
680 |
|
|
|