ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/testsuite/Test13.pas
Revision: 323
Committed: Thu Feb 25 12:14:35 2021 UTC (3 years, 8 months ago) by tony
Content type: text/x-pascal
File size: 5146 byte(s)
Log Message:
Fixed Merged

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 Test13;
28    
29     {$mode objfpc}{$H+}
30    
31     {Test 13: Open and read from Employee Database with ISQLMonitor}
32    
33     { This is a simple use of IBX to access the employee database in console mode.
34     The program opens the database, runs a query and writes the result to stdout.
35    
36     ISQLMonitor is used to trace the activity.
37    
38     }
39    
40     interface
41    
42     uses
43     Classes, SysUtils, TestApplication, IBXTestBase, IB, IBCustomDataSet, IBDatabase,
44     IBQuery, IBInternals, IBSQLMonitor;
45    
46     const
47     aTestID = '13';
48     aTestTitle = 'Open and read from Employee Database with ISQLMonitor';
49    
50     type
51    
52     { TTest13 }
53    
54     TTest13 = class(TIBXTestBase)
55     private
56     FIBSQLMonitor: TIBSQLMonitor;
57     FLog: TStringList;
58     procedure HandleOnSQL(EventText: String; EventTime : TDateTime);
59 tony 319 procedure ShowStatistics(Sender: TObject);
60 tony 315 protected
61     procedure CreateObjects(Application: TTestApplication); override;
62     function GetTestID: AnsiString; override;
63     function GetTestTitle: AnsiString; override;
64     procedure InitTest; override;
65     public
66     destructor Destroy; override;
67     procedure RunTest(CharSet: AnsiString; SQLDialect: integer); override;
68     end;
69    
70    
71     implementation
72    
73     const
74     sqlExample =
75     'with recursive Depts As ( '+
76     'Select DEPT_NO, DEPARTMENT, HEAD_DEPT, cast(DEPARTMENT as VarChar(256)) as DEPT_PATH,'+
77     'cast(DEPT_NO as VarChar(64)) as DEPT_KEY_PATH '+
78     'From DEPARTMENT Where HEAD_DEPT is NULL '+
79     'UNION ALL '+
80     'Select D.DEPT_NO, D.DEPARTMENT, D.HEAD_DEPT, Depts.DEPT_PATH || '' / '' || D.DEPARTMENT as DEPT_PATH,'+
81     'Depts.DEPT_KEY_PATH || '';'' || D.DEPT_NO as DEPT_KEY_PATH '+
82     'From DEPARTMENT D '+
83     'JOIN Depts On D.HEAD_DEPT = Depts.DEPT_NO '+
84     ')'+
85    
86     'Select First 2 A.EMP_NO, A.FIRST_NAME, A.LAST_NAME, A.PHONE_EXT, A.HIRE_DATE, A.DEPT_NO, A.JOB_CODE,'+
87     'A.JOB_GRADE, A.JOB_COUNTRY, A.SALARY, A.FULL_NAME, D.DEPT_PATH, D.DEPT_KEY_PATH '+
88     'From EMPLOYEE A '+
89     'JOIN Depts D On D.DEPT_NO = A.DEPT_NO';
90    
91     { TTest13 }
92    
93     procedure TTest13.HandleOnSQL(EventText: String; EventTime: TDateTime);
94     begin
95 tony 319 FLog.Add('*Monitor* ' {+DateTimeToStr(EventTime)}+' '+EventText);
96 tony 315 end;
97    
98 tony 319 procedure TTest13.ShowStatistics(Sender: TObject);
99     begin
100     writeln(OutFile,FIBSQLMonitor.ReadCount,' ISQL Monitor Messages Received');
101     end;
102    
103 tony 315 procedure TTest13.CreateObjects(Application: TTestApplication);
104     begin
105     inherited CreateObjects(Application);
106     FIBSQLMonitor := TIBSQLMonitor.Create(Application);
107     FIBSQLMonitor.TraceFlags := [tfQPrepare, tfQExecute, tfQFetch, tfError, tfStmt, tfConnect,
108     tfTransact, tfBlob, tfService, tfMisc];
109     IBDatabase.TraceFlags := [tfQPrepare, tfQExecute, tfQFetch, tfError, tfStmt, tfConnect,
110     tfTransact, tfBlob, tfService, tfMisc];
111     FIBSQLMonitor.OnSQL := @HandleOnSQL;
112 tony 319 FIBSQLMonitor.OnMonitoringDisabled := @ShowStatistics;
113 tony 315 FIBSQLMonitor.Enabled := true;
114     FLog := TStringList.Create;
115     end;
116    
117     function TTest13.GetTestID: AnsiString;
118     begin
119     Result := aTestID;
120     end;
121    
122     function TTest13.GetTestTitle: AnsiString;
123     begin
124     Result := aTestTitle;
125     end;
126    
127     procedure TTest13.InitTest;
128     begin
129     inherited InitTest;
130     IBDatabase.DatabaseName := Owner.GetEmployeeDatabaseName;
131     ReadOnlyTransaction;
132     end;
133    
134     destructor TTest13.Destroy;
135     begin
136     FLog.Free;
137     inherited Destroy;
138     end;
139    
140     procedure TTest13.RunTest(CharSet: AnsiString; SQLDialect: integer);
141     var stats: TPerfCounters;
142     i: integer;
143     begin
144     writeln(OutFile);
145     EnableMonitoring;
146     CheckSynchronize(1);
147     with IBQuery do
148     begin
149     AllowAutoActivateTransaction := true;
150     Unidirectional := true;
151     SQL.Text := sqlExample;
152     EnableStatistics := true;
153     Active := true;
154     PrintDataSet(IBQuery);
155    
156     if GetPerfStatistics(stats) then
157     WritePerfStats(stats);
158     PrintAffectedRows(IBQuery);
159     writeln(OutFile);
160     writeln(OutFile,'Reconnect');
161     IBDatabase.ReConnect;
162     Unidirectional := false;
163     Active := true;
164     PrintDataSet(IBQuery);
165     end;
166     IBDatabase.Connected := false;
167     CheckSynchronize(1);
168     DisableMonitoring;
169 tony 319 writeln(Outfile,MonitorHook.GetWriteCount,' ISQL Monitor Messages written');
170     Sleep(1000);
171 tony 315 for i := 0 to FLog.Count - 1 do
172     writeln(OutFile,FLog[i]);
173 tony 319 writeln(OutFile,FIBSQLMonitor.ReadCount,' ISQL Monitor Messages Received');
174 tony 315 end;
175    
176     initialization
177     RegisterTest(TTest13);
178    
179     end.
180