FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Strange problems on decimals - dangerous bug !!
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Strange problems on decimals - dangerous bug !!
Posted: Sun Jan 18, 2015 07: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
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Strange problems on decimals - dangerous bug !!
Posted: Sun Jan 18, 2015 07: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
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Strange problems on decimals - dangerous bug !!
Posted: Sun Jan 18, 2015 07: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 (fw): Select all Collapse
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
Posts: 858
Joined: Fri Oct 07, 2005 12:00 PM
Re: Strange problems on decimals - dangerous bug !!
Posted: Sun Jan 18, 2015 08: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......

Best Regards,



Marco Turco

SOFTWARE XP LLP
Posts: 858
Joined: Fri Oct 07, 2005 12:00 PM
Re: Strange problems on decimals - dangerous bug !!
Posted: Sun Jan 18, 2015 08: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
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Strange problems on decimals - dangerous bug !!
Posted: Sun Jan 18, 2015 11:00 PM

Marco,

Is it working fine with Harbour ?

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 858
Joined: Fri Oct 07, 2005 12:00 PM
Re: Strange problems on decimals - dangerous bug !!
Posted: Mon Jan 19, 2015 07: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
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Strange problems on decimals - dangerous bug !!
Posted: Mon Jan 19, 2015 09: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
Posts: 858
Joined: Fri Oct 07, 2005 12:00 PM
Re: Strange problems on decimals - dangerous bug !!
Posted: Mon Jan 19, 2015 10:24 AM

Hi, yes I have a SET DECIMAL TO 7

Best Regards,



Marco Turco

SOFTWARE XP LLP
Posts: 858
Joined: Fri Oct 07, 2005 12:00 PM
Re: Strange problems on decimals - dangerous bug !!
Posted: 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
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Strange problems on decimals - dangerous bug !!
Posted: 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
Posts: 858
Joined: Fri Oct 07, 2005 12:00 PM
Re: Strange problems on decimals - dangerous bug !!
Posted: 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( &quot;test.sql&quot; )
If oSQLite:lError
    msgStop( &quot;error&quot; )
    RETURN
EndIf

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

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

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



return

function gettemppath()
return("")

Best Regards,



Marco Turco

SOFTWARE XP LLP
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Strange problems on decimals - dangerous bug !!
Posted: 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 (fw): Select all Collapse
#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
Posts: 858
Joined: Fri Oct 07, 2005 12:00 PM
Re: Strange problems on decimals - dangerous bug !!
Posted: 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
Posts: 389
Joined: Mon Oct 13, 2008 11:26 AM
Re: Strange problems on decimals - dangerous bug !!
Posted: Mon Jan 19, 2015 01:44 PM
Change the name of the var, nTest_Decimals := 3

Code (fw): Select all Collapse
#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