Recent

Author Topic: the request string_agg and TMemo problem  (Read 1939 times)

azizi_lazard1988

  • New Member
  • *
  • Posts: 24
the request string_agg and TMemo problem
« on: July 26, 2017, 03:17:11 pm »
hello,
i work with portgresql and lazarus , and i want to repurate two varchar fields in one fields
and show them in same TMemo
i use the request of String_agg this  but when i execute he show me  type_main not found  but when i execute request in postgresql all is fine  can you help me please

Code: Pascal  [Select][+][-]
  1.  GmaoDataModule.PreventifDetailQuery.Active:=true;
  2.   GmaoDataModule.PreventifDetailQuery.SQL.Text:= 'SELECT ref_equip,string_agg(type_maintenance,'''+''+''') as type_main FROM "PreventifDetail" where ref_equip='''+NewOTForm.CodeAmcEdit.Text+''' GROUP BY ref_equip;';
  3.   NewOTForm.Memo1.Text:=GmaoDataModule.PreventifDetailQuery.FieldByName('type_main').AsString;
  4.   GmaoDataModule.PreventifDetailQuery.Active:=true;
  5.  NewOTForm.Show;  

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: the request string_agg and TMemo problem
« Reply #1 on: July 26, 2017, 04:44:51 pm »
hello,
i work with portgresql and lazarus , and i want to repurate two varchar fields in one fields
and show them in same TMemo
i use the request of String_agg this  but when i execute he show me  type_main not found  but when i execute request in postgresql all is fine  can you help me please

Code: Pascal  [Select][+][-]
  1.  GmaoDataModule.PreventifDetailQuery.Active:=true;
  2.   GmaoDataModule.PreventifDetailQuery.SQL.Text:= 'SELECT ref_equip,string_agg(type_maintenance,'''+''+''') as type_main FROM "PreventifDetail" where ref_equip='''+NewOTForm.CodeAmcEdit.Text+''' GROUP BY ref_equip;';
  3.   NewOTForm.Memo1.Text:=GmaoDataModule.PreventifDetailQuery.FieldByName('type_main').AsString;
  4.   GmaoDataModule.PreventifDetailQuery.Active:=true;
  5.  NewOTForm.Show;  

Code: Pascal  [Select][+][-]
  1.  GmaoDataModule.PreventifDetailQuery.Active:=False;//<-- why true?
  2.   GmaoDataModule.PreventifDetailQuery.SQL.Text:= 'SELECT ref_equip,string_agg(type_maintenance,'''+''+''') as type_main FROM "PreventifDetail" where ref_equip='''+NewOTForm.CodeAmcEdit.Text+''' GROUP BY ref_equip;';
  3.   //NewOTForm.Memo1.Text:=GmaoDataModule.PreventifDetailQuery.FieldByName('type_main').AsString;//<-- ofcourse it will raise an exception it has the old dataset in memory.
  4.   GmaoDataModule.PreventifDetailQuery.Active:=true;//<--new data, new fields
  5.   NewOTForm.Memo1.Text:=GmaoDataModule.PreventifDetailQuery.FieldByName('type_main').AsString; //no problems
  6.  NewOTForm.Show;  
Keep in mind that nothing was tested, I just changed the order of things, to what I consider a more appropriate order, if it does not work post more info.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

azizi_lazard1988

  • New Member
  • *
  • Posts: 24
Re: the request string_agg and TMemo problem
« Reply #2 on: July 26, 2017, 11:05:10 pm »
thank you very much the problem is resolved it is really good i'am very happy thank you very much  :D :D :D :D :D

 

TinyPortal © 2005-2018