Result: -729,6744
on every 64 bit release
SQL_INT64:
begin
if VSQLVar^.sqlscale = 0 then
li := AParam.AsLargeInt
else if AParam.DataType = ftFMTBcd then
li := AParam.AsFMTBCD * IntPower10(-VSQLVar^.sqlscale)
else
li := Round(AParam.AsCurrency * IntPower10(-VSQLVar^.sqlscale));
Move(li, VSQLVar^.SQLData^, VSQLVar^.SQLLen);
end;
var
q : TSQLQuery;
begin
Result := True;
q := TSQLQuery.Create(nil);
try
q.Database := dbconn;
q.SQL.Text := 'UPDATE OR INSERT INTO ' + oggetto.TableName + ' (' + oggetto.FieldID + ', ' + oggetto.FieldCurrency + ', ' +
oggetto.FieldDecimal + ', ' + oggetto.FieldDouble + ') ' +
'VALUES(1, :par0, :par1, :par2) ' +
'MATCHING (' + oggetto.FieldID + ') ';
q.Params[0].AsFMTBCD := currToBCD(oggetto.InputValue);
q.Params[1].AsCurrency := oggetto.InputValue;
q.Params[2].AsFloat := oggetto.InputValue;
q.ExecSql;
dbconn.Transaction.Commit;
q.SQL.Text := 'SELECT ' + oggetto.FieldCurrency + ' as c0, ' + oggetto.FieldDecimal + ', ' + oggetto.FieldDouble + ' ' +
'FROM ' + oggetto.TableName + ' ' +
'WHERE ' + oggetto.FieldID + ' = 1 ';
q.Open;
if not(q.EOF) then
begin
ShowMessage('Query executed successfully: ' + LineEnding +
'DECIMAL ' + CurrToStrF(q.Fields[0].asCurrency, ffGeneral, 4) + LineEnding +
'NUMERIC ' + CurrToStrF(q.Fields[1].asCurrency, ffGeneral, 4) + LineEnding +
'Double ' + CurrToStrF(q.Fields[2].asCurrency, ffGeneral, 2));
end;
q.Close;
except on ex : Exception do
begin
Result := False;
dbconn.Transaction.Rollback;
Application.MessageBox(PChar('Unexpected error while doing the query:' + LineEnding +
ex.Message), 'Error', MB_OK + MB_ICONERROR);
end;
end;
q.Free;
q.Params[0].DataType:=ftFMTBcd;
q.Params[0].NumericScale:=8;
q.Params[0].Precision:=18;
q.Params[0].Value := oggetto.InputValue;
This change save correct data. NumericScale and Precision is not needed work without this two lines. But changing last line to AsFloat or AsCurrency is not OK.function IntPower10(e: integer): double;
const PreComputedPower10: array[0..9] of integer = (1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000);
var n: integer;
begin
n := abs(e); //exponent can't be greater than 18
if n <= 9 then
Result := PreComputedPower10[n]
else
Result := PreComputedPower10[9] * PreComputedPower10[n-9];
if e < 0 then
Result := 1 / Result;
end;