Recent

Author Topic: SQLITE3: TSQLQuery fails when using Params for float data (aarch64)  (Read 1361 times)

apeoperaio

  • Sr. Member
  • ****
  • Posts: 269
I have an issue when using TSQLQuery to insert float data in a table using Params (on aarch64).

I attached a sample project, where TSQLQuery simply execute an insert statement (works) and perform insert using Params (does not work).
In order to test it just replace
  dbfile:= 'yourfilename';
with your filename.

Is it a known issue?

Lazarus 2.2.7 (rev lazarus_2_2_6-1-gada7a90f86) FPC 3.2.2 aarch64-darwin-cocoa

rvk

  • Hero Member
  • *****
  • Posts: 5481
Re: SQLITE3: TSQLQuery fails when using Params for float data (aarch64)
« Reply #1 on: March 16, 2023, 01:10:06 pm »
I attached a sample project, where TSQLQuery simply execute an insert statement (works) and perform insert using Params (does not work).
What does "does not work" mean?
Do you get an error?
Or does it do nothing (no error, no messages) and add nothing?

BTW shouldn't you use a sqlq.Prepare; after assigning sqlq.SQL.Text and before sqlq.ExecSQL, to let the program know what parameters there are?

apeoperaio

  • Sr. Member
  • ****
  • Posts: 269
Re: SQLITE3: TSQLQuery fails when using Params for float data (aarch64)
« Reply #2 on: March 16, 2023, 01:44:50 pm »
It does not work in the sense that the float value is not inserted in the table.
When I use the SQL statement:

Code: Pascal  [Select][+][-]
  1. sqlq.SQL.Text:= 'INSERT INTO DATA (int_value, float_value, str_value) values ("10", "1.3", "str1")';

I get 3 values in the table
101.3str1

while when I use:
Code: Pascal  [Select][+][-]
  1.     sqlq.SQL.Text:= 'INSERT INTO DATA (int_value, float_value, str_value) values (:int_value, :float_value, :str_value)';
  2.     sqlq.Params.Items[0].AsInteger:= 9;
  3.     sqlq.Params.Items[1].AsFloat:= 0.998;
  4.     sqlq.Params.Items[2].AsString:= 'str2';
  5.  

I get a table like:
90str2

The float value (0.998) is not inserted, the value in the table is 0.
« Last Edit: March 16, 2023, 01:47:30 pm by apeoperaio »

apeoperaio

  • Sr. Member
  • ****
  • Posts: 269
Re: SQLITE3: TSQLQuery fails when using Params for float data (aarch64)
« Reply #3 on: March 16, 2023, 01:54:28 pm »
I forgot to mention that, except from darwin aarch64, the code works for all other platforms (win x86_64, linux x86_64, darwin x86_64)

rvk

  • Hero Member
  • *****
  • Posts: 5481
Re: SQLITE3: TSQLQuery fails when using Params for float data (aarch64)
« Reply #4 on: March 16, 2023, 02:00:21 pm »
What happens if you do:
Code: Pascal  [Select][+][-]
  1. sqlq.SQL.Text:= 'INSERT INTO DATA (int_value, float_value, str_value) values (10, 1.3, "str1")';
  2. sqlq.Prepare;

Note that 10 and 1.3 aren't enclosed by quotes because they are not strings.

(I think sqlite does convert automatically but perhaps something goes wrong there)

Don't forget the prepare. It should be done automatically, but it can't hurt.

It the 10 and 1.3 are really added then too, then there must be something wrong with passing parameters.
« Last Edit: March 16, 2023, 02:05:14 pm by rvk »

rvk

  • Hero Member
  • *****
  • Posts: 5481
Re: SQLITE3: TSQLQuery fails when using Params for float data (aarch64)
« Reply #5 on: March 16, 2023, 02:20:52 pm »
It's a known problem...

Float Params don't work for SQLite. Probably only effect ARM
See https://gitlab.com/freepascal.org/fpc/source/-/issues/28140

Apparently you need to (re)compile FPC with  -Caeabihf options.

apeoperaio

  • Sr. Member
  • ****
  • Posts: 269
Re: SQLITE3: TSQLQuery fails when using Params for float data (aarch64)
« Reply #6 on: March 16, 2023, 03:15:47 pm »
Ok, it is a seven years old issue. Now closed, but the bug is still there. Will FPC change it in the future?

rvk

  • Hero Member
  • *****
  • Posts: 5481
Re: SQLITE3: TSQLQuery fails when using Params for float data (aarch64)
« Reply #7 on: March 16, 2023, 03:18:46 pm »
Ok, it is a seven years old issue. Now closed, but the bug is still there. Will FPC change it in the future?
It was not a bug (as I see it).
It was a compilation issue.

When FPC was recompiled with a certain switch, the problem went away.

Quote
I got it fpc compiled properly once I got all the make parameters right. It seems it boils down to that I thought OPT parameters for make where cumulative.
Thanks for your help. The bug can be closed.

I'm not sure why it was not done originally.

Maybe if you mention the OS, someone can take a look.
(I don't have aarch64, either Mac or Linux)

apeoperaio

  • Sr. Member
  • ****
  • Posts: 269
Re: SQLITE3: TSQLQuery fails when using Params for float data (aarch64)
« Reply #8 on: March 16, 2023, 03:31:07 pm »
I get this error only on darwin aarch, I edited my comment in gitlab.

Thank you.

upsidasi

  • New Member
  • *
  • Posts: 28
Re: SQLITE3: TSQLQuery fails when using Params for float data (aarch64)
« Reply #9 on: June 07, 2023, 03:24:50 pm »
Is there any chance for the property .AsFloat to work for AARCH64? I noticed the new comment on the bug report https://gitlab.com/freepascal.org/fpc/source/-/issues/28140, but its status is still "closed".

Чебурашка

  • Sr. Member
  • ****
  • Posts: 450
  • СЛАВА УКРАЇНІ! / Slava Ukraïni!
Re: SQLITE3: TSQLQuery fails when using Params for float data (aarch64)
« Reply #10 on: June 22, 2023, 12:18:35 pm »
It was not a bug (as I see it).
It was a compilation issue.

When FPC was recompiled with a certain switch, the problem went away.

From the perpective of any user of FPC this is a bug as the things don't work properly and do not allow a user program to work as expected and as works on a different platform, like OP says.

« Last Edit: June 22, 2023, 12:21:24 pm by Чебурашка »
FPC 3.2.0/Lazarus 2.0.10+dfsg-4+b2 on Debian 11.5
FPC 3.2.2/Lazarus 2.2.0 on Windows 10 Pro 21H2

 

TinyPortal © 2005-2018