dbTalk Databases Forums  

Reading an Index

comp.databases.pick comp.databases.pick


Discuss Reading an Index in the comp.databases.pick forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
ddspell-m3
 
Posts: n/a

Default Reading an Index - 02-15-2007 , 08:19 PM






I've been told to do this:
You may want to use the 'R' operator as it returns an exact match.
e.g.

INVNO = {Something Input}
A.CODE = 'A30'
ROOT 'SHIP', A.CODE TO ROOT.ID THEN
KEY('R', ROOT.ID, INVNO, SHIPID) THEN

Reply With Quote
  #2  
Old   
Mark Brown
 
Posts: n/a

Default Re: Reading an Index - 02-16-2007 , 01:15 AM






What you want to do is use the "R" operator to find the first hit, then use
the "N" to find the next key in the sequence. At each hit, compare with the
original key and as long as it's the same, continue processing. For
example:

kx = invno
idx = ''
key('r',root.id,kx,idx) then
loop
<process first hit here>
key('n',root.id,kx,idx) then
if kx # invno then exit
end else exit
repeat
end else

end


Mark Brown


"ddspell-m3" <ddspell (AT) gmail (DOT) com> wrote

Quote:
I've been told to do this:
You may want to use the 'R' operator as it returns an exact match.
e.g.

INVNO = {Something Input}
A.CODE = 'A30'
ROOT 'SHIP', A.CODE TO ROOT.ID THEN
KEY('R', ROOT.ID, INVNO, SHIPID) THEN
.
...Do whatever you want here
.
END ELSE
.
...Process error if entered INVNO not found
.
END
END

Hope this helps.

Bill H.

-----------------------------------------
This works, but how do I get the next SHIPID?
I can get all the SHIPIDs if I use the 'X' operator, but the problem
with this is that it won't do an exact match like the 'R' operator
does. How do I get the functionality of both operators in one?


Thanks,
Danny




Reply With Quote
  #3  
Old   
ddspell-m3
 
Posts: n/a

Default Re: Reading an Index - 02-16-2007 , 11:52 AM



On Feb 16, 1:15 am, "Mark Brown" <mbr... (AT) drexelmgt (DOT) com> wrote:
Quote:
What you want to do is use the "R" operator to find the first hit, then use
the "N" to find the next key in the sequence. At each hit, compare with the
original key and as long as it's the same, continue processing. For
example:

kx = invno
idx = ''
key('r',root.id,kx,idx) then
loop
process first hit here
key('n',root.id,kx,idx) then
if kx # invno then exit
end else exit
repeat
end else

end

Mark Brown
Thanks for the help. I modified what you gave me and this is what I
did:
SHIP.ID = A$ID
SALES.IDS = NIL
KEY('R', SHIP.IDX, SHIP.ID, SALES.ID) THEN
SALES.IDS<-1> = SALES.ID

LOOP
KEY('N', SHIP.IDX, SHIP.ID, SALES.ID)
UNTIL SHIP.ID # A$ID DO
SALES.IDS<-1> = SALES.ID
REPEAT

Z = DCOUNT(SALES.IDS, FM)
FOR I = 1 TO Z
..
..
..
<processing>
..
..
..
NEXT I
END



Reply With Quote
  #4  
Old   
Scott Ballinger
 
Posts: n/a

Default Re: Reading an Index - 02-16-2007 , 04:48 PM



I have never found the D3 btree syntax to be particularly intuitive,
so a long time ago I wrote a subroutine to do the heavy lifting. This
also has the advantage of making code portable to UV and other
environments.

/Scott Ballinger
Pareto Corporation
Edmonds WA USA
206 713 6006

subroutine get.btree.sub(filename,fieldname,thing,result)
* Get result id(s) from the btree index fieldname for filename.
* Result is mv if more than 1 id found for thing.
* If thing ends with ] then return all starting with thing.
* If thing doesn't end with ] then return all exactly matching thing.
* If thing requires an iconv (e.g. a date) then iconv before passing
it.

* Prepend an "x" to strings to make sure we compare strings not
numbers,
* e.g. bank-routing-number dot account-number may get interpreted as a
* large number with a lot of decimal places, and precision limitation
* would erroneously return 123456789.1234567891000 =
123456789.123456789
* note least significant digits ignored ^^^^

begin case
case fieldname matches "'a'0n"
ac = fieldname
case fieldname matches "0n"
ac = "a":fieldname
case 1
open "dict",filename to dict.filevar else
stop 201,"dict ":filename
end
read rec from dict.filevar,fieldname then
if rec<8>[1,1] eq "a" then
ac = rec<8>
end else
ac = "a":rec<2>
end
end else
print "error! can't read item ":fieldname:" in dict ":filename
stop
end
end case

root filename,ac to fileroot else
print "error! no index defined for
":filename:",":ac:" (":fieldname:")
stop
end

lent = len(thing)
if thing[lent,1] eq "]" then
wildcard = 1
lent -= 1
thing = thing[1,lent]
end else
wildcard = 0
end

search = thing
result = ""
id = ""
done = 0
xthing = "x":thing ;* make sure we compare strings not numbers

loop
key("x",fileroot,search,id) then
if wildcard then
if "x"search[1,lent]) ne xthing then done = 1
end else
if "x":search ne xthing then done = 1
end
end else
done = 1
end
until done do
result<-1> = id
repeat

convert @am to @vm in result

return




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.