1 |
+ |
(* |
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 |
|
unit Test17; |
28 |
|
|
29 |
|
{$mode objfpc}{$H+} |
54 |
|
private |
55 |
|
FIBDataSet1: TIBDataSet; |
56 |
|
FIBDataSet2: TIBDataSet; |
57 |
+ |
F2KeyDataset: TIBDataset; |
58 |
|
procedure HandleDeleteReturning(Sender: TObject; QryResults: IResults); |
59 |
|
procedure HandleBeforeOpen(DataSet: TDataSet); |
60 |
|
procedure HandleAfterOpen(DataSet: TDataSet); |
241 |
|
BeforeRefresh := @HandleBeforeRefresh; |
242 |
|
AfterRefresh := @HandleAfterRefresh; |
243 |
|
end; |
244 |
+ |
F2KeyDataset := TIBDataSet.Create(Application); |
245 |
+ |
with F2KeyDataset do |
246 |
+ |
begin |
247 |
+ |
Database := IBDatabase; |
248 |
+ |
Transaction := IBTransaction; |
249 |
+ |
SelectSQL.Text := 'Select Key1, Key2 From IBXTest2'; |
250 |
+ |
InsertSQL.Text := 'Insert into IBXTest2(Key1,Key2) Values(:Key1,:Key2)'; |
251 |
+ |
RefreshSQL.Text := 'Select Key1, Key2 From IBXTest2 where Key1 = :Key1 and Key2 = :Key2'; |
252 |
+ |
end; |
253 |
|
end; |
254 |
|
|
255 |
|
function TTest17.GetTestID: AnsiString; |
271 |
|
|
272 |
|
procedure TTest17.RunTest(CharSet: AnsiString; SQLDialect: integer); |
273 |
|
var lastKey: integer; |
274 |
+ |
i: integer; |
275 |
+ |
B: TBookmark; |
276 |
|
begin |
277 |
|
IBDatabase.CreateDatabase; |
278 |
|
try |
298 |
|
FieldByName('PlainText').AsString := 'This is the update test'; |
299 |
|
Post; |
300 |
|
PrintDataSetRow(FIBDataSet1); |
301 |
< |
writeln(OutFile,'Now delete the first row'); |
301 |
> |
writeln(Outfile,'Show whole Dataset'); |
302 |
|
PrintDataSet(FIBDataSet1); |
303 |
+ |
writeln(OutFile,'Now delete the first row'); |
304 |
|
First; |
305 |
|
Delete; |
306 |
|
PrintDataSet(FIBDataSet1); |
347 |
|
Active := true; |
348 |
|
PrintDataSet(FIBDataSet1); |
349 |
|
|
350 |
< |
{See https://bugs.freepascal.org/view.php?id=37900} |
312 |
< |
|
313 |
< |
(* IBTransaction.Rollback; |
350 |
> |
IBTransaction.Rollback; |
351 |
|
IBTransaction.Active := true; |
352 |
|
writeln(Outfile); |
353 |
|
writeln(Outfile,'Unidirectional editing'); |
364 |
|
Refresh; |
365 |
|
writeln(OutFile,'After Refresh - unidirectional'); |
366 |
|
PrintDataSetRow(FIBDataSet1); |
367 |
< |
writeln(OutFile,'Append and Update'); |
367 |
> |
writeln(OutFile,' Record Count = ',FIBDataSet1.RecordCount); |
368 |
> |
writeln(OutFile,'Insert and Update'); |
369 |
|
Insert; |
370 |
|
FieldByName('PlainText').AsString := 'This is another test - unidirectional'; |
371 |
|
Post; |
374 |
|
FieldByName('PlainText').AsString := 'This is the update test - unidirectional'; |
375 |
|
Post; |
376 |
|
PrintDataSetRow(FIBDataSet1); |
377 |
< |
writeln(OutFile,'Now delete the first row - unidirectional'); |
378 |
< |
PrintDataSet(FIBDataSet1); |
379 |
< |
First; |
377 |
> |
writeln(OutFile,'Now delete the first row - unidirectional with Record Count = ',FIBDataSet1.RecordCount); |
378 |
> |
Active := false; |
379 |
> |
Active := true; |
380 |
|
Delete; |
381 |
< |
PrintDataSet(FIBDataSet1); |
381 |
> |
writeln(OutFile,'Show Current Row'); |
382 |
> |
PrintDataSetRow(FIBDataSet1); |
383 |
> |
writeln(OutFile,' Record Count = ',FIBDataSet1.RecordCount); |
384 |
|
writeln(Outfile,'Ensure dataset saved to database'); |
385 |
|
Active := false; |
386 |
|
Active := true; |
387 |
< |
PrintDataSet(FIBDataSet1); *) |
387 |
> |
PrintDataSet(FIBDataSet1); |
388 |
|
|
389 |
|
end; |
390 |
|
writeln(Outfile,'=================================='); |
391 |
|
IBTransaction.Rollback; |
392 |
|
IBTransaction.Active := true; |
393 |
|
with FIBDataSet2 do |
394 |
< |
begin |
394 |
> |
try |
395 |
|
Active := true; |
396 |
|
writeln(OutFile,'FIBDataSet2: Simple Append'); |
397 |
|
Append; |
434 |
|
FieldByName('PlainText').AsString := 'This is a test'; |
435 |
|
Post; |
436 |
|
PrintDataSetRow(FIBDataSet2); |
437 |
< |
|
437 |
> |
except on E: Exception do |
438 |
> |
writeln(Outfile,E.Message); |
439 |
> |
end; |
440 |
> |
IBTransaction.Rollback; |
441 |
> |
IBTransaction.Active := true; |
442 |
> |
with FIBDataSet1 do |
443 |
> |
try |
444 |
> |
Unidirectional := false; |
445 |
> |
Active := true; |
446 |
> |
writeln(outfile,'----------------------------------------------'); |
447 |
> |
writeln(OutFile,'FIBDataSet1: Insert at start'); |
448 |
> |
for i := 1 to 2 do |
449 |
> |
begin |
450 |
> |
Append; |
451 |
> |
FieldByName('PlainText').AsString := 'Row ' + IntToStr(i); |
452 |
> |
Post; |
453 |
> |
end; |
454 |
> |
First; |
455 |
> |
Insert; |
456 |
> |
FieldByName('PlainText').AsString := 'This is an insert test'; |
457 |
> |
Post; |
458 |
> |
B := Bookmark; |
459 |
> |
PrintDataSet(FIBDataSet1); |
460 |
> |
writeln(outfile,'Delete inserted row'); |
461 |
> |
Bookmark := B; |
462 |
> |
Delete; |
463 |
> |
PrintDataSet(FIBDataSet1); |
464 |
> |
writeln(outfile,'Repeat'); |
465 |
> |
First; |
466 |
> |
Insert; |
467 |
> |
FieldByName('PlainText').AsString := 'This is an insert test #1'; |
468 |
> |
Post; |
469 |
> |
B := Bookmark; |
470 |
> |
PrintDataSet(FIBDataSet1); |
471 |
> |
writeln(outfile,'Delete inserted row'); |
472 |
> |
Bookmark := B; |
473 |
> |
Delete; |
474 |
> |
PrintDataSet(FIBDataSet1); |
475 |
> |
writeln(outfile,'Insert/Delete after first row'); |
476 |
> |
Next; |
477 |
> |
Insert; |
478 |
> |
FieldByName('PlainText').AsString := 'This is an insert test #2'; |
479 |
> |
Post; |
480 |
> |
B := Bookmark; |
481 |
> |
PrintDataSet(FIBDataSet1); |
482 |
> |
writeln(outfile,'Delete inserted row'); |
483 |
> |
Bookmark := B; |
484 |
> |
Delete; |
485 |
> |
PrintDataSet(FIBDataSet1); |
486 |
> |
writeln(outfile,'Insert/Delete at last row'); |
487 |
> |
Last; |
488 |
> |
Insert; |
489 |
> |
FieldByName('PlainText').AsString := 'This is an insert test #3'; |
490 |
> |
Post; |
491 |
> |
B := Bookmark; |
492 |
> |
PrintDataSet(FIBDataSet1); |
493 |
> |
writeln(outfile,'Delete inserted row'); |
494 |
> |
Bookmark := B; |
495 |
> |
Delete; |
496 |
> |
PrintDataSet(FIBDataSet1); |
497 |
> |
except on E: Exception do |
498 |
> |
writeln(Outfile,E.Message); |
499 |
|
end; |
500 |
+ |
|
501 |
+ |
writeln(outfile,'Refresh Dataset wit two primary keys'); |
502 |
+ |
with F2KeyDataset do |
503 |
+ |
try |
504 |
+ |
Transaction.Active := true; |
505 |
+ |
Active := true; |
506 |
+ |
Append; |
507 |
+ |
FieldByName('Key1').AsInteger := 1; |
508 |
+ |
FieldByName('Key2').AsInteger := 1; |
509 |
+ |
Post; |
510 |
+ |
Append; |
511 |
+ |
FieldByName('Key1').AsInteger := 1; |
512 |
+ |
FieldByName('Key2').AsInteger := 2; |
513 |
+ |
Post; |
514 |
+ |
Refresh; |
515 |
+ |
PrintDataset(F2KeyDataset); |
516 |
+ |
except on E: Exception do |
517 |
+ |
writeln(Outfile,E.Message); |
518 |
+ |
end; |
519 |
+ |
|
520 |
|
finally |
521 |
|
IBDatabase.DropDatabase; |
522 |
|
end; |