Strange problems on decimals - dangerous bug !!

Re: Strange problems on decimals - dangerous bug !!

Postby Antonio Linares » Sun Jan 18, 2015 7:24 pm

Marco,

In your example please change this line:

msginfo(str(88.456,10, Int( nDecimals ) )) && RETURN 88 !!!
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42203
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Strange problems on decimals - dangerous bug !!

Postby nageswaragunupudi » Sun Jan 18, 2015 7:35 pm

As you said you created the table with column as SHORTINT. This type is giving problems.
Create the column as INT and it works well. Please populate the data afresh. Please do not copy with SQL statements.

I tested with ADO and shared my observations with you.

Another advice: Use FWH Ado functions and ADO and you will not go wrong. I am afraid of other libraries.

I did not get any problem first because I used FWH library functions. I tried many times. What saved me was that I used FWH function to create the table, which used the correct datatype, ie INT and not SMALLINT.
Trust ADO and Trust FWH.
Regards

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

Re: Strange problems on decimals - dangerous bug !!

Postby nageswaragunupudi » Sun Jan 18, 2015 7:46 pm

This is a sample I used for testing with ADO and FWH Ado functions:
This works if Sqlite3 ODBC driver is installed.

Code: Select all  Expand view  RUN
function testsql3

   local oCn, oRs
   local nDecimals

   oCn      := FW_OpenAdoConnection( "test3.db" )
   if oCn:State < 1
      ? "fail"
      return nil
   endif

   TRY
      oCn:Execute( "DROP TABLE NUMDEC" )
   CATCH
   END

   // Create Table and populate data
   FWAdoCreateTable( "NUMDEC", { { "DATE",      'D', 8, 0 }, ;
                                 { "NDECIMALS", 'N', 2, 0 } }, oCn, .f. )

   oRs   := FW_OpenRecordSet( oCn, "NUMDEC" )
   oRs:AddNew( { "Date", "NDECIMALS" }, { Date(), 3 } )
   oRs:Close()

   // Open Table and Use data
   oRs         := FW_OpenRecordSet( oCn, "NUMDEC" )
   nDecimals   := oRs:Fields( "nDecimals" ):Value
   ? nDecimals, ValType( nDecimals )

   msginfo( Str( 88.456, 10, 3 ) )
   msginfo( Str( 88.456, 10, nDecimals ) )
   oRs:Close()
   oCn:Close()

return nil
 
Regards

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

Re: Strange problems on decimals - dangerous bug !!

Postby Marco Turco » Sun Jan 18, 2015 8:43 pm

Hi Rao,
I understand but SMALLINT runs well with xHarbour 1.2.1 rev 9656.
What did you change from that version to 1.2.3 rev build 20141106 to affect smallint ?
I know I can use ado but using a direct lib to access the db is quicker and it's a very long job to change and test anything on ado on any OS configuration,
do you think it could be possible to solve the problem on the xharbour side ? Sqlite is a great db, open source, and all C source code is avalable all of us.

It isn't a sqlite related problem, only an xharbour problem,
if we, software programmers are not sure anymore if xharbour manages any numeric value in a proper way and in any situation......
Last edited by Marco Turco on Sun Jan 18, 2015 9:10 pm, edited 3 times in total.
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Re: Strange problems on decimals - dangerous bug !!

Postby Marco Turco » Sun Jan 18, 2015 8:48 pm

Antonio Linares wrote:Marco,

In your example please change this line:

msginfo(str(88.456,10, Int( nDecimals ) )) && RETURN 88 !!!



It always return 88
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Re: Strange problems on decimals - dangerous bug !!

Postby Antonio Linares » Sun Jan 18, 2015 11:00 pm

Marco,

Is it working fine with Harbour ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42203
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Strange problems on decimals - dangerous bug !!

Postby Marco Turco » Mon Jan 19, 2015 7:51 am

Antonio Linares wrote:Marco,

Is it working fine with Harbour ?


I didn't try. Anyway we are using some 3rd parts components (eztwain, fastreport etc.) and there is a 15 pages thread on your forum with subject "Migrating to Harbour".... I don't think a migration is a question of hours :?
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Re: Strange problems on decimals - dangerous bug !!

Postby Antonio Linares » Mon Jan 19, 2015 9:51 am

Marco,

Do you use somewhere in your code SET DECIMALS TO ... ?

In my example xHarbour behaves ok, so its really strange that your code is failing...
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42203
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Strange problems on decimals - dangerous bug !!

Postby Marco Turco » Mon Jan 19, 2015 10:24 am

Hi, yes I have a SET DECIMAL TO 7
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Re: Strange problems on decimals - dangerous bug !!

Postby Marco Turco » Mon Jan 19, 2015 10:59 am

Hi Antonio,
I have tested the self contained sample with and without SET DECIMALS but the problem appear in any way.

Pls. find at http://109.228.12.120/softwaredistribut ... /test1.rar the self contained with also executable that show the problem.
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Re: Strange problems on decimals - dangerous bug !!

Postby cnavarro » Mon Jan 19, 2015 11:09 am

You have attempted to define the scope of the nDecimals variable?

Local ..
Static ..
etc
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6552
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Strange problems on decimals - dangerous bug !!

Postby Marco Turco » Mon Jan 19, 2015 11:19 am

Hi,
no I didn't. As you can see the self-contained is very minimal.

---

#include "fivewin.ch"

procedure start()

oSQLite := TSQLiteServer():New( "test.sql" )
If oSQLite:lError
msgStop( "error" )
RETURN
EndIf

cQuery:="SELECT * from t_tables;"
oQry:=oSQLite:Query(cQuery)
nDecimals:=oQry:aData[1,7]
oQry:End()
oSQLite:End()

msginfo(ndecimals) && return 3
msginfo(valtype(ndecimals)) && return N

msginfo(str(88.456,10,3)) && return 88.456
msginfo(str(88.456,10,nDecimals)) && RETURN 88 !!!



return
function gettemppath()
return("")
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Re: Strange problems on decimals - dangerous bug !!

Postby cnavarro » Mon Jan 19, 2015 11:25 am

Marco Turco wrote:Hi,
no I didn't. As you can see the self-contained is very minimal.

---

#include "fivewin.ch"

procedure start()

oSQLite := TSQLiteServer():New( "test.sql" )
If oSQLite:lError
msgStop( "error" )
RETURN
EndIf

cQuery:="SELECT * from t_tables;"
oQry:=oSQLite:Query(cQuery)
nDecimals:=oQry:aData[1,7]
oQry:End()
oSQLite:End()

msginfo(ndecimals) && return 3
msginfo(valtype(ndecimals)) && return N

msginfo(str(88.456,10,3)) && return 88.456
msginfo(str(88.456,10,nDecimals)) && RETURN 88 !!!



return
function gettemppath()
return("")



Add

Code: Select all  Expand view  RUN

#include "fivewin.ch"

procedure start()

Local ndecimals := 0    //

 
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6552
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Strange problems on decimals - dangerous bug !!

Postby Marco Turco » Mon Jan 19, 2015 11:42 am

Hi cnavarro,
I have tried but the problem is still in place.
msginfo(str(88.456,10,nDecimals)) Always return 88
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Re: Strange problems on decimals - dangerous bug !!

Postby sambomb » Mon Jan 19, 2015 1:44 pm

Change the name of the var, nTest_Decimals := 3

Code: Select all  Expand view  RUN

#include "fivewin.ch"

procedure start()
Local nTest_Decimals := 3

oSQLite := TSQLiteServer():New( "test.sql" )
If oSQLite:lError
msgStop( "error" )
RETURN
EndIf

cQuery:="SELECT * from t_tables;"
oQry:=oSQLite:Query(cQuery)
nTest_Decimals :=oQry:aData[1,7]
oQry:End()
oSQLite:End()

msginfo(nTest_Decimals ) && return 3
msginfo(valtype(nTest_Decimals )) && return N

msginfo(str(88.456,10,3)) && return 88.456
msginfo(str(88.456,10,nTest_Decimals )) && RETURN 88 !!!



return
function gettemppath()
return("")
 
Email: SamirSSabreu@gmail.com
xHarbour 1.2.3 + Fwhh 20.2
User avatar
sambomb
 
Posts: 388
Joined: Mon Oct 13, 2008 11:26 am
Location: Itaocara - RJ - Brasil

PreviousNext

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 34 guests