ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/testsuite/Test21.pas
Revision: 315
Committed: Thu Feb 25 11:56:36 2021 UTC (3 years, 9 months ago) by tony
Content type: text/x-pascal
File size: 3998 byte(s)
Log Message:
Updated for IBX 4 release

File Contents

# User Rev Content
1 tony 315 unit Test21;
2    
3     {$mode objfpc}{$H+}
4    
5     {Test 21: Big dataset test}
6    
7     { create a 100,000 record database.
8     read it back and check for errors using an MD5 message digest.
9     }
10    
11     interface
12    
13     uses
14     Classes, SysUtils, TestApplication, IBXTestBase, IB, IBSQL, MD5;
15    
16     const
17     aTestID = '21';
18     aTestTitle = 'Big dataset test';
19    
20     type
21    
22     { TTest21 }
23    
24     TTest21 = class(TIBXTestBase)
25     private
26     FIBSQL: TIBSQL;
27     function StuffDatabase: TMDDigest;
28     function ReadDatabase: TMDDigest;
29     protected
30     procedure CreateObjects(Application: TTestApplication); override;
31     function GetTestID: AnsiString; override;
32     function GetTestTitle: AnsiString; override;
33     procedure InitTest; override;
34     public
35     procedure RunTest(CharSet: AnsiString; SQLDialect: integer); override;
36     end;
37    
38    
39     implementation
40    
41     uses DateUtils;
42    
43     const
44     testText = 'The quick brown fox jumped over the lazy dog';
45     RecordCount = 100000;
46    
47     { TTest21 }
48    
49     function TTest21.StuffDatabase: TMDDigest;
50     var i: integer;
51     HashString: AnsiString;
52     MD5Context: TMDContext;
53     Started: TDateTime;
54     begin
55     Started := Now;
56     writeln(Outfile,'Loading data into database table. Started at ',DateTimeToStr(Started));
57     MDInit(MD5Context,MD_VERSION_5);
58     IBTransaction.Active := true;
59     for i := 1 to RecordCount do
60     with FIBSQL do
61     begin
62     Params[0].AsInteger := i;
63     Params[1].AsString := DateTimeToStr(Now) + testText + testText + testText + testText;
64     Params[2].AsDateTime := Now;
65     HashString := Params[0].Asstring + Params[1].AsString + DateTimeToStr(Params[2].AsDateTime);
66     ExecQuery;
67     MDUpdate(MD5Context,PAnsiChar(HashString)^,Length(HashString));
68     end;
69     IBTransaction.Commit;
70     MDFinal(MD5Context,Result);
71     writeln(OutFile, 'Data load completed at ',DateTimeToStr(Now), ' Elapsed Time = ',
72     (MilliSecondsBetween(Now,Started)),' ms, ',RecordCount,' records loaded');
73     writeln(Outfile,' MD5 checksum = ',MD5Print(Result));
74     end;
75    
76     function TTest21.ReadDatabase: TMDDigest;
77     var MD5Context: TMDContext;
78     Started: TDateTime;
79     HashString: AnsiString;
80     Count: integer;
81     begin
82     MDInit(MD5Context,MD_VERSION_5);
83     IBTransaction.Active := true;
84     Started := Now;
85     Count := 0;
86     writeln(Outfile,'Database Read started at ',DateTimeToStr(Started));
87     with IBQuery do
88     begin
89     Active := true;
90     while not EOF do
91     begin
92     Inc(Count);
93     HashString := Fields[0].AsString + Fields[1].AsString + DateTimeToStr(Fields[2].AsDateTime);
94     MDUpdate(MD5Context,PAnsiChar(HashString)^,Length(HashString));
95     Next;
96     end;
97     end;
98     writeln(OutFile, 'Read Dataset completed at ',DateTimeToStr(Now), ' Elapsed Time = ',
99     (MilliSecondsBetween(Now,Started)), ' ms, ',Count,' records read');
100     MDFinal(MD5Context,Result);
101     writeln(Outfile,' MD5 checksum = ',MD5Print(Result));
102     end;
103    
104     procedure TTest21.CreateObjects(Application: TTestApplication);
105     begin
106     inherited CreateObjects(Application);
107     FIBSQL := TIBSQL.Create(Application);
108     with FIBSQL do
109     begin
110     Database := IBDatabase;
111     Transaction := IBTransaction;
112     SQL.Text := 'Insert into LotsOfData(RowID,Mytext,theDate) Values(?,?,?)';
113     ParamCheck := false;
114     end;
115     IBQuery.SQL.Text := 'Select RowID,MyText,theDate from LotsOfData';
116     end;
117    
118     function TTest21.GetTestID: AnsiString;
119     begin
120     Result := aTestID;
121     end;
122    
123     function TTest21.GetTestTitle: AnsiString;
124     begin
125     Result := aTestTitle;
126     end;
127    
128     procedure TTest21.InitTest;
129     begin
130     IBDatabase.DatabaseName := Owner.GetNewDatabaseName;
131     IBDatabase.CreateIfNotExists := true;
132     ReadWriteTransaction;
133     end;
134    
135     procedure TTest21.RunTest(CharSet: AnsiString; SQLDialect: integer);
136     var Digest: TMD5Digest;
137     begin
138     IBDatabase.CreateDatabase;
139     try
140     Digest := StuffDatabase; {This creates a database holding a large 100,000 record table}
141     if MD5Match(Digest,ReadDatabase) then
142     writeln(Outfile,'Test Completed successfully')
143     else
144     writeln(Outfile,'Test failed. MD5 checksum error');
145     finally
146     IBDatabase.DropDatabase;
147     end;
148     end;
149    
150     initialization
151     RegisterTest(TTest21);
152    
153     end.
154