Board index » delphi » Record# in Local Interbase database

Record# in Local Interbase database

Is there a way to find out the position of a record in a Local
Interbase database?  How?  What I really want to do is display
something like "Record xx of yy" where xx is the current record and yy
is the total number of records in a dataset.

Kenny

 

Re:Record# in Local Interbase database


Quote
Kenny Lok wrote:

> Is there a way to find out the position of a record in a Local
> Interbase database?  How?  What I really want to do is display
> something like "Record xx of yy" where xx is the current record and yy
> is the total number of records in a dataset.

> Kenny

Most SQL servers don't have record numbers. All of my tables are created
with an Integer primary key. I use a trigger and a generator to fill it
in InterBAse. If you to to the last record and check its PK you will know
roughly how many records are there and the current key will approximate
where you are. I say approximate because if someone deletes a record it
will go an the PK numbers will not be adjusted.

--

Robert Schieck
-----------------------------------------------------------------------
MER Systems Inc.

Client/Server Development and Training using Delphi,  InterBase and
Oracle

InterBase page  http://www.mers.com/interbase.html
udflib page     http://www.mers.com/product.html
TDUG page       http://www.mers.com/tdug.html      -Toronto Delphi Users
Group

Re:Record# in Local Interbase database


On Thu, 25 Jul 1996 05:16:46 GMT,
Kenny Lok  <cf...@asiaonline.net> wrote:

Quote
>Is there a way to find out the position of a record in a Local
>Interbase database?  How?  What I really want to do is display
>something like "Record xx of yy" where xx is the current record and yy
>is the total number of records in a dataset.

You can get YY from the RecordCount property of the dataset.  You might
note though that there have been reports of bugs in this property, so
others simply count the number of rows in the dataset by brute force
(looping through the set).  You can manually maintain the value of XX by
going to the top of the set (First) and setting XX to 1.  From then on,
manually update its value as you traverse through the dataset.  Not quite
nice huh?  

IMHO, SQL tables were not designed for traversing row by row, as are
local tables.  That's why there is no easy way of getting the physical row
position.  Even Delphi recognizes that.  Have you seen how the elevator in
the vertical scrollbar of a DBGrid takes only 3 positions: top, middle and
bottom?  That's because those are the only row positions it knows of a
dataset: top bottom and somewhere in between.

Lito Dizon
adi...@us.net

Re:Record# in Local Interbase database


Quote
"Angelito Dizon" <adi...@mail.us.net> writes:
> On Thu, 25 Jul 1996 05:16:46 GMT,
> Kenny Lok  <cf...@asiaonline.net> wrote:

> >Is there a way to find out the position of a record in a Local
> >Interbase database?  How?  What I really want to do is display
> >something like "Record xx of yy" where xx is the current record and yy
> >is the total number of records in a dataset.

> You can get YY from the RecordCount property of the dataset.  You might
> note though that there have been reports of bugs in this property, so
> others simply count the number of rows in the dataset by brute force
> (looping through the set).  You can manually maintain the value of XX by
> going to the top of the set (First) and setting XX to 1.  From then on,
> manually update its value as you traverse through the dataset.  Not quite
> nice huh?  

> IMHO, SQL tables were not designed for traversing row by row, as are
> local tables.  That's why there is no easy way of getting the physical row
> position.  Even Delphi recognizes that.  Have you seen how the elevator in
> the vertical scrollbar of a DBGrid takes only 3 positions: top, middle and
> bottom?  That's because those are the only row positions it knows of a
> dataset: top bottom and somewhere in between.

> Lito Dizon
> adi...@us.net

Hi,
as far as I anderstood You was intersted in total number of records in Your table
To get it You may use TQuery component with SQL function count()
for ex.:
SELECT COUNT (DISTINCT CURRENCY) FROM COUNTRY;
Regards, Joel.

Other Threads