1 |
tony |
315 |
unit Test25; |
2 |
|
|
|
3 |
|
|
{$mode objfpc}{$H+} |
4 |
|
|
|
5 |
|
|
{Test 25: TIBTable Tests} |
6 |
|
|
|
7 |
|
|
{ Append, Update, Delete tests on TIBTable |
8 |
|
|
} |
9 |
|
|
|
10 |
|
|
interface |
11 |
|
|
|
12 |
|
|
uses |
13 |
|
|
Classes, SysUtils, TestApplication, IBXTestBase, DB, IB, IBTable, |
14 |
|
|
IBCustomDataSet, IBExtract, IBXScript; |
15 |
|
|
|
16 |
|
|
const |
17 |
|
|
aTestID = '25'; |
18 |
|
|
aTestTitle = 'TIBTable Tests'; |
19 |
|
|
|
20 |
|
|
type |
21 |
|
|
|
22 |
|
|
{ TTest25 } |
23 |
|
|
|
24 |
|
|
TTest25 = class(TIBXTestBase) |
25 |
|
|
private |
26 |
|
|
FIBTable: TIBTable; |
27 |
|
|
FIBExtract: TIBExtract; |
28 |
|
|
protected |
29 |
|
|
procedure CreateObjects(Application: TTestApplication); override; |
30 |
|
|
function GetTestID: AnsiString; override; |
31 |
|
|
function GetTestTitle: AnsiString; override; |
32 |
|
|
procedure InitTest; override; |
33 |
|
|
public |
34 |
|
|
procedure RunTest(CharSet: AnsiString; SQLDialect: integer); override; |
35 |
|
|
end; |
36 |
|
|
|
37 |
|
|
|
38 |
|
|
implementation |
39 |
|
|
|
40 |
|
|
{ TTest25 } |
41 |
|
|
|
42 |
|
|
procedure TTest25.CreateObjects(Application: TTestApplication); |
43 |
|
|
begin |
44 |
|
|
inherited CreateObjects(Application); |
45 |
|
|
FIBTable := TIBTable.Create(Application); |
46 |
|
|
with FIBTable do |
47 |
|
|
begin |
48 |
|
|
Database := IBDatabase; |
49 |
|
|
Transaction := IBTransaction; |
50 |
|
|
TableName := 'TestTable'; |
51 |
|
|
with FieldDefs do |
52 |
|
|
begin |
53 |
|
|
Add('MYKEY',ftInteger,4); |
54 |
|
|
Add('TEXTFIELD',ftString,32); |
55 |
|
|
end; |
56 |
|
|
IndexDefs.Add('PrimaryIndex','MYKEY',[ixPrimary]); |
57 |
|
|
end; |
58 |
|
|
FIBExtract := TIBExtract.Create(Application); |
59 |
|
|
FIBExtract.Database := IBDatabase; |
60 |
|
|
FIBExtract.Transaction := IBTransaction; |
61 |
|
|
FIBExtract.CaseSensitiveObjectNames := true; |
62 |
|
|
end; |
63 |
|
|
|
64 |
|
|
function TTest25.GetTestID: AnsiString; |
65 |
|
|
begin |
66 |
|
|
Result := aTestID; |
67 |
|
|
end; |
68 |
|
|
|
69 |
|
|
function TTest25.GetTestTitle: AnsiString; |
70 |
|
|
begin |
71 |
|
|
Result := aTestTitle; |
72 |
|
|
end; |
73 |
|
|
|
74 |
|
|
procedure TTest25.InitTest; |
75 |
|
|
begin |
76 |
|
|
IBDatabase.DatabaseName := Owner.GetNewDatabaseName; |
77 |
|
|
IBDatabase.CreateIfNotExists := true; |
78 |
|
|
ReadWriteTransaction; |
79 |
|
|
end; |
80 |
|
|
|
81 |
|
|
procedure TTest25.RunTest(CharSet: AnsiString; SQLDialect: integer); |
82 |
|
|
begin |
83 |
|
|
IBDatabase.Connected := true; |
84 |
|
|
IBTransaction.Active := true; |
85 |
|
|
try |
86 |
|
|
FIBTable.CreateTable; |
87 |
|
|
IBTransaction.Commit; |
88 |
|
|
IBTransaction.Active := true; |
89 |
|
|
writeln(Outfile,'IBTable after create'); |
90 |
|
|
FIBExtract.ExtractObject(eoTable,'TestTable'); |
91 |
|
|
writeln(Outfile,FIBExtract.Items.Text); |
92 |
|
|
FIBTable.Active := true; |
93 |
|
|
PrintDataset(FIBTable); |
94 |
|
|
writeln(Outfile,'Add 2 rows'); |
95 |
|
|
FIBTable.AppendRecord([1,'Test 1']); |
96 |
|
|
FIBTable.AppendRecord([2,'Test 2']); |
97 |
|
|
PrintDataset(FIBTable); |
98 |
|
|
writeln(Outfile,'Update first row'); |
99 |
|
|
with FIBTable do |
100 |
|
|
begin |
101 |
|
|
if Locate('MYKEY',1,[]) then |
102 |
|
|
begin |
103 |
|
|
Edit; |
104 |
|
|
FieldByName('TextField').Asstring := 'Updated Test 1'; |
105 |
|
|
Post; |
106 |
|
|
end; |
107 |
|
|
end; |
108 |
|
|
PrintDataset(FIBTable); |
109 |
|
|
writeln(Outfile,'Delete first row'); |
110 |
|
|
with FIBTable do |
111 |
|
|
if Locate('MYKEY',1,[]) then |
112 |
|
|
Delete; |
113 |
|
|
PrintDataset(FIBTable); |
114 |
|
|
writeln(Outfile,'Empty the Table'); |
115 |
|
|
FIBTable.EmptyTable; |
116 |
|
|
PrintDataset(FIBTable); |
117 |
|
|
writeln(Outfile,'Now drop the table'); |
118 |
|
|
FIBTable.Active := false; |
119 |
|
|
FIBTable.DeleteTable; |
120 |
|
|
IBTransaction.Commit; |
121 |
|
|
IBTransaction.Active := true; |
122 |
|
|
writeln(Outfile,'Extract table after drop - should be empty'); |
123 |
|
|
FIBExtract.ExtractObject(eoTable,'TestTable'); |
124 |
|
|
writeln(Outfile,FIBExtract.Items.Text); |
125 |
|
|
finally |
126 |
|
|
IBXScriptObj.ExecSQLScript('Drop Database'); |
127 |
|
|
end; |
128 |
|
|
end; |
129 |
|
|
|
130 |
|
|
initialization |
131 |
|
|
RegisterTest(TTest25); |
132 |
|
|
|
133 |
|
|
end. |
134 |
|
|
|