ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/testsuite/Test01.pas
Revision: 380
Committed: Mon Jan 10 10:13:17 2022 UTC (2 years, 10 months ago) by tony
Content type: text/x-pascal
File size: 4952 byte(s)
Log Message:
propset for eol-style

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 Test01;
28    
29     {$mode objfpc}{$H+}
30    
31     {Test 1: Open and read from Employee Database}
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     The test is run first with unidirectional buffering and then with bi-directional
37     buffering.
38    
39     Both client side and server side filters are tested with bi-directional buffering.
40    
41     Finally, a beforeOpen handler is used to dynamically filter the results.
42    
43     }
44    
45     interface
46    
47     uses
48     Classes, SysUtils, TestApplication, IBXTestBase, DB, IB, IBCustomDataSet, IBDatabase, IBQuery;
49    
50     const
51     aTestID = '01';
52     aTestTitle = 'Open and read from Employee Database';
53    
54     type
55    
56     { TTest1 }
57    
58     TTest1 = class(TIBXTestBase)
59     private
60     procedure ClientSideFilter(DataSet: TDataSet; var Accept: Boolean);
61     procedure HandleBeforeOpen(DataSet: TDataSet);
62     protected
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     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 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     { TTest1 }
92    
93     procedure TTest1.ClientSideFilter(DataSet: TDataSet; var Accept: Boolean);
94     begin
95     Accept := DataSet.FieldByName('HIRE_DATE').AsDateTime > EncodeDate(1994 ,1,1);
96     end;
97    
98     procedure TTest1.HandleBeforeOpen(DataSet: TDataSet);
99     begin
100     (DataSet as TIBParserDataSet).Parser.Add2WhereClause('FIRST_NAME = :FN');
101     (DataSet as TIBQuery).ParamByName('FN').AsString := 'Claudia';
102     end;
103    
104     function TTest1.GetTestID: AnsiString;
105     begin
106     Result := aTestID;
107     end;
108    
109     function TTest1.GetTestTitle: AnsiString;
110     begin
111     Result := aTestTitle;
112     end;
113    
114     procedure TTest1.InitTest;
115     begin
116     inherited InitTest;
117     IBDatabase.DatabaseName := Owner.GetEmployeeDatabaseName;
118     ReadOnlyTransaction;
119     end;
120    
121     procedure TTest1.RunTest(CharSet: AnsiString; SQLDialect: integer);
122     var stats: TPerfCounters;
123     begin
124     with IBQuery do
125     begin
126     AllowAutoActivateTransaction := true;
127     writeln(OutFile,'Read dataset unidirectional buffering');
128     Unidirectional := true;
129     SQL.Text := sqlExample;
130     EnableStatistics := true;
131     Active := true;
132     PrintDataSet(IBQuery);
133    
134     if GetPerfStatistics(stats) then
135     WritePerfStats(stats);
136     PrintAffectedRows(IBQuery);
137     writeln(OutFile);
138     writeln(OutFile,'Reconnect');
139     writeln(OutFile,'Read dataset bidirectional buffering');
140     IBDatabase.ReConnect;
141     Unidirectional := false;
142     Active := true;
143     PrintDataSet(IBQuery);
144     Active := false;
145     writeln(OutFile,'Server Side Filter: Hire Date < 1/1/90');
146     SQLFiltered := true;
147     SQLFilterParams.Text := 'HIRE_DATE < ''1990.01.01''';
148     Active := true;
149     PrintDataSet(IBQuery);
150     Active := false;
151     writeln(Outfile,'Client side Filter: Hire Date > 1/1/94');
152     SQLFiltered := false;
153     Filtered := true;
154     OnFilterRecord := @ClientSideFilter;
155     Active := true;
156     PrintDataSet(IBQuery);
157     Active := false;
158     Filtered := false;
159     writeln(Outfile,'TIBQuery with open parameters - select only records with First Name = Claudia');
160     BeforeOpen := @HandleBeforeOpen;
161     Active := true;
162     PrintDataSet(IBQuery);
163    
164     end;
165     end;
166    
167     initialization
168     RegisterTest(TTest1);
169    
170     end.
171    

Properties

Name Value
svn:eol-style native