52 |
|
private |
53 |
|
procedure UpdateDatabase(Attachment: IAttachment); |
54 |
|
procedure QueryDatabase(Attachment: IAttachment); |
55 |
+ |
procedure ValidateStrToNumeric; |
56 |
|
public |
57 |
|
function TestTitle: AnsiString; override; |
58 |
|
procedure RunTest(CharSet: AnsiString; SQLDialect: integer); override; |
62 |
|
|
63 |
|
implementation |
64 |
|
|
65 |
+ |
uses IBUtils; |
66 |
+ |
|
67 |
|
const |
68 |
|
sqlCreateTable = |
69 |
|
'Create Table TestData ('+ |
124 |
|
Params[1].AsString := '1.0'; |
125 |
|
Params[2].AsString := '10.'; |
126 |
|
Params[3].AsString := '2.3E-2'; |
127 |
< |
Params[4].AsString := '0'; |
127 |
> |
Params[4].AsString := '11e-4'; |
128 |
|
Params[5].AsString := '2.33456E2'; |
129 |
|
end; |
130 |
|
Statement.Execute; |
157 |
|
ReportResults(Statement); |
158 |
|
end; |
159 |
|
|
160 |
+ |
procedure TTest21.ValidateStrToNumeric; |
161 |
+ |
const |
162 |
+ |
TestValues: array of string = ['1234.567','-765.4321','0.1','0.01','+123', |
163 |
+ |
'1.23456E308','-1.2e-02','10.','.12', '0.12', |
164 |
+ |
'1.2E1.2', '1,000', '1e1e1', '1.2+3']; {bad syntax} |
165 |
+ |
var |
166 |
+ |
i: integer; |
167 |
+ |
aValue: Int64; |
168 |
+ |
aScale: integer; |
169 |
+ |
begin |
170 |
+ |
for i := 0 to Length(TestValues) - 1 do |
171 |
+ |
begin |
172 |
+ |
if TryStrToNumeric(TestValues[i],aValue,aScale) then |
173 |
+ |
begin |
174 |
+ |
writeln(Outfile,TestValues[i],' parsed to ',aValue,' scale = ',aScale); |
175 |
+ |
writeln(Outfile,'As Float = ',NumericToDouble(aValue,aScale)); |
176 |
+ |
end |
177 |
+ |
else |
178 |
+ |
writeln(Outfile,'Parsing of ',TestValues[i],' failed'); |
179 |
+ |
end; |
180 |
+ |
end; |
181 |
+ |
|
182 |
|
function TTest21.TestTitle: AnsiString; |
183 |
|
begin |
184 |
|
Result := 'Test 21: Exercise setting and getting of numeric data types'; |
196 |
|
Attachment := FirebirdAPI.CreateDatabase(Owner.GetNewDatabaseName,DPB); |
197 |
|
try |
198 |
|
Attachment.ExecImmediate([isc_tpb_write,isc_tpb_wait,isc_tpb_consistency],sqlCreateTable); |
199 |
+ |
ValidateStrToNumeric; |
200 |
|
SetFloatTemplate('#,###.00000000'); |
201 |
|
UpdateDatabase(Attachment); |
202 |
|
QueryDatabase(Attachment); |