Strange problems on decimals - dangerous bug !!
- Antonio Linares
- Site Admin
- Posts: 42595
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 38 times
- Been thanked: 86 times
- Contact:
Re: Strange problems on decimals - dangerous bug !!
Marco,
In your example please change this line:
msginfo(str(88.456,10, Int( nDecimals ) )) && RETURN 88 !!!
In your example please change this line:
msginfo(str(88.456,10, Int( nDecimals ) )) && RETURN 88 !!!
- nageswaragunupudi
- Posts: 10729
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Been thanked: 10 times
- Contact:
Re: Strange problems on decimals - dangerous bug !!
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.
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
G. N. Rao.
Hyderabad, India
- nageswaragunupudi
- Posts: 10729
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Been thanked: 10 times
- Contact:
Re: Strange problems on decimals - dangerous bug !!
This is a sample I used for testing with ADO and FWH Ado functions:
This works if Sqlite3 ODBC driver is installed.
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
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
- Marco Turco
- Posts: 858
- Joined: Fri Oct 07, 2005 12:00 pm
- Location: London
- Contact:
Re: Strange problems on decimals - dangerous bug !!
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......
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
Marco Turco
SOFTWARE XP LLP
- Marco Turco
- Posts: 858
- Joined: Fri Oct 07, 2005 12:00 pm
- Location: London
- Contact:
Re: Strange problems on decimals - dangerous bug !!
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
Marco Turco
SOFTWARE XP LLP
- Antonio Linares
- Site Admin
- Posts: 42595
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 38 times
- Been thanked: 86 times
- Contact:
- Marco Turco
- Posts: 858
- Joined: Fri Oct 07, 2005 12:00 pm
- Location: London
- Contact:
Re: Strange problems on decimals - dangerous bug !!
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
Marco Turco
SOFTWARE XP LLP
- Antonio Linares
- Site Admin
- Posts: 42595
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 38 times
- Been thanked: 86 times
- Contact:
Re: Strange problems on decimals - dangerous bug !!
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...
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...
- Marco Turco
- Posts: 858
- Joined: Fri Oct 07, 2005 12:00 pm
- Location: London
- Contact:
Re: Strange problems on decimals - dangerous bug !!
Hi, yes I have a SET DECIMAL TO 7
Best Regards,
Marco Turco
SOFTWARE XP LLP
Marco Turco
SOFTWARE XP LLP
- Marco Turco
- Posts: 858
- Joined: Fri Oct 07, 2005 12:00 pm
- Location: London
- Contact:
Re: Strange problems on decimals - dangerous bug !!
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.
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
Marco Turco
SOFTWARE XP LLP
Re: Strange problems on decimals - dangerous bug !!
You have attempted to define the scope of the nDecimals variable?
Local ..
Static ..
etc
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
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
- Marco Turco
- Posts: 858
- Joined: Fri Oct 07, 2005 12:00 pm
- Location: London
- Contact:
Re: Strange problems on decimals - dangerous bug !!
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("")
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
Marco Turco
SOFTWARE XP LLP
Re: Strange problems on decimals - dangerous bug !!
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 //
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
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
- Marco Turco
- Posts: 858
- Joined: Fri Oct 07, 2005 12:00 pm
- Location: London
- Contact:
Re: Strange problems on decimals - dangerous bug !!
Hi cnavarro,
I have tried but the problem is still in place.
msginfo(str(88.456,10,nDecimals)) Always return 88
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
Marco Turco
SOFTWARE XP LLP
Re: Strange problems on decimals - dangerous bug !!
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("")
Email: SamirSSabreu@gmail.com
xHarbour 1.2.3 + Fwhh 20.2
xHarbour 1.2.3 + Fwhh 20.2