ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/fbintf/testsuite/Test21.pas
Revision: 353
Committed: Sat Oct 23 14:11:37 2021 UTC (3 years, 1 month ago) by tony
Content type: text/x-pascal
File size: 5107 byte(s)
Log Message:
Fixes Merged

File Contents

# User Rev Content
1 tony 351 (*
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 Test21;
30    
31     {$IFDEF MSWINDOWS}
32     {$DEFINE WINDOWS}
33     {$ENDIF}
34    
35     {$IFDEF FPC}
36     {$mode delphi}
37     {$codepage utf8}
38     {$ENDIF}
39    
40     {Test 21: Exercise setting and getting of numeric data types}
41    
42     interface
43    
44     uses
45     Classes, SysUtils, TestApplication, FBTestApp, IB;
46    
47     type
48    
49     { TTest21 }
50    
51     TTest21 = class(TFBTestBase)
52     private
53     procedure UpdateDatabase(Attachment: IAttachment);
54     procedure QueryDatabase(Attachment: IAttachment);
55     public
56     function TestTitle: AnsiString; override;
57     procedure RunTest(CharSet: AnsiString; SQLDialect: integer); override;
58     end;
59    
60    
61    
62     implementation
63    
64     const
65     sqlCreateTable =
66     'Create Table TestData ('+
67     'RowID Integer not null,'+
68     'iType Integer,'+
69     'i64Type BIGINT,'+
70     'CurrType Numeric(12,4),'+
71     'dType DOUBLE PRECISION,'+
72     'FixedPoint Numeric(10,6),'+
73     'Primary Key (RowID)'+
74     ')';
75    
76     sqlInsert = 'Insert into TestData(RowID,iType,i64Type,CurrType,dType,FixedPoint) Values(?,?,?,?,?,?)';
77    
78    
79     { TTest21 }
80    
81     procedure TTest21.UpdateDatabase(Attachment: IAttachment);
82     var Transaction: ITransaction;
83     Statement: IStatement;
84     begin
85     Transaction := Attachment.StartTransaction([isc_tpb_write,isc_tpb_nowait,isc_tpb_concurrency],taCommit);
86     Statement := Attachment.Prepare(Transaction,sqlInsert);
87     ParamInfo(Statement.GetSQLParams);
88     with Statement.GetSQLParams do
89     begin
90     Params[0].AsInteger := 1;
91     Params[1].AsString := '101';
92     Params[2].AsString := ' 9223372036854775807';
93     Params[3].AsString := '10000.1234';
94     Params[4].AsString := '9999.123456780';
95     Params[5].AsString := '1234567890.12345678';
96     end;
97     Statement.Execute;
98     with Statement.GetSQLParams do
99     begin
100     Params[0].AsInteger := 2;
101     Params[1].AsString := '-32457';
102     Params[2].AsString := ' -9223372036854775808 ';
103     Params[3].AsString := '+1000001.12';
104     Params[4].AsString := '1.7E308';
105     Params[5].AsString := '-1234567890.12345678';
106     end;
107     Statement.Execute;
108     with Statement.GetSQLParams do
109     begin
110     Params[0].AsInteger := 3;
111     Params[1].AsString := '0';
112     Params[2].AsString := '0';
113     Params[3].AsString := '0';
114     Params[4].AsString := '0';
115     Params[5].AsString := '0';
116     end;
117     Statement.Execute;
118     with Statement.GetSQLParams do
119     begin
120     Params[0].AsInteger := 4;
121     Params[1].AsString := '1.0';
122     Params[2].AsString := '10.';
123     Params[3].AsString := '2.3E-2';
124 tony 353 Params[4].AsString := '11e-4';
125 tony 351 Params[5].AsString := '2.33456E2';
126     end;
127     Statement.Execute;
128     {error handling}
129     with Statement.GetSQLParams do
130     try
131     Params[0].AsInteger := 5;
132     Params[1].AsString := '1,000';
133     Statement.Execute;
134     except on E: Exception do
135     writeln(Outfile,'Expected Error - ',E.Message);
136     end;
137     with Statement.GetSQLParams do
138     try
139     Params[0].AsInteger := 6;
140     Params[5].AsString := '10.0.0';
141     Statement.Execute;
142     except on E: Exception do
143     writeln(Outfile,'Expected Error - ',E.Message);
144     end;
145    
146     end;
147    
148     procedure TTest21.QueryDatabase(Attachment: IAttachment);
149     var Transaction: ITransaction;
150     Statement: IStatement;
151     begin
152     Transaction := Attachment.StartTransaction([isc_tpb_read,isc_tpb_nowait,isc_tpb_concurrency],taCommit);
153     Statement := Attachment.Prepare(Transaction,'Select * from TestData');
154     ReportResults(Statement);
155     end;
156    
157     function TTest21.TestTitle: AnsiString;
158     begin
159     Result := 'Test 21: Exercise setting and getting of numeric data types';
160     end;
161    
162     procedure TTest21.RunTest(CharSet: AnsiString; SQLDialect: integer);
163     var DPB: IDPB;
164     Attachment: IAttachment;
165     begin
166     DPB := FirebirdAPI.AllocateDPB;
167     DPB.Add(isc_dpb_user_name).setAsString(Owner.GetUserName);
168     DPB.Add(isc_dpb_password).setAsString(Owner.GetPassword);
169     DPB.Add(isc_dpb_lc_ctype).setAsString(CharSet);
170     DPB.Add(isc_dpb_set_db_SQL_dialect).setAsByte(SQLDialect);
171     Attachment := FirebirdAPI.CreateDatabase(Owner.GetNewDatabaseName,DPB);
172     try
173     Attachment.ExecImmediate([isc_tpb_write,isc_tpb_wait,isc_tpb_consistency],sqlCreateTable);
174     SetFloatTemplate('#,###.00000000');
175     UpdateDatabase(Attachment);
176     QueryDatabase(Attachment);
177     finally
178     Attachment.DropDatabase;
179     end;
180     end;
181    
182     initialization
183     RegisterTest(TTest21);
184     end.
185