Recent

Author Topic: problem with floats when converting Paradox tables to SQLite tables  (Read 336 times)

dpap

  • Jr. Member
  • **
  • Posts: 52
I try to convert a Paradox table, that has some TFloatfields,  to SQLite using SQL commands. For every Paradox row I create a string with field values (in Delphi 2007) building a SQL "insert into" string and then I read this SQL string (in Lazarus 3.6) and execute the SQL command. I save the values with quottedStr function even they are floats. At the end of the process I have a SQLite table with all my data. Using  DB browser for SQLite I can see them and I can see that the Float fields are actually saved as TFloat type having their decimal part as excpected.
Now I create a testing app with this code
 uses
     Classes, SysUtils, mysql80conn, SQLDB, DB, SQLite3Conn, Forms, Controls,
               Graphics, Dialogs, DBGrids, DBCtrls;

type

               { TForm1 }

     TForm1 = class(TForm)
                              DataSource1 : TDataSource;
                              DBGrid1 : TDBGrid;
                              DBNavigator1 : TDBNavigator;
                              SQLite3Connection1 : TSQLite3Connection;
                              SQLQuery1 : TSQLQuery;
                              SQLTransaction1 : TSQLTransaction;
                              procedure FormCreate(Sender : TObject);
     private

     public

     end;

var
     Form1 : TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.FormCreate(Sender : TObject);
begin
    SQLite3Connection1.Open;
    with  SQLQuery1 do begin
      SQL.text := 'SELECT * FROM myTable';
      open;
    end;
end;
end.

and I receive the float values truncated (only the integer part) eg 3.9999999 becomes 3
This happens in the DBgrid and showmessage and every other displaying way I tried.
I suspect the decimal separator my system uses (",") but I changed to "." before the creation of the transforming SQL without success.

PS. If I use SQL.text := 'SELECT myFloatField, typeof(myFloatField) FROM myTable' then I see the zero values as float and non zero as 'text'. That means the "insert into" SQL statement treated the float value as text but why?

Do you know why this happens?

PascalDragon

  • Hero Member
  • *****
  • Posts: 5899
  • Compiler Developer
Re: problem with floats when converting Paradox tables to SQLite tables
« Reply #1 on: February 13, 2025, 08:30:51 pm »
Not related to your problem, but please use [code=pascal][/code]-tags when posting code. Make it nicer to view and avoids the forum software potentially interpreting your code.

dpap

  • Jr. Member
  • **
  • Posts: 52
Deepseek suggest me to not to use quottedStr but StringReplace(FormatFloat('0.0000000', fields[j].asFloat),',','.',[rfReplaceAll]) and the problem solved!

 

TinyPortal © 2005-2018