Recent

Author Topic: [solved] Sqlite SELECT problem  (Read 898 times)

oldfart

  • New Member
  • *
  • Posts: 15
[solved] Sqlite SELECT problem
« 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;
« Last Edit: October 08, 2021, 06:46:18 pm by oldfart »

JanRoza

  • Hero Member
  • *****
  • Posts: 627
    • http://www.silentwings.nl
Re: Sqlite SELECT problem
« Reply #1 on: October 08, 2021, 05:28:26 pm »
If you want the first value in the database then why not simply use 'SqlQuery1.First'?
OS: Windows 10 (64 bit) / Linux Mint (64 bit)
Laz: Lazarus 2.0.12 FPC 3.2.0
       CodeTyphon 7.7 FPC 3.3.1

dseligo

  • Sr. Member
  • ****
  • Posts: 375
Re: Sqlite SELECT problem
« Reply #2 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');
« Last Edit: October 08, 2021, 06:10:54 pm by dseligo »

oldfart

  • New Member
  • *
  • Posts: 15
Re: Sqlite SELECT problem
« Reply #3 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