ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/testsuite/Test04.pas
Revision: 410
Committed: Thu Jun 22 13:52:39 2023 UTC (17 months ago) by tony
Content type: text/x-pascal
File size: 9952 byte(s)
Log Message:
Release 2.6.0 beta

File Contents

# User Rev Content
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 Test04;
28    
29     {$mode objfpc}{$H+}
30    
31     {Test 4: handling of data types up to Firebird 3.
32    
33     Tests, Append, Edit and Delete operations
34    
35     Test both default createdatabase and createdatabasefromSQL
36     }
37    
38     interface
39    
40     uses
41     Classes, SysUtils, TestApplication, IBXTestBase, DB, IB, IBCustomDataSet;
42    
43     const
44     aTestID = '04';
45     aTestTitle = 'Handling of data types up to Firebird 3';
46    
47     type
48    
49     { TTest04 }
50    
51     TTest04 = class(TIBXTestBase)
52     private
53     FDataSet: TIBDataSet;
54     FCreateArrayOnInsert: boolean;
55     procedure HandleAfterInsert(DataSet: TDataSet);
56     procedure HandleTransactionEdit(Sender: TObject);
57     procedure HandleTransactionDelete(Sender: TObject);
58     procedure HandleTransactionInsert(Sender: TObject);
59     procedure HandleTransactionPost(Sender: TObject);
60     procedure HandleTransactionExecQuery(Sender: TObject);
61     protected
62     procedure CreateObjects(Application: TTestApplication); override;
63     function GetTestID: AnsiString; override;
64     function GetTestTitle: AnsiString; override;
65     procedure InitTest; override;
66     public
67     procedure RunTest(CharSet: AnsiString; SQLDialect: integer); override;
68     end;
69    
70    
71     implementation
72    
73     uses DateUtils, IBSQL;
74    
75     { TTest04 }
76    
77     procedure TTest04.HandleAfterInsert(DataSet: TDataSet);
78     var S, F: TStream;
79     Str: TStringList;
80     i,j: integer;
81     ar: IArray;
82     begin
83     with DataSet do
84     begin
85     FieldByName('F1').AsInteger := 2;
86     FieldByName('f2').AsFloat := 0.314;
87     FieldByName('f3').AsFloat := 0.31412345678;
88     FieldByName('F4').AsFloat := 101.314;
89     FieldByName('F5').AsCurrency := 101.99;
90     FieldByName('F6').AsDateTime := EncodeDateTime(2007,12,25,12,30,15,0);
91     FieldByName('F7').AsDateTime := EncodeDateTime(2007,12,25,12,30,29,130);
92     FieldByName('F8').AsString := 'XX';
93     FieldByName('F9').AsString := 'The Quick Brown Fox jumps over the lazy dog';
94     S := CreateBlobStream(FieldByName('F10'),bmWrite);
95     F := TFileStream.Create('resources/Test04.jpg',fmOpenRead);
96     try
97     S.CopyFrom(F,0);
98     finally
99     S.Free;
100     F.Free;
101     end;
102     FieldByName('F11').AsLargeInt := 9223372036854775807;
103     FieldByName('F12').AsInteger := 65566;
104     FieldByName('F13').AsDateTime := EncodeDateTime(2007,12,26,12,30,45,0);
105     Str := TStringList.Create;
106     try
107     Str.LoadFromFile('resources/Test04.txt');
108     FieldByName('F14').AsString := Str.Text;
109     finally
110     Str.Free;
111     end;
112     if FCreateArrayOnInsert then
113     ar := TIBArrayField(FieldByName('MyArray')).CreateArray
114     else
115     ar := (DataSet as TIBCustomDataset).GetArray(TIBArrayField(FieldByName('MyArray')));
116     j := 100;
117     for i := 0 to 16 do
118     begin
119     ar.SetAsInteger([i],j);
120     dec(j);
121     end;
122     TIBArrayField(FieldByName('MyArray')).ArrayIntf := ar;
123     end;
124     end;
125    
126     procedure TTest04.HandleTransactionEdit(Sender: TObject);
127     begin
128     writeln(OutFile,'Transaction Edit');
129     end;
130    
131     procedure TTest04.HandleTransactionDelete(Sender: TObject);
132     begin
133     writeln(OutFile,'Transaction Delete');
134     end;
135    
136     procedure TTest04.HandleTransactionInsert(Sender: TObject);
137     begin
138     writeln(OutFile,'Transaction Insert');
139     end;
140    
141     procedure TTest04.HandleTransactionPost(Sender: TObject);
142     begin
143     writeln(OutFile,'Transaction Post');
144     end;
145    
146     procedure TTest04.HandleTransactionExecQuery(Sender: TObject);
147     begin
148     write(OutFile,'Transaction Exec Query ');
149     if Sender is TIBSQL then
150     writeln(OutFile,'"',(Sender as TIBSQL).SQL.Text,'"')
151     else
152     writeln(OutFile);
153     end;
154    
155     procedure TTest04.CreateObjects(Application: TTestApplication);
156     begin
157     inherited CreateObjects(Application);
158     FDataSet := TIBDataSet.Create(Application);
159     with FDataSet do
160     begin
161     Database := IBDatabase;
162 tony 410 Transaction := IBTransaction;
163 tony 315 with IBTransaction do
164     begin
165     AfterEdit := @HandleTransactionEdit;
166     AfterDelete := @HandleTransactionDelete;
167     AfterInsert := @HandleTransactionInsert;
168     AfterPost := @HandleTransactionPost;
169     AfterExecQuery := @HandleTransactionExecQuery;
170     end;
171     SelectSQL.Text := 'Select A.TABLEKEY, A.F1, A.F2, A.F3, A.F4, A.F5, A.F6,'+
172     ' A.F7, A.F8, A.F9, A.F10, A.F11, A."f12", A.F13, A.F14, A.MyArray, A.'+
173     'GRANTS, A."My Field" as MYFIELD1, A."MY Field" as MYFIELD2 From IBXTEST A';
174     InsertSQL.Text :=
175     'Insert Into IBXTEST(TABLEKEY, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, "f12", F13, F14, MyArray, '+
176     ' GRANTS) Values(:TABLEKEY, :F1, :F2, :F3, :F4, :F5, :F6, :F7,'+
177 tony 410 ':F8, :F9, :F10, :F11, :F12, :F13, :F14, :MyArray, :GRANTS) Returning MyArray, F10, F14, F15';
178 tony 315 RefreshSQL.Text :=
179     'Select A.TABLEKEY, A.F1, A.F2, A.F3, A.F4, A.F5, A.F6,' +
180     ' A.F7, A.F8, A.F9, A.F10, A.F11, A."f12", A.F13, A.F14, A.MyArray, A.'+
181     'GRANTS, A."My Field" as MYFIELD1, A."MY Field" as MYFIELD2 From IBXTEST A '+
182     'Where A.TABLEKEY = :TABLEKEY';
183     ModifySQL.Text :=
184     'Update IBXTEST A Set ' +
185     ' A.F1 = :F1,' +
186     ' A.F2 = :F2,' +
187     ' A.F3 = :F3,' +
188     ' A.F4 = :F4,' +
189     ' A.F5 = :F5,' +
190     ' A.F6 = :F6,' +
191     ' A.F7 = :F7,' +
192     ' A.F8 = :F8,' +
193     ' A.F9 = :F9,' +
194     ' A.F10 = :F10,' +
195     ' A.F11 = :F11,' +
196     ' A."f12" = :F12,' +
197     ' A.F13 = :F13,' +
198     ' A.F14 = :F14,' +
199     ' A.MyArray = :MyArray, ' +
200     ' A."My Field" = :MYFIELD1,'+
201     ' A."MY Field" = :MYFIELD2,'+
202     ' A.GRANTS = :GRANTS '+
203     'Where A.TABLEKEY = :OLD_TABLEKEY';
204     DeleteSQL.Text :=
205     'Delete From IBXTEST A '+
206     'Where A.TABLEKEY = :OLD_TABLEKEY';
207     DataSetCloseAction := dcSaveChanges;
208     AutoCommit := acDisabled;
209     GeneratorField.Generator := 'IBXGEN';
210     GeneratorField.Field := 'TABLEKEY';
211     GeneratorField.ApplyOnEvent := gaeOnNewRecord;
212     AfterInsert := @HandleAfterInsert;
213     end;
214     end;
215    
216     function TTest04.GetTestID: AnsiString;
217     begin
218     Result := aTestID;
219     end;
220    
221     function TTest04.GetTestTitle: AnsiString;
222     begin
223     Result := aTestTitle;
224     end;
225    
226     procedure TTest04.InitTest;
227     begin
228     IBDatabase.DatabaseName := Owner.GetNewDatabaseName;
229     IBDatabase.CreateIfNotExists := true;
230     ReadWriteTransaction;
231     end;
232    
233     procedure TTest04.RunTest(CharSet: AnsiString; SQLDialect: integer);
234     var OldDefaultFormatSettings: TFormatSettings;
235     begin
236     OldDefaultFormatSettings := DefaultFormatSettings;
237     IBDatabase.CreateDatabase;
238     try
239     DefaultFormatSettings.LongTimeFormat := 'HH:MM:SS.zzzz';
240     IBTransaction.Active := true;
241     FDataSet.Active := true;
242     writeln(OutFile,'Add a record');
243     FDataSet.Append;
244     FDataSet.Post;
245     writeln(OutFile,'Add and edit a record');
246     FCreateArrayOnInsert := true;
247     FDataSet.Append;
248     FDataSet.Post;
249     FDataSet.Edit;
250     FDataSet.FieldByName('MYField1').AsString := 'My Field';
251     FDataSet.FieldByName('MYFIELD2').AsString := 'MY Field';
252     FDataSet.Post;
253 tony 410 writeln(OutFile,'Clear Blob and Array');
254     FDataSet.Append;
255     FDataSet.Post;
256     FDataSet.Edit;
257     FDataSet.FieldByName('F14').Clear;
258     FDataSet.FieldByName('MYARRAY').Clear;
259     FDataSet.Post;
260 tony 315 IBTransaction.Commit;
261    
262     IBTransaction.Active := true;
263     FDataSet.Active := true;
264     PrintDataSet(FDataSet);
265 tony 410 FDataset.Last;
266     FDataset.Delete; {Remove clear Blob row}
267     IBTransaction.Commit;
268     IBTransaction.Active := true;
269     FDataSet.Active := true;
270    
271 tony 315 writeln(OutFile,'Delete a record');
272     FDataSet.First;
273     FDataSet.Delete;
274     PrintDataSet(FDataSet);
275     writeln(OutFile,'Rollback Retaining');
276     IBTransaction.RollbackRetaining;
277     FDataSet.Active := false;
278     FDataSet.Active := true;
279     PrintDataSet(FDataSet);
280     writeln(OutFile,'Delete a record');
281     FDataSet.First;
282     FDataSet.Delete;
283     PrintDataSet(FDataSet);
284     writeln(OutFile,'Rollback');
285     IBTransaction.Rollback;
286     IBTransaction.Active := true;
287     FDataSet.Active := true;
288     PrintDataSet(FDataSet);
289     writeln(OutFile,'Commit Retaining');
290     FDataSet.Append;
291     FDataSet.Post;
292     IBTransaction.CommitRetaining;
293     FDataSet.Active := false;
294     FDataSet.Active := true;
295     PrintDataSet(FDataSet);
296     writeln(OutFile,'Commit');
297     IBTransaction.Commit;
298     IBTransaction.Active := true;
299     FDataSet.Active := true;
300     PrintDataSet(FDataSet);
301     finally
302     IBDatabase.DropDatabase;
303     end;
304    
305     writeln(Outfile,'Creating Database from SQL');
306     IBDatabase.CreateDatabase('CREATE DATABASE ''' + Owner.GetNewDatabaseName +
307     ''' USER ''' + Owner.GetUserName +
308     ''' PASSWORD ''' + Owner.GetPassword + '''' +
309     ' DEFAULT CHARACTER SET UTF8');
310     if IBDatabase.Connected then
311     begin
312     writeln(Outfile,'Database Name = ',IBDatabase.DatabaseName);
313     try
314     IBTransaction.Active := true;
315     FDataSet.Active := true;
316     writeln(OutFile,'Add a record');
317     FDataSet.Append;
318     FDataSet.Post;
319     FDataSet.First;
320     PrintDataSet(FDataSet);
321     finally
322     IBDatabase.DropDatabase;
323     end;
324    
325     end
326     else
327     writeln(OutFile,'Create Database failed');
328     end;
329    
330     initialization
331     RegisterTest(TTest04);
332    
333     end.
334    

Properties

Name Value
svn:eol-style native