52 |
|
private |
53 |
|
procedure UpdateDatabase(Attachment: IAttachment); |
54 |
|
procedure QueryDatabase(Attachment: IAttachment); |
55 |
+ |
procedure ValidateStrToNumeric; |
56 |
+ |
procedure ValidateNumericInterface; |
57 |
|
public |
58 |
|
function TestTitle: AnsiString; override; |
59 |
|
procedure RunTest(CharSet: AnsiString; SQLDialect: integer); override; |
63 |
|
|
64 |
|
implementation |
65 |
|
|
66 |
+ |
uses FBNumeric, FmtBCD; |
67 |
+ |
|
68 |
|
const |
69 |
|
sqlCreateTable = |
70 |
|
'Create Table TestData ('+ |
125 |
|
Params[1].AsString := '1.0'; |
126 |
|
Params[2].AsString := '10.'; |
127 |
|
Params[3].AsString := '2.3E-2'; |
128 |
< |
Params[4].AsString := '0'; |
128 |
> |
Params[4].AsString := '11e-4'; |
129 |
|
Params[5].AsString := '2.33456E2'; |
130 |
|
end; |
131 |
|
Statement.Execute; |
146 |
|
except on E: Exception do |
147 |
|
writeln(Outfile,'Expected Error - ',E.Message); |
148 |
|
end; |
149 |
< |
|
149 |
> |
writeln(OutFile,'Test Numeric Type'); |
150 |
> |
with Statement.GetSQLParams do |
151 |
> |
begin |
152 |
> |
Clear; |
153 |
> |
Params[0].AsInteger := 7; |
154 |
> |
Params[1].AsNumeric := NewNumeric(1.0); |
155 |
> |
Params[2].AsVariant := 1234567; |
156 |
> |
Params[3].AsNumeric := NewNumeric(StrToFloat('2.3E-2'),-4); |
157 |
> |
Params[4].AsNumeric := NewNumeric('11e-4'); |
158 |
> |
Params[5].AsVariant := 1234.25; |
159 |
> |
end; |
160 |
> |
Statement.Execute; |
161 |
|
end; |
162 |
|
|
163 |
|
procedure TTest21.QueryDatabase(Attachment: IAttachment); |
169 |
|
ReportResults(Statement); |
170 |
|
end; |
171 |
|
|
172 |
+ |
procedure TTest21.ValidateStrToNumeric; |
173 |
+ |
const |
174 |
+ |
TestValues: array of string = ['1234.567','-765.4321','0.1','0.01','+123', |
175 |
+ |
'1.23456E308','-1.2e-02','10.','.12', '0.12', |
176 |
+ |
'1.2E1.2', '1,000', '1e1e1', '1.2+3']; {bad syntax} |
177 |
+ |
var |
178 |
+ |
i: integer; |
179 |
+ |
aValue: Int64; |
180 |
+ |
aScale: integer; |
181 |
+ |
begin |
182 |
+ |
for i := 0 to Length(TestValues) - 1 do |
183 |
+ |
begin |
184 |
+ |
if TryStrToNumeric(TestValues[i],aValue,aScale) then |
185 |
+ |
begin |
186 |
+ |
writeln(Outfile,TestValues[i],' parsed to ',aValue,' scale = ',aScale); |
187 |
+ |
writeln(Outfile,'As Float = ',NumericToDouble(aValue,aScale)); |
188 |
+ |
end |
189 |
+ |
else |
190 |
+ |
writeln(Outfile,'Parsing of ',TestValues[i],' failed'); |
191 |
+ |
end; |
192 |
+ |
end; |
193 |
+ |
|
194 |
+ |
procedure TTest21.ValidateNumericInterface; |
195 |
+ |
var numeric: IFBNumeric; |
196 |
+ |
begin |
197 |
+ |
writeln(Outfile,'Validating Numeric Interface - IFBNumeric'); |
198 |
+ |
numeric := NewNumeric(StrToCurr('9999.123456780')); |
199 |
+ |
writeln(Outfile,'Value from Currency = ',numeric.getAsString); |
200 |
+ |
writeln(Outfile,'Raw Value = ',numeric.getRawValue,' Scale = ',numeric.getScale); |
201 |
+ |
numeric := NewNumeric(StrToCurr('9999.123456780')).clone(-2); |
202 |
+ |
writeln(Outfile,'Value from Currency(rescaled) = ',numeric.getAsString); |
203 |
+ |
writeln(Outfile,'Raw Value = ',numeric.getRawValue,' Scale = ',numeric.getScale); |
204 |
+ |
numeric := NewNumeric(StrToFloat('9999.123456780'),-8); |
205 |
+ |
writeln(Outfile,'Value from Double = ',numeric.getAsString); |
206 |
+ |
writeln(Outfile,'Raw Value = ',numeric.getRawValue,' Scale = ',numeric.getScale); |
207 |
+ |
numeric := NewNumeric(StrToInt64('9223372036854775807')); |
208 |
+ |
writeln(Outfile,'Value from Integer = ',numeric.getAsString); |
209 |
+ |
writeln(Outfile,'Raw Value = ',numeric.getRawValue,' Scale = ',numeric.getScale); |
210 |
+ |
numeric := NewNumeric('9223372036854775807'); |
211 |
+ |
writeln(Outfile,'Value from string = ',numeric.getAsString); |
212 |
+ |
writeln(Outfile,'Raw Value = ',numeric.getRawValue,' Scale = ',numeric.getScale); |
213 |
+ |
numeric := NewNumeric('9999.123456780'); |
214 |
+ |
writeln(Outfile,'Value from string = ',numeric.getAsString); |
215 |
+ |
writeln(Outfile,'Raw Value = ',numeric.getRawValue,' Scale = ',numeric.getScale); |
216 |
+ |
numeric := NewNumeric('-1.2e-02'); |
217 |
+ |
writeln(Outfile,'Value from string = ',numeric.getAsString); |
218 |
+ |
writeln(Outfile,'Raw Value = ',numeric.getRawValue,' Scale = ',numeric.getScale); |
219 |
+ |
numeric := NewNumeric(StrToBCD('9999.123456780')); |
220 |
+ |
writeln(Outfile,'Value from BCD = ',numeric.getAsString); |
221 |
+ |
writeln(Outfile,'Raw Value = ',numeric.getRawValue,' Scale = ',numeric.getScale); |
222 |
+ |
numeric := NumericFromRawValues(9999123456780,-6); |
223 |
+ |
writeln(Outfile,'Value from Raw Data = ',numeric.getAsString); |
224 |
+ |
writeln(Outfile,'Raw Value = ',numeric.getRawValue,' Scale = ',numeric.getScale); |
225 |
+ |
end; |
226 |
+ |
|
227 |
|
function TTest21.TestTitle: AnsiString; |
228 |
|
begin |
229 |
|
Result := 'Test 21: Exercise setting and getting of numeric data types'; |
241 |
|
Attachment := FirebirdAPI.CreateDatabase(Owner.GetNewDatabaseName,DPB); |
242 |
|
try |
243 |
|
Attachment.ExecImmediate([isc_tpb_write,isc_tpb_wait,isc_tpb_consistency],sqlCreateTable); |
244 |
+ |
ValidateStrToNumeric; |
245 |
+ |
ValidateNumericInterface; |
246 |
|
SetFloatTemplate('#,###.00000000'); |
247 |
|
UpdateDatabase(Attachment); |
248 |
|
QueryDatabase(Attachment); |