Recent

Author Topic: Beginner Question: Detecting empty query result  (Read 1459 times)

dietmar

  • Full Member
  • ***
  • Posts: 170
Beginner Question: Detecting empty query result
« on: October 05, 2021, 02:12:58 pm »
Hi,

I gather data from a table via

Code: Pascal  [Select][+][-]
  1.   DBHelper.SelectQuery('SELECT * FROM Owner LIMIT 1;');
  2.   with DBHelper.SQLQuery do begin
  3.     edAuthor.Text := FieldByName('Wiz_Name').AsString + ' (' +
  4.       FieldByName('RL_Name').AsString + ')';
  5.  

How can I detect whether the query returns an empty result set?

Thx,
--Dietmar
Lazarus 2.2.0RC1 with FPC 3.2.2 (32 Bit) on Windows10 (64Bit)

ccrause

  • Sr. Member
  • ****
  • Posts: 481
Re: Beginner Question: Detecting empty query result
« Reply #1 on: October 05, 2021, 02:32:07 pm »
Check if IsEmpty of the resulting dataset returns true.

af0815

  • Hero Member
  • *****
  • Posts: 772
Re: Beginner Question: Detecting empty query result
« Reply #2 on: October 06, 2021, 06:30:59 am »
Another way is, to check with "Q.BOF AND Q.EOF". If a query is on Begin and End at the same time, the query is empty. This is the same as IsEmpty.
regards
Andreas

dietmar

  • Full Member
  • ***
  • Posts: 170
Re: Beginner Question: Detecting empty query result
« Reply #3 on: October 06, 2021, 07:01:07 pm »
Ok, and say I am using an UPDATE statement on the table.
If I do this manually, I usually get only a "ok, 1 row affected" or whatever back.
How can I determine here whether the update was successful?

Thx,
--Dietmar
Lazarus 2.2.0RC1 with FPC 3.2.2 (32 Bit) on Windows10 (64Bit)

Zvoni

  • Hero Member
  • *****
  • Posts: 807
Re: Beginner Question: Detecting empty query result
« Reply #4 on: October 07, 2021, 09:33:54 am »
Huh?

TSQLQuery inherits from TCustomSQLQuery, and TCustomSQLQuery has a public Function RowsAffected
https://www.freepascal.org/docs-html/fcl/sqldb/tcustomsqlquery.rowsaffected.html
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