oracle - ClientDataSet TBCDField rounding -
i'm using delphi 5 + bde + oracle. have following function:
class function tclientdatasetfactory.getclientdataset( const qrygen: tdataset): tclientdataset; var dspdados: tdatasetprovider; begin result := nil; try try result := tclientdataset.create(nil); dspdados := tdatasetprovider.create(result); dspdados.dataset := qrygen; qrygen.active := true; qrygen.first; result.data := dspdados.data; result.first; except on e: exception begin raise; end; end; end; end;
so, when run this:
var qrygen: tquery; cdsgen: tclientdataset; begin qrygen := nil; try try qrygen := criaquery(); qrygen.sql.text := 'select sum(total) total mytable'; cdsgen := tclientdatasetfactory.getclientdataset(qrygen); showmessagefmt('total: %f', [cdsgen.fieldbyname('total').asfloat]); except on e: exception begin raise; end; end; if assigned(qrygen) freeandnil(qrygen); end; end;
i got "159,00" but, if run this:
showmessagefmt('total: %f', [qrygen.fieldbyname('total').asfloat]);
i got "159,25".
can me?
i solved problem solution.
type tinternalquery = class(tquery) protected procedure internalinitfielddefs; override; public constructor create(aowner: tcomponent; const qrygen: tquery); reintroduce; end; constructor tinternalquery.create(aowner: tcomponent; const qrygen: tquery); var intcont: integer; begin inherited create(aowner); self.databasename := qrygen.databasename; self.updateobject := qrygen.updateobject; self.sql.text := qrygen.sql.text; intcont := 0 self.paramcount - 1 begin self.params[intcont].value := qrygen.params[intcont].value; end; end; procedure tinternalquery.internalinitfielddefs; var intcont: integer; begin inherited internalinitfielddefs; intcont := 0 fielddefs.count - 1 begin if (fielddefs[intcont].size = 0) , (fielddefs[intcont].datatype = ftbcd) begin fielddefs[intcont].precision := 64; fielddefs[intcont].size := 32; end; end; end;
the problem ((fielddefs[intcont].size = 0) , (fielddefs[intcont].datatype = ftbcd)). when clientdataset created, field truncated, because when oracle has function "sum(total)" result field created size 0, clientdataset handle field integer field.
Comments
Post a Comment