Recent

Author Topic: [SOLVED] FPreport print date base64 encoded  (Read 805 times)

dseligo

  • Hero Member
  • *****
  • Posts: 1686
[SOLVED] FPreport print date base64 encoded
« on: September 15, 2025, 07:23:54 pm »
I have SQL like this (DB is SQlite):
Code: MySQL  [Select][+][-]
  1. select date(insert_date_time) as insert_date
  2. from sometable

Column insert_date_time in SQlite is defined like this:
Code: Text  [Select][+][-]
  1. insert_date_time datetime default (datetime(current_timestamp, ''localtime''))

Memo in FPreport is created like:
Code: Pascal  [Select][+][-]
  1.   Memo := TFPReportMemo.Create(FDataBand);
  2.   Memo.Layout.Left := ALeft;
  3.   Memo.Layout.Width := AWidth;
  4.   Memo.Layout.Top := ATop;
  5.   Memo.Layout.Height := AHeight;
  6.   Memo.Font.Name := AFont;
  7.   Memo.Font.Size := AFontSize;
  8.   Memo.TextAlignment.Horizontal := AHorAlignment;
  9.   Memo.Text := '[insert_date]';

These are values I get in FPreport (exported to PDF):
Code: Text  [Select][+][-]
  1. MjAyNS0wNy0wMw==
  2. MjAyNS0wNy0xMw==
  3. MjAyNS0wNy0xNQ==
  4. MjAyNS0wNy0xOA==

With this:
Code: Pascal  [Select][+][-]
  1. WriteLn(Query1.FieldByName('insert_date').AsString);
  2. WriteLn(Query1.FieldByName('insert_date').FieldDef.DataType);

I get (for first row):
Code: Text  [Select][+][-]
  1. 2025-07-03
  2. ftMemo

What could be the cause?

I tried this on FPC 3.2.2 on Windows 11 and Android.
« Last Edit: September 16, 2025, 12:49:07 pm by dseligo »

anse

  • Jr. Member
  • **
  • Posts: 52
  • Bugmonkey
    • HeidiSQL
Re: FPreport print date base64 encoded
« Reply #1 on: September 15, 2025, 08:07:24 pm »
SQLite does not care much about defined column data types, and not even about results of functions like DATE() - most of them just return strings (which could be the cause of ftMemo), and the underlying driver you use does not really get information about the originated data type.

dseligo

  • Hero Member
  • *****
  • Posts: 1686
Re: FPreport print date base64 encoded
« Reply #2 on: September 15, 2025, 09:03:39 pm »
I don't mind string. Question is why FPreport encode this string in base64. And how do I prevent this.

rvk

  • Hero Member
  • *****
  • Posts: 7063
Re: FPreport print date base64 encoded
« Reply #3 on: September 15, 2025, 09:14:18 pm »
Probably because FPC considers TEXT from SQLite as memo and not as string. Same reason you get (memo) in a tdbgrid. I find this a wrong choice which was introduced some years ago.

TEXT should have stayed a field type ftstring (as it was before).

Similar topic here
https://forum.lazarus.freepascal.org/index.php?topic=62022.0

You can cast to a varchar or use gettext to return string (same as the solution for tdbgrid).

dseligo

  • Hero Member
  • *****
  • Posts: 1686
Re: FPreport print date base64 encoded
« Reply #4 on: September 16, 2025, 12:48:40 pm »
Probably because FPC considers TEXT from SQLite as memo and not as string. Same reason you get (memo) in a tdbgrid. I find this a wrong choice which was introduced some years ago.

TEXT should have stayed a field type ftstring (as it was before).

Similar topic here
https://forum.lazarus.freepascal.org/index.php?topic=62022.0

You can cast to a varchar or use gettext to return string (same as the solution for tdbgrid).

Thank you for the link, solution from answer #5 (from paweld) worked. Casting doesn't work for me.

 

TinyPortal © 2005-2018