Recent

Author Topic: TMemoField instead of TStringField.  (Read 564 times)

BSaidus

  • Hero Member
  • *****
  • Posts: 636
  • lazarus 1.8.4 Win8.1 / cross FreeBSD
TMemoField instead of TStringField.
« on: September 29, 2025, 04:18:22 pm »
Hello.
I use TZQuery from ZeosDBO and I have a an SQLITE View witch is an SQL aggregation of some fields from different tables.
Say
   vtmp_1 is a view, and
   f1: a VARCHAR field,
   f2: a VARCHAR field,
   f3: a VARCHAR field,
   f4: an aggregated field => CAST(('aa_'||LOWER(REPLACE(name, ' ', '_'))||'="'||fname||'"') AS VARCHAR) AS ENAME
When I use an SQL SELECT Statement in a ZQuery, I got "f4" as TMemoField
In every cases,
Code: SQL  [Select][+][-]
  1. SELECT  f1,
  2.         f2,
  3.         f3,
  4.         f4
  5.    FROM vtemp_1;  
  6.  
  7. SELECT  f1,
  8.         f2,
  9.         f3,
  10.         CAST(f4 AS VARCHAR) AS f4
  11.    FROM vtemp_1;
  12.  

So Is there any solution for this, I need it to use this fied as a Lookup field in TDBLookupComboBox ( Now it display (memo) as content ).

Thank you.



lazarus 1.8.4 Win8.1 / cross FreeBSD
dhukmucmur vernadh!

Zvoni

  • Hero Member
  • *****
  • Posts: 3135
Re: TMemoField instead of TStringField.
« Reply #1 on: September 29, 2025, 04:28:15 pm »
IIRC, you have to implement the OnGetText-Event for the Field

This is similiar to your problem:
https://forum.lazarus.freepascal.org/index.php/topic,69567.msg540683.html#msg540683

Edit: an alternative approach might be to use generated columns from the get go instead of concatenating it in the query/view
But this depends, if the used fields for f4/ename are from the same table
« Last Edit: September 29, 2025, 04:52:27 pm by Zvoni »
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

BSaidus

  • Hero Member
  • *****
  • Posts: 636
  • lazarus 1.8.4 Win8.1 / cross FreeBSD
Re: TMemoField instead of TStringField.
« Reply #2 on: September 29, 2025, 06:58:43 pm »
IIRC, you have to implement the OnGetText-Event for the Field

This is similiar to your problem:
https://forum.lazarus.freepascal.org/index.php/topic,69567.msg540683.html#msg540683

Edit: an alternative approach might be to use generated columns from the get go instead of concatenating it in the query/view
But this depends, if the used fields for f4/ename are from the same table

Thanks @Zvoni.
It works well, I will investigate the 2nd method.
Thnks again.
lazarus 1.8.4 Win8.1 / cross FreeBSD
dhukmucmur vernadh!

Zvoni

  • Hero Member
  • *****
  • Posts: 3135
Re: TMemoField instead of TStringField.
« Reply #3 on: September 30, 2025, 08:28:50 am »
Thanks @Zvoni.
It works well, I will investigate the 2nd method.
Thnks again.
As for the second (alternative) Approach (Generated Columns):
Could you post the CREATE-Statement for that View?

The crucial part is this
Quote
f4: an aggregated field => CAST(('aa_'||LOWER(REPLACE(name, ' ', '_'))||'="'||fname||'"') AS VARCHAR) AS ENAME

"name" and "fname": Are these two fields in the same table?
If yes, then i would definitely go with generated Columns instead of "calculating" it via query and then Type-Casting it from here to Moscow
If no (they are in separate tables), then your current solution is the only viable way
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

 

TinyPortal © 2005-2018