[fpc-pascal] Postgresql interface bronken for Raspberry pi model 1b

Björn Lundin b.f.lundin at gmail.com
Mon Mar 28 00:44:59 CEST 2016


Hi!
I'm using a pi as a monitor for some process, so I'm trying to get SDL2
and a working postgres interface on it.

However I'm running into trouble on timestamps fields on the pi.

I wrote a console program on Win7, using 32-bit compiler bundled with
Lazarus 1.6. (I think is is fpc 3.0.0)
and that platform can connect to the db, and run the program.



C:\pascal\pg_test_float>test_float.exe
A: 1
B:  1.0000000000000000E+000
C:  4.2457016203831023E+004
round(B): 1
round(C): 42457



The same program on the pi crashes.

pi at raspberrypi ~ $ fpc -v
Free Pascal Compiler version 2.6.0-9+rpi1+wsf1 [2015/04/28] for arm
Copyright (c) 1993-2011 by Florian Klaempfl and others

pi at raspberrypi ~ $ uname -a
Linux raspberrypi 4.1.7+ #817 PREEMPT Sat Sep 19 15:25:36 BST 2015
armv6l GNU/Linux


pi at raspberrypi ~/svn/bnlbot/botstart/bot-1-0/source/pascal $ ./test_float
An unhandled exception occurred at $000302D4 :
EDatabaseError :  : Unknown fieldtype for parameter "DT".
  $000302D4
  $0001C4D0
  $00020DE8
  $00008760

pi at raspberrypi ~/svn/bnlbot/botstart/bot-1-0/source/pascal $ addr2line
-e test_float 000302D4 0001C4D0 00020DE8 00008760
/home/pi/svn/bnlbot/botstart/bot-1-0/source/pascal/test_float.lpr:85
/home/pi/svn/bnlbot/botstart/bot-1-0/source/pascal/test_float.lpr:85
/home/pi/svn/bnlbot/botstart/bot-1-0/source/pascal/test_float.lpr:85
/home/pi/svn/bnlbot/botstart/bot-1-0/source/pascal/test_float.lpr:57


where line 57 is market <---- here in code below
ie. Q2.Params.ParamByName('DT').Value := now;


program test_float;
uses
pqconnection,sqldb,sysutils,db;

function CreateConnection: TPQConnection;
begin
  result := TPQConnection.Create(nil);
  result.Hostname := 'db.somewhwew.com';
  result.DatabaseName := 'asd';
  result.UserName := 'asd';
  result.Password := 'pwd';
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 : Double;
C : TDateTime;

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 timestamp(3) without time zone not null ) ';

  Q1.SQL.Text := sSql;
  Q1.ExecSql;

  Q2 := CreateQuery(T) ;
  sSql := 'insert into TEST values (1, 1.0, :DT)';
  Q2.SQL.Text := sSql;
  Q2.Prepare;
  //Q2.Params.ParamByName('DT').DataType := ftDateTime;
  Q2.Params.ParamByName('DT').Value := now;             <----Here
  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').AsDateTime;
      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.


Ideas ?


--
Björn



More information about the fpc-pascal mailing list