Problem to update number with decimals in SQLite

Discussion forum about all things Team Developer 5.x and 6.x
LarsAke
Sweden
Posts: 14
Joined: 23 Nov 2017, 15:59
Location: Stockholm/Sweden

Problem to update number with decimals in SQLite

Post by LarsAke » 18 Jan 2019, 17:16

I am trying to use a SQLite database with TD 6.2 but I have some problem to update decimals in a number.
I have the datatype decimal in the database and use the SQLite3_API_UNICODE.apl
Can somebody help me?

Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 2924
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

Re: Problem to update number with decimals in SQLite

Post by Dave Rabelink » 19 Jan 2019, 08:27

What is the exact problem you have?

Please post a small sample here to show what you would like to achieve.
Regards,
Dave Rabelink

Image
Articles and information on Team Developer Tips & Tricks Wiki
Download samples, documents and resources from TD Sample Vault
Videos on TDWiki YouTube Channel

LarsAke
Sweden
Posts: 14
Joined: 23 Nov 2017, 15:59
Location: Stockholm/Sweden

Re: Problem to update number with decimals in SQLite

Post by LarsAke » 21 Jan 2019, 14:18

The problem is that I can´t save decimals in a number but just the integer.
I saw in your program SQLite3_CountriesFlags_Sample and database countries that you save numbers with decimals in strings in the database, is that the "solution"/work around?

Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 2924
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

Re: Problem to update number with decimals in SQLite

Post by Dave Rabelink » 21 Jan 2019, 17:12

Use the double functions:

Code: Select all

! On insert or update...
Set nSalary = 24500.25
Call SQLite_BindDouble_Name( nStmtPtr, ":SALARY", nSalary )
...
! On select...
nSalary	= SQLite_ColumnDouble_Name( nStmtPtr, "salary" )


LarsAke wrote:
21 Jan 2019, 14:18
...save numbers with decimals in strings in the database, is that the "solution"/work around?
SQLite uses a dynamic type system. So it is indeed possible to pass a string which will be interpreted as a numeric value.

Read this page which explains Type Affinity:

https://www.sqlite.org/datatype3.html#type_affinity
Regards,
Dave Rabelink

Image
Articles and information on Team Developer Tips & Tricks Wiki
Download samples, documents and resources from TD Sample Vault
Videos on TDWiki YouTube Channel

LarsAke
Sweden
Posts: 14
Joined: 23 Nov 2017, 15:59
Location: Stockholm/Sweden

Re: Problem to update number with decimals in SQLite

Post by LarsAke » 22 Jan 2019, 09:29

Thank you Dave it sure works when you do right ;)
I did try the BindDouble but I forgot to read with ColumnDouble.
Thanks again!

Return to “General Discussion”

Who is online

Users browsing this forum: [Ccbot] and 0 guests