Lazarus

Programming => Databases => Topic started by: oldfart on October 08, 2021, 04:40:25 pm

Title: [solved] Sqlite SELECT problem
Post by: oldfart on October 08, 2021, 04:40:25 pm
returning empty string
Program contains create and insert procedures - all working correctly

I want to return the first value in the database:

SqlQuery1.SQL.Text := 'select id, cert_number from certificates LIMIT 1;'
SQLite3Connection1.Open;
SQLTransaction1.Active := true;
SqlQuery1.Open;
temp:= SQLQuery1.Fields.FieldByNumber(2).AsString;
Title: Re: Sqlite SELECT problem
Post by: JanRoza on October 08, 2021, 05:28:26 pm
If you want the first value in the database then why not simply use 'SqlQuery1.First'?
Title: Re: Sqlite SELECT problem
Post by: dseligo on October 08, 2021, 06:09:13 pm
I never used FieldByNumber, but try
Code: Pascal  [Select][+][-]
  1. temp:= SQLQuery1.Fields[1].AsString;
or
Code: Pascal  [Select][+][-]
  1. temp:= SQLQuery1.FieldByName('cert_number').AsString;

Are you sure you have something in record?
Try to see id field. Also check if you have result with Eof:
Code: Pascal  [Select][+][-]
  1. If SQLQuery1.Eof then showmessage('nothing found in query');
Title: Re: Sqlite SELECT problem
Post by: oldfart on October 08, 2021, 06:44:08 pm
Thanks for the replies, had gone through all those options .. turns out after half a day of messing with this, I had cocked up with the field type. Amended it and now everything working!!

Thanks again for the speedy replies
TinyPortal © 2005-2018