ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/branches/udr/testsuite/Test2.pas
Revision: 350
Committed: Wed Oct 20 14:58:56 2021 UTC (2 years, 6 months ago) by tony
Content type: text/x-pascal
Original Path: ibx/trunk/fbintf/testsuite/Test2.pas
File size: 6385 byte(s)
Log Message:
Fixed Merged

File Contents

# User Rev Content
1 tony 333 (*
2     * Firebird Interface (fbintf) Test suite. This program is used to
3     * test the Firebird Pascal Interface and provide a semi-automated
4     * pass/fail check for each test.
5     *
6     * The contents of this file are subject to the Initial Developer's
7     * Public License Version 1.0 (the "License"); you may not use this
8     * file except in compliance with the License. You may obtain a copy
9     * of the License here:
10     *
11     * http://www.firebirdsql.org/index.php?op=doc&id=idpl
12     *
13     * Software distributed under the License is distributed on an "AS
14     * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
15     * implied. See the License for the specific language governing rights
16     * and limitations under the License.
17     *
18     * The Initial Developer of the Original Code is Tony Whyman.
19     *
20     * The Original Code is (C) 2016 Tony Whyman, MWA Software
21     * (http://www.mwasoftware.co.uk).
22     *
23     * All Rights Reserved.
24     *
25     * Contributor(s): ______________________________________.
26     *
27     *)
28    
29     unit Test2;
30     {$IFDEF MSWINDOWS}
31     {$DEFINE WINDOWS}
32     {$ENDIF}
33    
34     {$IFDEF FPC}
35     {$mode delphi}
36     {$codepage utf8}
37     {$ENDIF}
38    
39     {Test 2: Open the employee database and run a query}
40    
41     { This test opens the employee example databases with the supplied user name/password
42     and runs a simple query with no parameters. Note that the password parameter
43     is first supplied empty and then updated.
44    
45     Both the output metadata and the query plan are printed out, followed by the results of the query.
46    
47     A specific employee record is then queried, first using a positional parameter
48     and then a parameter by name. In each case, the SQL Parameter metadata is also
49     printed followed by the query results.
50    
51     Finally, the database is explicitly disconnected.
52     }
53    
54     interface
55    
56     uses
57     Classes, SysUtils, TestApplication, FBTestApp, IB;
58    
59     type
60    
61     { TTest2 }
62    
63     TTest2 = class(TFBTestBase)
64     private
65     procedure DoQuery(Attachment: IAttachment);
66 tony 350 procedure DoScrollableQuery(Attachment: IAttachment);
67 tony 333 public
68     function TestTitle: AnsiString; override;
69     procedure RunTest(CharSet: AnsiString; SQLDialect: integer); override;
70     end;
71    
72    
73     implementation
74    
75     { TTest2 }
76    
77     procedure TTest2.DoQuery(Attachment: IAttachment);
78     var Transaction: ITransaction;
79     Statement: IStatement;
80     begin
81     Transaction := Attachment.StartTransaction([isc_tpb_read,isc_tpb_nowait,isc_tpb_concurrency],taCommit);
82     PrintTPB(Transaction.getTPB);
83     Statement := Attachment.Prepare(Transaction,
84     '-- SQL style inline comment' + LineEnding +
85     '/* this is a comment */ '+
86     'Select First 3 * from EMPLOYEE'
87     ,3);
88     PrintMetaData(Statement.GetMetaData);
89     writeln(OutFile,'Plan = ' ,Statement.GetPlan);
90     writeln(OutFile,Statement.GetSQLText);
91     writeln(OutFile);
92     ReportResults(Statement);
93     Statement := Attachment.Prepare(Transaction,'Select * from EMPLOYEE Where EMP_NO = ?',3);
94     writeln(OutFile,Statement.GetSQLText);
95     ParamInfo(Statement.SQLParams);
96     Statement.GetSQLParams[0].AsInteger := 8;
97     ReportResults(Statement);
98     writeln(OutFile,'With param names');
99     Statement := Attachment.PrepareWithNamedParameters(Transaction,
100 tony 350 'Select * from EMPLOYEE Where EMP_NO = :EMP_NO',3,false,false,'Test Cursor');
101 tony 333 Statement.SetRetainInterfaces(true);
102     try
103     writeln(OutFile,Statement.GetSQLText);
104     ParamInfo(Statement.SQLParams);
105     Statement.GetSQLParams.ByName('EMP_NO').AsInteger := 8;
106 tony 350 ReportResults(Statement,true);
107 tony 333 finally
108     Statement.SetRetainInterfaces(false);
109     end;
110     end;
111    
112 tony 350 procedure TTest2.DoScrollableQuery(Attachment: IAttachment);
113     var Transaction: ITransaction;
114     Statement: IStatement;
115     Results: IResultSet;
116     begin
117     writeln(Outfile,'Scollable Cursors');
118     Transaction := Attachment.StartTransaction([isc_tpb_read,isc_tpb_nowait,isc_tpb_concurrency],taCommit);
119     Statement := Attachment.Prepare(Transaction,'Select * from EMPLOYEE order by EMP_NO',3);
120     Results := Statement.OpenCursor(true);
121     writeln(Outfile,'Do Fetch Next:');
122     if Results.FetchNext then
123     ReportResult(Results);
124     writeln(Outfile,'Do Fetch Last:');
125     if Results.FetchLast then
126     ReportResult(Results);
127     writeln(Outfile,'Do Fetch Prior:');
128     if Results.FetchPrior then
129     ReportResult(Results);
130     writeln(Outfile,'Do Fetch First:');
131     if Results.FetchFirst then
132     ReportResult(Results);
133     writeln(Outfile,'Do Fetch Abs 8 :');
134     if Results.FetchAbsolute(8) then
135     ReportResult(Results);
136     writeln(Outfile,'Do Fetch Relative -2 :');
137     if Results.FetchRelative(-2) then
138     ReportResult(Results);
139     writeln(Outfile,'Do Fetch beyond EOF :');
140     if Results.FetchAbsolute(150) then
141     ReportResult(Results)
142     else
143     writeln(Outfile,'Fetch returned false');
144     end;
145    
146 tony 333 function TTest2.TestTitle: AnsiString;
147     begin
148     Result := 'Test 2: Open the employee database and run a query';
149     end;
150    
151     procedure TTest2.RunTest(CharSet: AnsiString; SQLDialect: integer);
152     var Attachment: IAttachment;
153     DPB: IDPB;
154     begin
155     DPB := FirebirdAPI.AllocateDPB;
156     DPB.Add(isc_dpb_user_name).setAsString(Owner.GetUserName);
157     DPB.Add(isc_dpb_password).setAsString(' ');
158     DPB.Add(isc_dpb_lc_ctype).setAsString(CharSet);
159     DPB.Add(isc_dpb_set_db_SQL_dialect).setAsByte(SQLDialect);
160     DPB.Find(isc_dpb_password).setAsString(Owner.GetPassword);
161     try
162     Attachment := FirebirdAPI.OpenDatabase(Owner.GetEmployeeDatabaseName,DPB);
163     except on e: Exception do
164     writeln(OutFile,'Open Database fails ',E.Message);
165     end;
166     writeln(OutFile,'Opening ',Owner.GetEmployeeDatabaseName);
167     Attachment := FirebirdAPI.OpenDatabase(Owner.GetEmployeeDatabaseName,DPB);
168     writeln(OutFile,'Database Open, SQL Dialect = ',Attachment.GetSQLDialect);
169     DoQuery(Attachment);
170     Attachment.Disconnect;
171     writeln(OutFile,'Now open the employee database as a local database');
172     DPB := FirebirdAPI.AllocateDPB;
173     DPB.Add(isc_dpb_lc_ctype).setAsString(CharSet);
174     DPB.Add(isc_dpb_set_db_SQL_dialect).setAsByte(SQLDialect);
175     DPB.Add(isc_dpb_user_name).setAsString(Owner.GetUserName);
176     if FirebirdAPI.GetClientMajor < 3 then
177     DPB.Add(isc_dpb_password).setAsString(Owner.GetPassword);
178     try
179     Attachment := FirebirdAPI.OpenDatabase(ExtractDBName(Owner.GetEmployeeDatabaseName),DPB);
180     except on e: Exception do
181     writeln(OutFile,'Open Local Database fails ',E.Message);
182     end;
183     DoQuery(Attachment);
184 tony 350 if FirebirdAPI.HasScollableCursors then
185     DoScrollableQuery(Attachment);
186 tony 333 Attachment.Disconnect;
187     end;
188    
189     initialization
190     RegisterTest(TTest2);
191    
192     end.
193