2422 |
|
Changed; |
2423 |
|
end; |
2424 |
|
|
2425 |
+ |
function TryStrToNumeric(S: Ansistring; out Value: int64; out scale: integer): boolean; |
2426 |
+ |
var i: integer; |
2427 |
+ |
ds: integer; |
2428 |
+ |
begin |
2429 |
+ |
Result := false; |
2430 |
+ |
ds := 0; |
2431 |
+ |
S := Trim(S); |
2432 |
+ |
{$IF declared(DefaultFormatSettings)} |
2433 |
+ |
with DefaultFormatSettings do |
2434 |
+ |
{$ELSE} |
2435 |
+ |
{$IF declared(FormatSettings)} |
2436 |
+ |
with FormatSettings do |
2437 |
+ |
{$IFEND} |
2438 |
+ |
{$IFEND} |
2439 |
+ |
begin |
2440 |
+ |
{ThousandSeparator not allowed as by Delphi specs} |
2441 |
+ |
if (ThousandSeparator <> DecimalSeparator) and |
2442 |
+ |
(Pos(ThousandSeparator, S) <> 0) then |
2443 |
+ |
Exit; |
2444 |
+ |
|
2445 |
+ |
for i := length(S) downto 1 do |
2446 |
+ |
begin |
2447 |
+ |
if S[i] = AnsiChar(DecimalSeparator) then |
2448 |
+ |
begin |
2449 |
+ |
if ds <> 0 then Exit; {only one allowed} |
2450 |
+ |
ds := i-1; |
2451 |
+ |
system.Delete(S,i,1); |
2452 |
+ |
end |
2453 |
+ |
else |
2454 |
+ |
if (i > 1) and (S[i] in ['+','-']) then |
2455 |
+ |
Exit |
2456 |
+ |
else |
2457 |
+ |
if not (S[i] in ['0'..'9']) then |
2458 |
+ |
Exit; {bad character} |
2459 |
+ |
|
2460 |
+ |
end; |
2461 |
+ |
if ds = 0 then |
2462 |
+ |
scale := 0 |
2463 |
+ |
else |
2464 |
+ |
scale := ds - Length(S); |
2465 |
+ |
Result := TryStrToInt64(S,Value); |
2466 |
+ |
end; |
2467 |
+ |
end; |
2468 |
+ |
|
2469 |
|
var b: IBlob; |
2470 |
|
dt: TDateTime; |
2471 |
|
timezone: AnsiString; |
2472 |
+ |
{$ifdef FPC_HAS_TYPE_EXTENDED} |
2473 |
+ |
FloatValue: Extended; |
2474 |
+ |
{$else} |
2475 |
|
FloatValue: Double; |
2476 |
+ |
{$endif} |
2477 |
|
Int64Value: Int64; |
2478 |
|
BCDValue: TBCD; |
2479 |
|
aScale: integer; |
2511 |
|
SQL_SHORT, |
2512 |
|
SQL_LONG, |
2513 |
|
SQL_INT64: |
2514 |
< |
{If the string contains an integer then convert and set directly} |
2467 |
< |
if TryStrToInt64(Value,Int64Value) then |
2468 |
< |
SetAsInt64(Int64Value) |
2469 |
< |
else |
2470 |
< |
if getColMetaData.getScale = 0 then {integer expected but non-integer string} |
2514 |
> |
if TryStrToNumeric(Value,Int64Value,aScale) then |
2515 |
|
begin |
2516 |
< |
if TryStrToFloat(Value,FloatValue) then |
2517 |
< |
{truncate it if the column is limited to an integer} |
2474 |
< |
SetAsInt64(Trunc(FloatValue)) |
2516 |
> |
if aScale = 0 then |
2517 |
> |
SetAsInt64(Int64Value) |
2518 |
|
else |
2519 |
< |
DoSetString; |
2519 |
> |
SetAsNumeric(Int64Value,aScale); |
2520 |
|
end |
2521 |
|
else |
2522 |
|
if TryStrToFloat(Value,FloatValue) then |
2523 |
< |
begin |
2481 |
< |
aScale := getColMetaData.getScale; |
2482 |
< |
{Set as int64 with adjusted scale} |
2483 |
< |
SetAsNumeric(AdjustScaleFromDouble(FloatValue,aScale),aScale) |
2484 |
< |
end |
2523 |
> |
SetAsDouble(FloatValue) |
2524 |
|
else |
2525 |
|
DoSetString; |
2526 |
|
|