Page 2 of 3

Re: Strange problems on decimals - dangerous bug !!

Posted: Sun Jan 18, 2015 7:24 pm
by Antonio Linares
Marco,

In your example please change this line:

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

Re: Strange problems on decimals - dangerous bug !!

Posted: Sun Jan 18, 2015 7:35 pm
by nageswaragunupudi
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.

Re: Strange problems on decimals - dangerous bug !!

Posted: Sun Jan 18, 2015 7:46 pm
by nageswaragunupudi
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

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
 

Re: Strange problems on decimals - dangerous bug !!

Posted: Sun Jan 18, 2015 8:43 pm
by Marco Turco
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......

Re: Strange problems on decimals - dangerous bug !!

Posted: Sun Jan 18, 2015 8:48 pm
by Marco Turco
Antonio Linares wrote:Marco,

In your example please change this line:

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



It always return 88

Re: Strange problems on decimals - dangerous bug !!

Posted: Sun Jan 18, 2015 11:00 pm
by Antonio Linares
Marco,

Is it working fine with Harbour ?

Re: Strange problems on decimals - dangerous bug !!

Posted: Mon Jan 19, 2015 7:51 am
by Marco Turco
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 :?

Re: Strange problems on decimals - dangerous bug !!

Posted: Mon Jan 19, 2015 9:51 am
by Antonio Linares
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...

Re: Strange problems on decimals - dangerous bug !!

Posted: Mon Jan 19, 2015 10:24 am
by Marco Turco
Hi, yes I have a SET DECIMAL TO 7

Re: Strange problems on decimals - dangerous bug !!

Posted: Mon Jan 19, 2015 10:59 am
by Marco Turco
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.

Re: Strange problems on decimals - dangerous bug !!

Posted: Mon Jan 19, 2015 11:09 am
by cnavarro
You have attempted to define the scope of the nDecimals variable?

Local ..
Static ..
etc

Re: Strange problems on decimals - dangerous bug !!

Posted: Mon Jan 19, 2015 11:19 am
by Marco Turco
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("")

Re: Strange problems on decimals - dangerous bug !!

Posted: Mon Jan 19, 2015 11:25 am
by cnavarro
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


#include "fivewin.ch"

procedure start()

Local ndecimals := 0    //

 

Re: Strange problems on decimals - dangerous bug !!

Posted: Mon Jan 19, 2015 11:42 am
by Marco Turco
Hi cnavarro,
I have tried but the problem is still in place.
msginfo(str(88.456,10,nDecimals)) Always return 88

Re: Strange problems on decimals - dangerous bug !!

Posted: Mon Jan 19, 2015 1:44 pm
by sambomb
Change the name of the var, nTest_Decimals := 3

Code: Select all | Expand


#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("")