Alternative for RecordCount ?

Forum related to version 6.5.1 (alpha) and 6.6.x (beta) of ZeosLib's DBOs

Moderators: gto, cipto_kh, EgonHugeist

Post Reply
gto
Zeos Dev Team
Zeos Dev Team
Posts: 278
Joined: 11.11.2005, 18:35
Location: Porto Alegre / Brasil

Alternative for RecordCount ?

Post by gto »

Hello!!

Searching the forum and trying myself, I think the RecordCount is an expensive property and may be used with caution to avoid the component to pass through all the matched data only to count the rows...

It's become more evident when we use big databases, like one I made to test, with 350000 rows..

So, in my program there's a function that checks if certain data is already in the table. I use as parameters the name of the table, the column and data do compare. Internal, there's a ZReadOnlyQuery executing a select with the function data, and finally it compares the RecordCount of the query with zero, becouse if it's one or more, the data is duplicated.

For that propouses, could I use the RecNo property? If the SQL results no data, the RecNo returns zero, no rows, no RecNo. But if the SQL returns data, the RecNo becomes one, and symbols the duplicate record.

Could the RecNo used for that? It's less expensive than RecordCount?

Sorry for the bad writing :lol:
Thanks in advance!
Use the FU!!!!!IN Google !

gto's Zeos Quick Start Guide

Te Amo Taís!
zippo
Silver Boarder
Silver Boarder
Posts: 322
Joined: 12.10.2005, 18:01
Location: Slovenia

Post by zippo »

Can you show an example?
MarkusD
Zeos Dev Team
Zeos Dev Team
Posts: 20
Joined: 28.08.2005, 03:40
Location: Ingolstadt

Check BOF and EOF

Post by MarkusD »

Hello gto,

Just checking if BOF and EOF aren't both true, is imo the best way to check if a query didn't return a row.

Code: Select all

Query1.SQL.Text := 'select 1 from tablename where columnname = comparevalue';
Query1.Open;
if not ( Query1.BOF and Query1.EOF) then
  ShowMessage( 'Record found');
Query1.Close;
You could also use a parameter for the comparevalue and ensure that you only get one record ( could be faster):

Code: Select all

Query1.SQL.Text := 'select 1 where exists(select 1 from tablename where columnname = :comparevalue)';
Query1.ParamByName( 'comparevalue').Value := comparevalue;
Query1.Open;
if not ( Query1.BOF and Query1.EOF) then
  ShowMessage( 'Record found');
Query1.Close;
Best Regards,
Markus Dütting
btrewern
Expert Boarder
Expert Boarder
Posts: 193
Joined: 06.10.2005, 18:51

Post by btrewern »

There is an TZQuery.IsEmpty property which may be what you need.

Regards,

Ben
gto
Zeos Dev Team
Zeos Dev Team
Posts: 278
Joined: 11.11.2005, 18:35
Location: Porto Alegre / Brasil

Re: Check BOF and EOF

Post by gto »

MarkusD wrote:Hello gto,

Just checking if BOF and EOF aren't both true, is imo the best way to check if a query didn't return a row.
:wallb:

I totally forgot about EOF and BOF ! :oops:
thank you MarkusD !!
btrewern wrote: There is an TZQuery.IsEmpty property which may be what you need.
Regards,
Ben
tomorrow, in work, I'll check that also!
I like to go "in depth" with that functions :twisted:

:thanks:
Use the FU!!!!!IN Google !

gto's Zeos Quick Start Guide

Te Amo Taís!
Post Reply