Problem with EOF or BOF

Discussion of open issues, suggestions and bugs regarding IBDAC (InterBase Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
firebird_hunter
Posts: 9
Joined: Tue 18 Mar 2008 18:47

Problem with EOF or BOF

Post by firebird_hunter » Tue 18 Mar 2008 19:23

Hello,

i have a problem when i am navigating through a IBCTable or IBCQuery result.

For example: I have a table with four entries. After Activating the table by setting active property to true, i start with the first record. I have a button called next, which uses the Next() method. Thereafter i am checking, if EOF is true to disable the next button. But the following happens:

I go from the third to the fourth entry with Next. The fourth entry is the last one. But EOF still give me false retour. By using Next again EOF is true, but i am still at the end of the table.

The same is with BOF, getting true after reaching the first entry and using Prior.

Using DBNavigator component gives me the same behaviour.

My workaroung is to get the numbers of records and doing the navigation with comparing the position with the records number.

Does anybody have an idea to solv these problems?


Regards,

Firedbird-Hunter

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Wed 19 Mar 2008 08:56

It is standard behaviour of EOF and BOF properties. EOF is set to True by Next method when it failed to get the next record.

When you come to the last record, and FetchAll property is False, the component not always knows if there are subsequent records. When you call Next method again, the component tries to fetch next block of records, and sets EOF, if there are no more records.

firebird_hunter
Posts: 9
Joined: Tue 18 Mar 2008 18:47

Post by firebird_hunter » Thu 20 Mar 2008 08:49

Dear Plash

thanks for your information. Ok, so i have to find another way doing the navigation.

For this purpose i want to get the record count. Do i get the right record count when i activating a table / query and do a First() and Last() just behind? Of course i would use only a simple query to reduce workload on the server.


With regards

Firebird_Hunter

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Thu 20 Mar 2008 09:30

You can get right record count, if you call Last method, and then read RecordCount property. You can also set FetchAll property to True. In this case you don't need to call Last method.

If you table contains a large amount of records, you can set Options.QueryRecCount property to True, and FetchAll to False. TOraQuery component will execute additional query 'SELECT COUNT() FROM ...' on openning to get record count. So RecordCount property contains correct value, and you do not need to call Last method.

firebird_hunter
Posts: 9
Joined: Tue 18 Mar 2008 18:47

Post by firebird_hunter » Thu 20 Mar 2008 11:20

Hi Plash,

that is the information i need. Thank you!


Regards

Firebird_Hunter

Post Reply