Subject | RE: [IBO] Query.Locate -with OrderingItems & OrderingLinks |
---|---|
Author | Michael Horne |
Post date | 2003-11-15T17:27:36Z |
Hello,
----
Reposting this problem since I have received solution
----
I have run into a problem. I need query.locate to
position to the first record with a value, even if
the record ordering has been changed since the query
was opened. That doesn't happen currently, or I am
doing something wrong. By the way the file has about
60000 records.
If I open query of:
SELECT NC_ID, NC_Name, NC_REFERENCE
from NetComIn order by NC_Reference
perform a
query.locate(('NC_Reference', 'GARY', []);
it will position to the first 'GARY'
However if I have a query of:
SELECT NC_ID, NC_Name, NC_REFERENCE
from NetComIn
with the following OrderingLinks
ByType=NC_name, NC_ID desc; NC_Type desc, NC_ID desc
ByReference=NC_REFERENCE, NC_ID desc; NC_REFERENCE desc, NC_ID desc
perform a
query.locate(('NC_Reference', 'GARY', []);
it will NOT position to the first 'GARY'
Change the ordering to us the 'ByReference' one and
do the locate it still doesn't find the first record.
--------
Using First before the locate doesn't help.
However some additional info on what is happening:
1. It seems that the record that is located is always
the same no matter which order the file is in.
2. That record is the first with the code when the
file is retrieved unordered.
This seems to indicate that when orderinglinks are
used to determine the order of the records. "Locate"
must use a method like:
select first 1 * from netcomin
where nc_reference = 'GARY'
to determine the record ID of the record to position
to then scans the keys to find the record. When I
issue the SQL statement above it goes to the record
that locate is finding.
Also, adding [lopPartialKey, lopFindNearest] to the locate
causes it to find a different record but still not the first
one.
You will find below the code and components I used
to do this.
I hope you all have some ideals?????
Thanks
Michael L. Horne
unit fTest;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, IB_Components, Grids, IB_Grid;
type
TformTest = class(TForm)
IB_Query1: TIB_Query;
IB_Grid1: TIB_Grid;
IB_DataSource1: TIB_DataSource;
Panel1: TPanel;
edLocate: TEdit;
Button1: TButton;
btLocateName: TButton;
btLocateRef: TButton;
procedure Button1Click(Sender: TObject);
procedure btLocateNameClick(Sender: TObject);
procedure btLocateRefClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
formTest: TformTest;
implementation
{$R *.dfm}
procedure TformTest.Button1Click(Sender: TObject);
begin
ib_Query1.Close;
ib_Query1.Open;
end;
procedure TformTest.btLocateNameClick(Sender: TObject);
begin
ib_Query1.Locate('NC_Name', edLocate.Text, [lopPartialKey,
lopFindNearest]);
end;
procedure TformTest.btLocateRefClick(Sender: TObject);
begin
// qyNetComIn.Locate('NC_Reference', 'GARY', [lopPartialKey,
lopFindNearest]);
ib_Query1.Locate('NC_Reference', edLocate.Text, []);
end;
end.
object formTest: TformTest
Left = 314
Top = 480
Width = 661
Height = 434
Caption = 'formTest'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object IB_Grid1: TIB_Grid
Left = 0
Top = 97
Width = 653
Height = 310
CustomGlyphsSupplied = []
DataSource = IB_DataSource1
Align = alClient
TabOrder = 0
end
object Panel1: TPanel
Left = 0
Top = 0
Width = 653
Height = 97
Align = alTop
Caption = 'Panel1'
TabOrder = 1
object edLocate: TEdit
Left = 160
Top = 8
Width = 121
Height = 21
TabOrder = 0
Text = 'GARY'
end
object Button1: TButton
Left = 16
Top = 8
Width = 75
Height = 25
Caption = 'Open File'
TabOrder = 1
OnClick = Button1Click
end
object btLocateName: TButton
Left = 16
Top = 40
Width = 75
Height = 25
Caption = 'Loc Name'
TabOrder = 2
OnClick = btLocateNameClick
end
object btLocateRef: TButton
Left = 16
Top = 64
Width = 75
Height = 25
Caption = 'Loc Ref'
TabOrder = 3
OnClick = btLocateRefClick
end
end
object IB_Query1: TIB_Query
DatabaseName = 'C:\Offroad\IB\ORInventory.gdb'
FieldsDisplayWidth.Strings = (
'NC_REFERENCE=108')
IB_Connection = formIBData.cnMain
SQL.Strings = (
'select nc_id, nc_name, nc_reference'
'from netcomin')
ColorScheme = False
MasterSearchFlags = [msfOpenMasterOnOpen, msfSearchAppliesToMasterOnly]
OrderingItemNo = 1
OrderingItems.Strings = (
'byname=nc_name, nc_id; nc_name desc, nc_id desc'
'byreference=nc_reference, nc_id; nc_reference desc, nc_id desc')
OrderingLinks.Strings = (
'nc_name=1'
'nc_reference=2')
BufferSynchroFlags = []
FetchWholeRows = True
Left = 384
Top = 16
end
object IB_DataSource1: TIB_DataSource
Dataset = IB_Query1
Left = 304
Top = 16
end
end
----
Reposting this problem since I have received solution
----
I have run into a problem. I need query.locate to
position to the first record with a value, even if
the record ordering has been changed since the query
was opened. That doesn't happen currently, or I am
doing something wrong. By the way the file has about
60000 records.
If I open query of:
SELECT NC_ID, NC_Name, NC_REFERENCE
from NetComIn order by NC_Reference
perform a
query.locate(('NC_Reference', 'GARY', []);
it will position to the first 'GARY'
However if I have a query of:
SELECT NC_ID, NC_Name, NC_REFERENCE
from NetComIn
with the following OrderingLinks
ByType=NC_name, NC_ID desc; NC_Type desc, NC_ID desc
ByReference=NC_REFERENCE, NC_ID desc; NC_REFERENCE desc, NC_ID desc
perform a
query.locate(('NC_Reference', 'GARY', []);
it will NOT position to the first 'GARY'
Change the ordering to us the 'ByReference' one and
do the locate it still doesn't find the first record.
--------
Using First before the locate doesn't help.
However some additional info on what is happening:
1. It seems that the record that is located is always
the same no matter which order the file is in.
2. That record is the first with the code when the
file is retrieved unordered.
This seems to indicate that when orderinglinks are
used to determine the order of the records. "Locate"
must use a method like:
select first 1 * from netcomin
where nc_reference = 'GARY'
to determine the record ID of the record to position
to then scans the keys to find the record. When I
issue the SQL statement above it goes to the record
that locate is finding.
Also, adding [lopPartialKey, lopFindNearest] to the locate
causes it to find a different record but still not the first
one.
You will find below the code and components I used
to do this.
I hope you all have some ideals?????
Thanks
Michael L. Horne
unit fTest;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, IB_Components, Grids, IB_Grid;
type
TformTest = class(TForm)
IB_Query1: TIB_Query;
IB_Grid1: TIB_Grid;
IB_DataSource1: TIB_DataSource;
Panel1: TPanel;
edLocate: TEdit;
Button1: TButton;
btLocateName: TButton;
btLocateRef: TButton;
procedure Button1Click(Sender: TObject);
procedure btLocateNameClick(Sender: TObject);
procedure btLocateRefClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
formTest: TformTest;
implementation
{$R *.dfm}
procedure TformTest.Button1Click(Sender: TObject);
begin
ib_Query1.Close;
ib_Query1.Open;
end;
procedure TformTest.btLocateNameClick(Sender: TObject);
begin
ib_Query1.Locate('NC_Name', edLocate.Text, [lopPartialKey,
lopFindNearest]);
end;
procedure TformTest.btLocateRefClick(Sender: TObject);
begin
// qyNetComIn.Locate('NC_Reference', 'GARY', [lopPartialKey,
lopFindNearest]);
ib_Query1.Locate('NC_Reference', edLocate.Text, []);
end;
end.
object formTest: TformTest
Left = 314
Top = 480
Width = 661
Height = 434
Caption = 'formTest'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object IB_Grid1: TIB_Grid
Left = 0
Top = 97
Width = 653
Height = 310
CustomGlyphsSupplied = []
DataSource = IB_DataSource1
Align = alClient
TabOrder = 0
end
object Panel1: TPanel
Left = 0
Top = 0
Width = 653
Height = 97
Align = alTop
Caption = 'Panel1'
TabOrder = 1
object edLocate: TEdit
Left = 160
Top = 8
Width = 121
Height = 21
TabOrder = 0
Text = 'GARY'
end
object Button1: TButton
Left = 16
Top = 8
Width = 75
Height = 25
Caption = 'Open File'
TabOrder = 1
OnClick = Button1Click
end
object btLocateName: TButton
Left = 16
Top = 40
Width = 75
Height = 25
Caption = 'Loc Name'
TabOrder = 2
OnClick = btLocateNameClick
end
object btLocateRef: TButton
Left = 16
Top = 64
Width = 75
Height = 25
Caption = 'Loc Ref'
TabOrder = 3
OnClick = btLocateRefClick
end
end
object IB_Query1: TIB_Query
DatabaseName = 'C:\Offroad\IB\ORInventory.gdb'
FieldsDisplayWidth.Strings = (
'NC_REFERENCE=108')
IB_Connection = formIBData.cnMain
SQL.Strings = (
'select nc_id, nc_name, nc_reference'
'from netcomin')
ColorScheme = False
MasterSearchFlags = [msfOpenMasterOnOpen, msfSearchAppliesToMasterOnly]
OrderingItemNo = 1
OrderingItems.Strings = (
'byname=nc_name, nc_id; nc_name desc, nc_id desc'
'byreference=nc_reference, nc_id; nc_reference desc, nc_id desc')
OrderingLinks.Strings = (
'nc_name=1'
'nc_reference=2')
BufferSynchroFlags = []
FetchWholeRows = True
Left = 384
Top = 16
end
object IB_DataSource1: TIB_DataSource
Dataset = IB_Query1
Left = 304
Top = 16
end
end