Duplicate result when using locate, loPartialKey and Filter

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

Duplicate result when using locate, loPartialKey and Filter

Post by gto »

Hello there

I found a bug when using a simple query and an edit field that looks for the typed word using locate, loPartialKey and filtered=true. Some rows of the result appear twice.

Image

There's a connection to a firebird database, a query with "select * from table" and filtered=true, and a DataSource, all linked to the a default DBGrid.

The only typed code is under Edit1Change:

Code: Select all

if edit1.text <> '' then
   ZQuery1.Locate('USUARIO' ,edit1.text, [loPartialKey]);
The problem occurs when you look for various (3-4..) keys, which have found something, and then look for a last match key. When it matched, you select the grid and start to press down in the keyboard, until the bottom of DBGrid. When you reach the bottom, press down one more time, and the first and last line of DBGrid will have the same value (duplicated).

A very strange bug, and an old one, since 6.5.1 as I remember. I've tested with and without a bogus filter (1=1), and the results are the same.

Should I register a bug in mantis?

Thks
Use the FU!!!!!IN Google !

gto's Zeos Quick Start Guide

Te Amo Taís!
User avatar
cipto_kh
Senior Boarder
Senior Boarder
Posts: 83
Joined: 28.09.2005, 11:22
Location: Indonesia
Contact:

Post by cipto_kh »

Yep, I also think this is a bug, should register to mantis.

Could you also give an example program in mantis by using Firebird standart example of employee.fdb database?
gto
Zeos Dev Team
Zeos Dev Team
Posts: 278
Joined: 11.11.2005, 18:35
Location: Porto Alegre / Brasil

Post by gto »

Just posted the bug into mantis:

http://zeosbugs.firmos.at/view.php?id=108

Any help is welcome!

Thanks!
Use the FU!!!!!IN Google !

gto's Zeos Quick Start Guide

Te Amo Taís!
gto
Zeos Dev Team
Zeos Dev Team
Posts: 278
Joined: 11.11.2005, 18:35
Location: Porto Alegre / Brasil

Post by gto »

Hello guys!

News from the front: Just found that the procedure doing this problem is TZAbstractRODataset.MoveRecNo!

After a closer look into TZAbstractRODataset.Locate method, which calls MoveRecNo, I've found that the bug root are a bit different than I related:

Everytime, when TZAbstractRODataset find some row using locate, it fires a MoveRecNo to position the cursor over it.

Then, MoveRecNo uses the Resync procedure, which reset the cursor position. MoveRecNo uses a integer var to save this position and then re-set it when Resync is done.

The problem is: This procedure isn't enough to tell the TZAbstractRODataset that the cursor is postitioned over this row. When I scrolled down the DBGrid and the components tried to search for the next record (off the screen/scroll limit), it was taking the search result cursor, and not the current cursor (in this case, I scrolled by hand down the bottom of DBGrid).

Well, I solved it calling UpdateCursorPos by the end of MoveRecNo , right after re-setting the CurrentRow position.

Don't know if it's a good practice, but I'll wait for your comments! :)

Thanks!

UPDATE:

My version of the funcion MoveRecNo:

Code: Select all

procedure TZAbstractRODataset.MoveRecNo(Value: Integer);
var
  PreviousCurrentRow: Integer;
begin
  Value := Max(1, Value);
  if Value < CurrentRow then
    CheckBiDirectional;

  if FetchRows(Value) then
    CurrentRow := Value
  else CurrentRow := CurrentRows.Count;

  PreviousCurrentRow := CurrentRow;//Resync moves the current row away
  try
    if not (State in [dsInactive]) then Resync([]);
  finally
    CurrentRow := PreviousCurrentRow;
  end;
  UpdateCursorPos;
end;
Use the FU!!!!!IN Google !

gto's Zeos Quick Start Guide

Te Amo Taís!
dragos
Fresh Boarder
Fresh Boarder
Posts: 12
Joined: 27.09.2005, 18:28

Post by dragos »

This also fixes a bug with a TDBLookupComboBox whose data comes from a TZQuery's dataset where scrolling up/down would - under some conditions - seem as if all entries are duplicates.

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

Post by gto »

Oh thanks for testing!

I'm glad to see it worked beyond my test site... nice!

I guess we can ask mdaems to put this change on the SVN tree :)

Thank you!
Use the FU!!!!!IN Google !

gto's Zeos Quick Start Guide

Te Amo Taís!
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post by mdaems »

Done already! SVN rev. 368 on 13/05/2008. Will be merged into trunk next time merge happens.

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

Post by gto »

mdaems wrote:Done already! SVN rev. 368 on 13/05/2008. Will be merged into trunk next time merge happens.

Mark
Thank you Mark! :mrgreen:
Use the FU!!!!!IN Google !

gto's Zeos Quick Start Guide

Te Amo Taís!
Post Reply