FWMARIA FIELDPUT

FWMARIA FIELDPUT

Postby cjcardoza » Fri Jun 05, 2020 1:29 am

Estimados FiveWiner's
Tengo un inconveniente que se me presenta aleatoriamente con diferentes valores al grabar en MySql mediante Fieldput() cuando grabo valores numéricos mediante un producto o mediante una variable este valor grabado es diferente al producto calculado, en el ejemplo que le detallo a continuación:
::vGet:nPrecio:=230
::vGet:nPctdes:=10/100
::vGet:nImpDes:= ::vGet:nPrecio * ::vGet:nPctdes
oMovimdet:Append()
oMovimdet:FieldPut("impdes" , ::vGet:nImpDes )
oMovimdet:save()
*** yo muestro la variable mediante un msginfo(::vGet:nImpDes) y me muestra 23
*** pero en la variable "impdes" graba 22
*** por mas intentos de otras maneras de grabar la variable y sin resultados me vi forzado a ejecutar el siguiente Query para q grabe la informacion correctamente
oConex:SqlQuery("UPDATE movimdet SET igv="+ALLTRIM(STR(::vGet:nIgv))+",impdes="+ALLTRIM(STR(::vGet:nImpDes))+;
" WHERE tipcpg='"+::vGet:cTipCpg+"' AND sercpg='"+ALLTRIM(::vGet:cSerCpg)+"' AND nrocpg="+ALLTRIM(STR(::vGet:nNroCpg))+" AND correl="+ALLTRIM(STR(::vGet:nCorrel)))

Agradezco su atención y espero contar con su apoyo

actualmente estoy trabajando con FW1907 + BCC7 + MYSQL 5.5
cjcardoza
 
Posts: 31
Joined: Thu Jul 13, 2006 12:20 am
Location: Lima - Peru

Re: FWMARIA FIELDPUT

Postby Armando » Sat Jun 06, 2020 3:06 pm

cjcardoza:

Intenta redondeando el resultado

Code: Select all  Expand view

::vGet:nImpDes:= ROUND(::vGet:nPrecio * ::vGet:nPctdes,2)
 


Saludos
SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
User avatar
Armando
 
Posts: 3061
Joined: Fri Oct 07, 2005 8:20 pm
Location: Toluca, México

Re: FWMARIA FIELDPUT

Postby cjcardoza » Sun Jun 21, 2020 12:38 am

Armando
No es problema de redondeo, porque la variable que contiene el resultado es de tipo double(12,2) deberia grabar sin inconveniente.
Es un problema aleatorio que se me presenta de tiempo en tiempo con FWMARIA y que uso en otro sistema con TMYSQL y graba correctamente, en este ejemplo que tengo error es con los numeros que muestro.
cjcardoza
 
Posts: 31
Joined: Thu Jul 13, 2006 12:20 am
Location: Lima - Peru

Re: FWMARIA FIELDPUT

Postby jacgsoft » Wed Jun 24, 2020 8:01 pm

Carlos,

Usa Procedimientos Almacenados, para grabar información, y así te olvidas, si trabajas con Ms-sql server, MySql, MariaDb y cualquier base de datos. :D :D
User avatar
jacgsoft
 
Posts: 104
Joined: Fri Nov 24, 2006 9:03 pm
Location: Lima - Peru

Re: FWMARIA FIELDPUT

Postby nageswaragunupudi » Thu Jun 25, 2020 2:41 am

Intenta redondeando el resultado

Not necessary. The method FieldPut() rounds off the value to the number of decimal places specified for the field.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10248
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: FWMARIA FIELDPUT

Postby nageswaragunupudi » Thu Jun 25, 2020 2:46 am

cjcardoza wrote:Estimados FiveWiner's
Tengo un inconveniente que se me presenta aleatoriamente con diferentes valores al grabar en MySql mediante Fieldput() cuando grabo valores numéricos mediante un producto o mediante una variable este valor grabado es diferente al producto calculado, en el ejemplo que le detallo a continuación:
::vGet:nPrecio:=230
::vGet:nPctdes:=10/100
::vGet:nImpDes:= ::vGet:nPrecio * ::vGet:nPctdes
oMovimdet:Append()
oMovimdet:FieldPut("impdes" , ::vGet:nImpDes )
oMovimdet:save()
*** yo muestro la variable mediante un msginfo(::vGet:nImpDes) y me muestra 23
*** pero en la variable "impdes" graba 22
*** por mas intentos de otras maneras de grabar la variable y sin resultados me vi forzado a ejecutar el siguiente Query para q grabe la informacion correctamente
oConex:SqlQuery("UPDATE movimdet SET igv="+ALLTRIM(STR(::vGet:nIgv))+",impdes="+ALLTRIM(STR(::vGet:nImpDes))+;
" WHERE tipcpg='"+::vGet:cTipCpg+"' AND sercpg='"+ALLTRIM(::vGet:cSerCpg)+"' AND nrocpg="+ALLTRIM(STR(::vGet:nNroCpg))+" AND correl="+ALLTRIM(STR(::vGet:nCorrel)))

Agradezco su atención y espero contar con su apoyo

actualmente estoy trabajando con FW1907 + BCC7 + MYSQL 5.5


We tried our best the reproduce the problem at our end. We might have tried more than 200 times. We did not get this error and every time the value is stored correctly in the database.
We reviewed the code also carefully and there is no scope for any such errors.

We help you to reproduce the error.

This is one of the test programs we used.
Code: Select all  Expand view
#include "fivewin.ch"

function Main()

   local oCn, cSql, oRs
   local nPrice, nPctdes, nImpdes
   local oDlg, oFont, oGet, oBrw, oBtn

   SetGetColorFocus()

TEXT INTO cSql
 CREATE TABLE numtest (
 id INT  AUTO_INCREMENT PRIMARY KEY,
 price   DECIMAL( 12, 2 ),
 impdes  DECIMAL( 10, 2 ),
 impdesd DOUBLE,
 impdesf FLOAT
 )
ENDTEXT

   oCn   := FW_DemoDB( 6 )
   if oCn == nil
      ? "Connect Fail"
      return nil
   endif

   if oCn:TableExists( "numtest" )
      oCn:DropTable( "numtest" )
   endif
   oCn:Execute( cSql )

   nPrice := nImpDes := nPctDes := 0.00

   oRs   := oCn:numtest

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
   DEFINE DIALOG oDlg SIZE 800,300 PIXEL TRUEPIXEL TITLE FWVERSION FONT oFont

   @ 30, 20 SAY "Price : " GET oGet VAR nPrice PICTURE "99999.99" SIZE 180,24 PIXEL OF oDlg RIGHT
   oGet:bValid := <||
      nPctdes  := 10/100
      nImpdes  := nPrice * nPctdes

      oRs:Append()
      oRs:price   := nPrice
      oRs:impdes  := nImpdes
      oRs:impdesd := nImpdes
      oRs:impdesf := nImpdes
      oRs:Save()

      oDlg:Update()
      return .t.
      >

   @ 32,400 SAY { || nImpDes } PICTURE "ImpDes : 99999.99" SIZE 300,24 PIXEL OF oDlg UPDATE

   @ 70, 20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg DATASOURCE oRs AUTOCOLS ;
      CELL LINES NOBORDER FOOTERS UPDATE

   oBrw:cFooters := { "INT", "DECIMAL(12,2)", "DECIMAL(10,2)", "DOUBLE", "FLOAT" }
   oBrw:CreateFromCode()

   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oFont

   oRs:Close()
   oCn:Close()

return nil
 


Please try this program and see if you see any error.

Image
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10248
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 75 guests