Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2008-12

SQLite Numeric error

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Andrea Mauri

Dear all,
I am using SQLite db in my application and I found a problem using NUMERIC field type.
In order to reproduce it, create a new project, drop a sqliteconnection, sqltransaction, sqlquery and a button on the form. In the OnButton drop the following code:

procedure TForm1.Button1Click(Sender: TObject);
var
  id: integer;
  fl: double;
begin
  SQLite3Connection1.DatabaseName:= 'e:\temp\db.sqlite';
  if FileExists(SQLite3Connection1.DatabaseName) then
    DeleteFile(SQLite3Connection1.DatabaseName);
  SQLite3Connection1.Transaction:= SQLTransaction1;
  SQLQuery1.DataBase:= SQLite3Connection1;
  SQLQuery1.Transaction:= SQLTransaction1;
  SQLite3Connection1.ExecuteDirect('CREATE TABLE T1 (ID INTEGER, VAL
NUMERIC (10,3))');
  SQLQuery1.SQL.Text:= 'INSERT INTO T1 (ID, VAL) VALUES (1, 10.13)';
  SQLQuery1.ExecSQL;
  SQLTransaction1.CommitRetaining;
  SQLQuery1.SQL.Text:= 'SELECT * FROM T1';
  SQLQuery1.Open;
  SQLQuery1.First;
  while not SQLQuery1.EOF do
  begin
    id:= SQLQuery1.FieldByName('ID').AsInteger;
    fl:= SQLQuery1.FieldByName('VAL').AsFloat;
    MessageDlg(Format('ID: %s, VAL: %s', [IntToStr(id),
FloatToStr(fl)]), mtInformation, [mbOK],0);
    SQLQuery1.Next;
  end;
  SQLite3Connection1.Close;
end;

In the fl variable I get 0.001. The same works well using firebird (it gets 10.13). The insert works well, I verified it by using other sqlite administration tools (like sqlite extension for firefox). If I look at T1 table using sqlite extension for firefox I correctly get 10.13 in the VAL field of the first record.
If I use REAL field type instead NUMERIC I correctly get 10.13. I tested it both on Linux an Windows (FPC 2.2.2 Lazarus SVN), it doesn't work both on Linux and Windows.
Best regards,
Andrea

Dr. Andrea Mauri, PhD Milano Chemometrics and QSAR Research Group Department of Environmental Sciences University of Milano-Bicocca P.zza della Scienza, 1 20126 Milano - Italy Tel: ++39 02 64482801 mailto: http://michem.disat.unimib.it/chm/

Reply by email

Joost van der Sluis
to Andrea Mauri

Op maandag 22-12-2008 om 11:53 uur [tijdzone +0100], schreef Andrea Mauri:

Show quoted text 9 lines
In the fl variable I get 0.001. The same works well using firebird (it gets 10.13). The insert works well, I verified it by using other sqlite administration tools (like sqlite extension for firefox). If I look at T1 table using sqlite extension for firefox I correctly get 10.13 in the VAL field of the first record. If I use REAL field type instead NUMERIC I correctly get 10.13. I tested it both on Linux an Windows (FPC 2.2.2 Lazarus SVN), it doesn't work both on Linux and Windows.

This is probably fixed in any svn-version of fpc (recent 2.2.3 or 2.3.1)

Joost.

Reply by email