Sign in Join

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

Mailing lists / lazarus / 2016-03

TPQConnection and float

4 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

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

Björn Lundin

Hi !
I'm new to Lazarus (since Saturday)
but in the 90:ies id wrote some Turbo Pascal for school and liked it. However, the last 15 years, I've worked with a system written in Ada so that is the language I'm fluid in.
But it is close to Pascal.

So - I started to write a form with a tree widget and a graph, and started go get data from a database to fill the graph with, depending on the selected node in the tree.
But the values are off with a factor 10000.

I wrote a console test program to reproduce it,
and in also gets the floats wrong with a factor 10000.

Where should I report this - if this mailing list is not the place? But perhaps first of all - am I doing something wrong here ? code below.

Besides this, I am really impressed with Lazarus,
as an IDE.

I've already ordered some as follows:
C:\pg_test_float>test_float.exe
A: 1
B: 1.0000000000000000E+004
C: 2.2000000000000000E+004
round(B): 10000
round(C): 22000

(Win7 , Postgres 9.4, libpq.dll also 9.4, Lazarus 1.6)

program test_float;
uses
pqconnection,sqldb ;
function CreateConnection: TPQConnection;
begin
  result := TPQConnection.Create(nil);
  result.Hostname := 'some-server';
  result.DatabaseName := 'some-db';
  result.UserName := 'some-user';
  result.Password := 'some-pass;
end;
function CreateTransaction(pConnection: TPQConnection): TSQLTransaction;
begin
  result := TSQLTransaction.Create(pConnection);
  result.Database := pConnection;
end;
function CreateQuery(pTransaction: TSQLTransaction): TSQLQuery;
begin
  result := TSQLQuery.Create(pTransaction.Database);
  result.Database := pTransaction.Database;
  result.Transaction := pTransaction
end;
var
PQConn : TPQConnection;
T      : TSQLTransaction;
Q1, Q2, Q3 : TSQLQuery;
A : LongInt;
B,C : Double;
sSql : String;
begin
  PQConn := CreateConnection ;
  PQConn.Open;
  T := CreateTransaction(PQConn);
  T.StartTransaction;
  Q1 := CreateQuery(T) ;
  sSql := 'create table TEST ( ';
  sSql += 'A integer not null primary key, ';
  sSql += 'B numeric(8,3) not null , ';
  sSql += 'C numeric(15,2) not null ) ';
  Q1.SQL.Text := sSql;
  Q1.ExecSql;
  Q2 := CreateQuery(T) ;
  sSql := 'insert into TEST values (1, 1.0, 2.2)';
  Q2.SQL.Text := sSql;
  Q2.ExecSql;
  Q3 := CreateQuery(T) ;
  sSql := 'select * from TEST order by A';
  Q3.SQL.Text := sSql;
  Q3.Open;
  if not Q3.Eof then begin
    A := Q3.FieldByName('A').AsLongint;
    B := Q3.FieldByName('B').AsFloat;
    C := Q3.FieldByName('C').AsFloat;
    Writeln('A: ', A);
    Writeln('B: ', B);
    Writeln('C: ', C);
    Writeln('round(B): ', round(B));
    Writeln('round(C): ', round(C));
  end
  else
    writeln('Eos');
  Q3.Close;
  T.Rollback;
  Q1.Free;
  Q2.Free;
  Q3.Free;
  T.Free;
  PQConn.Close;
end.
/Bj?rn -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20160321/e4f0af3b/attachment-0001.html>

Reply by email

LacaK
to Björn Lundin

This is probably same bug as #29760
(http://bugs.freepascal.org/view.php?id=29760)
See last comment there. (bug exists in FPC 3.0, so you can downgrade to FPC 2.6.4 and test)
-Laco.

Show quoted text 126 lines
Hi ! I'm new to Lazarus (since Saturday) but in the 90:ies id wrote some Turbo Pascal for school and liked it. However, the last 15 years, I've worked with a system written in Ada so that is the language I'm fluid in. But it is close to Pascal. So - I started to write a form with a tree widget and a graph, and started go get data from a database to fill the graph with, depending on the selected node in the tree. But the values are off with a factor 10000. I wrote a console test program to reproduce it, and in also gets the floats wrong with a factor 10000. Where should I report this - if this mailing list is not the place? But perhaps first of all - am I doing something wrong here ? code below. Besides this, I am really impressed with Lazarus, as an IDE. I've already ordered some books at Amazon. output as follows: C:\pg_test_float>test_float.exe A: 1 B: 1.0000000000000000E+004 C: 2.2000000000000000E+004 round(B): 10000 round(C): 22000 (Win7 , Postgres 9.4, libpq.dll also 9.4, Lazarus 1.6) program test_float; uses pqconnection,sqldb ; function CreateConnection: TPQConnection; begin result := TPQConnection.Create(nil); result.Hostname := 'some-server'; result.DatabaseName := 'some-db'; result.UserName := 'some-user'; result.Password := 'some-pass; end; function CreateTransaction(pConnection: TPQConnection): TSQLTransaction; begin result := TSQLTransaction.Create(pConnection); result.Database := pConnection; end; function CreateQuery(pTransaction: TSQLTransaction): TSQLQuery; begin result := TSQLQuery.Create(pTransaction.Database); result.Database := pTransaction.Database; result.Transaction := pTransaction end; var PQConn : TPQConnection; T : TSQLTransaction; Q1, Q2, Q3 : TSQLQuery; A : LongInt; B,C : Double; sSql : String; begin PQConn := CreateConnection ; PQConn.Open; T := CreateTransaction(PQConn); T.StartTransaction; Q1 := CreateQuery(T) ; sSql := 'create table TEST ( '; sSql += 'A integer not null primary key, '; sSql += 'B numeric(8,3) not null , '; sSql += 'C numeric(15,2) not null ) '; Q1.SQL.Text := sSql; Q1.ExecSql; Q2 := CreateQuery(T) ; sSql := 'insert into TEST values (1, 1.0, 2.2)'; Q2.SQL.Text := sSql; Q2.ExecSql; Q3 := CreateQuery(T) ; sSql := 'select * from TEST order by A'; Q3.SQL.Text := sSql; Q3.Open; if not Q3.Eof then begin A := Q3.FieldByName('A').AsLongint; B := Q3.FieldByName('B').AsFloat; C := Q3.FieldByName('C').AsFloat; Writeln('A: ', A); Writeln('B: ', B); Writeln('C: ', C); Writeln('round(B): ', round(B)); Writeln('round(C): ', round(C)); end else writeln('Eos'); Q3.Close; T.Rollback; Q1.Free; Q2.Free; Q3.Free; T.Free; PQConn.Close; end. -- /Bj?rn -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Michael Van Canneyt
to Björn Lundin: Hi ! I'm new to Lazarus (since Saturday) but in the 90:ies id wrote some Turbo Pascal for…
Bj?rn Lundin wrote 11 lines
Hi ! I'm new to Lazarus (since Saturday) but in the 90:ies id wrote some Turbo Pascal for school and liked it. However, the last 15 years, I've worked with a system written in Ada so that is the language I'm fluid in. But it is close to Pascal. So - I started to write a form with a tree widget and a graph, and started go get data from a database to fill the graph with, depending on the selected node in the tree. But the values are off with a factor 10000.

This is a known bug which is fixed in trunk.
See e.g. http://bugs.freepascal.org/view.php?id=29760

Michael.

Reply by email

Björn Lundin
to Michael Van Canneyt

2016-03-22 8:02 GMT+01:00 Michael Van Canneyt :

This is a known bug which is fixed in trunk. See e.g. http://bugs.freepascal.org/view.php?id=29760

Oh, it did not occur to me to look for a ticket/bug database. Thanks, I'll go for a downgrade coming weekend.

/Bj?rn -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20160322/92b73889/attachment.html>

Reply by email