Recent

Author Topic: Float truncated in SQLite  (Read 10870 times)

Cigydd

  • New Member
  • *
  • Posts: 15
  • Programming for fun
    • My GitHub
Float truncated in SQLite
« on: September 30, 2009, 06:23:13 pm »
Hi everybody,

I experience troubles using SQLite query. :'(

Accessing fields defined as real in SQLite, the stored values get truncated to whole numbers (integers).

Lazarus 0.9.27/fpc 2.2.2, Laz. 0.9.26.2.

Is there someone who would know how do I need to define the field in SQLite to get real floating point values? Is this a bug or not? Please help me.
Cigydd Bach

davesimplewear

  • Sr. Member
  • ****
  • Posts: 306
    • Davids Freeware
Re: Float truncated in SQLite
« Reply #1 on: October 01, 2009, 12:13:32 am »
One way is to use the numeric field, define the numbers by numeric(6,2) for example for currency operations or change either of those values to suit your needs or use float instead of real.
All things considered insanity seems the best option

Cigydd

  • New Member
  • *
  • Posts: 15
  • Programming for fun
    • My GitHub
Re: Float truncated in SQLite
« Reply #2 on: October 01, 2009, 11:59:54 am »
Thank you :)
I think that float also gets truncated. But I'll test it.
Fields defined as numeric(x,y) get divided by 10,000. I can only work it around by multiplying the values. Again, is it a bug or not?
Cigydd Bach

Cigydd

  • New Member
  • *
  • Posts: 15
  • Programming for fun
    • My GitHub
Re: Float truncated in SQLite
« Reply #3 on: October 01, 2009, 04:06:46 pm »
I have already tested it. Changed all real fields to floats but still everything gets truncated.  :(
« Last Edit: October 01, 2009, 04:09:04 pm by Cigydd »
Cigydd Bach

Cigydd

  • New Member
  • *
  • Posts: 15
  • Programming for fun
    • My GitHub
Re: Float truncated in SQLite
« Reply #4 on: October 02, 2009, 01:14:23 pm »
I think it's the regional setting. We have a decimal comma instead of point. I send the numbers with the comma to the SQL command and so it becomes truncated. So it has a merely prosaic reason.
Excuse me for annoying.
Cigydd Bach

Cigydd

  • New Member
  • *
  • Posts: 15
  • Programming for fun
    • My GitHub
Re: Float truncated in SQLite
« Reply #5 on: October 02, 2009, 03:34:58 pm »
Strangely enough, it still persists, even when I use the decimal point.
Edit:
And even strangelier, it's gone. Sorry for the noise.
« Last Edit: October 02, 2009, 04:32:58 pm by Cigydd »
Cigydd Bach

clauslack

  • Sr. Member
  • ****
  • Posts: 275
Re: Float truncated in SQLite
« Reply #6 on: October 03, 2009, 03:52:44 pm »
I have a similar problem.
In what control do you see the number truncated ?

With a SQL Select to Firebird Database, the float field in TDBEdit  show only 2 digits(60), but in TDBGrid show fine the number.(606)

For me is TDBEdit  issue,

Under Lazarus 0.9.29 svn 21445. fpc 2.3.1 svn 13383.

I will do more check with the last lazarus svn for report in bugtracker.
Regards

Cigydd

  • New Member
  • *
  • Posts: 15
  • Programming for fun
    • My GitHub
Re: Float truncated in SQLite
« Reply #7 on: October 03, 2009, 04:41:37 pm »
For me, the truncated numbers were only got from TQuerys and saved into a log file. No specific control. In my case it was my mistake - now I'm aware that the most probable cause was that I didn't convert the numbers from decimal comma to decimal point.
Cigydd Bach

clauslack

  • Sr. Member
  • ****
  • Posts: 275
Re: Float truncated in SQLite
« Reply #8 on: October 03, 2009, 05:35:02 pm »
In my case the problem is not decimal comma or decimal point.
DBEdit show only 2 digits after
-
SQLTransaction.Commit
SQLTransaction.StartTransaction.
--
DBGrid in the same transaction that DBEdit show fine the float number.

I don't know if is a SQLdb issue(fpc) or TDBEdit issue(LCL).
I will do more test.