Lazarus

Programming => Databases => Topic started by: Milsa on September 27, 2021, 07:54:59 pm

Title: SQLite: Get field names from table
Post by: Milsa on September 27, 2021, 07:54:59 pm
I have this fragment of code:
Code: Pascal  [Select][+][-]
  1.     SQL.Text := Format('SELECT * FROM [%s]', [Name]);
  2.     Open;
  3.     while not EOF do
  4.     begin
  5.       //detecting field names
  6.       Next;
  7.     end;
  8.     Close;      
Can I detect field names from TSQLQuery like "Fields[0].Name"?
Title: Re: SQLite: Get field names from table
Post by: dseligo on September 28, 2021, 07:49:52 am
This works with ZEOSlib:
Code: Pascal  [Select][+][-]
  1. For i:=0 to Fields.Count-1 do
  2.   showMessage(Fields[i].FieldName);
Title: Re: SQLite: Get field names from table
Post by: Zvoni on September 28, 2021, 08:39:06 am
Use "GetFieldNames" of TSQLite3Connection of TSQLConnection (SQLite3Connection inherits from it) --> TSQLite3Connection overrides the one from TSQLConnection
https://www.freepascal.org/daily/packages/fcl-db/sqlite3conn/tsqlite3connection.getfieldnames.html
https://www.freepascal.org/docs-html/fcl/sqldb/tsqlconnection.getfieldnames.html

EDIT: Alternative is to fire a PRAGMA-Call from a TSQLQuery-Object
Code: Pascal  [Select][+][-]
  1. MySQLQuery.SQL.Text:='PRAGMA table_info(MyTableName)';
  2. MySQLQuery.Open;
Title: Re: SQLite: Get field names from table
Post by: Milsa on October 02, 2021, 01:40:49 pm
Thank you very much. This is solution for me.
TinyPortal © 2005-2018