PDA

View Full Version : Index not setting


ABC123

Tom Henkel
01-27-2005, 10:03 AM
OK,

We have a script that is supposed to reset the primary index to a specific index, then fetch all records with a certain key using that index.

When we do the "tbl".index_primary_put("FULLNAME"), there is no error given. When we do a fetch_find using a specific key, the FIRST record with that key is returned.

Now the issue. We know that 5 records have this specific key. A "fetch_next" SHOULD retrieve the next record with that key. It appears like we are in RECORD NUMBER order. We have been looking at this script for hours.

If anyone has a clue as to what is going wrong, please let me know.

Script and DEBUG screen are attached.

Thanks,

Tom

Steve Workings
01-27-2005, 11:15 AM
Haven't studied it all to completely understand it Tom, but:

A couple notes within this snippet:

--------
indx = v_int.index_primary_put("FULLNAME")
nxt:
f = v_int.fetch_next(1)
--------

(1)
Setting the index again here will fetch to the first record as well. Try commenting that out.

(2)
There's no reason to specify the fetch level in the fetch_next() command, since you've already identified the table with v_int. Just use the function without the fetching level.

(3)
How about controlling your loop with something like this pseudo code:

i = 1
While v_int.name = N1 .and. .not. v_int.name.eof()
.. do stuff
i = i + 1
v_int.fetch_next()
end while

You have some added complexity in there I wish I had time to figure out, but busy day...

Let us know.

- Steve

Tom Henkel
01-27-2005, 11:33 AM
Steve,

Thanks, I will pass this on to the programmer, and we will let you know.

Tom

Finian Lennon
01-27-2005, 08:31 PM
Tom:

I think it would be a lot easier for you to do a query rather than a fetch_find, particularly if there is the likelihood of finding multiple matching records.

I would use the index_pointer=table.order(order,filter,expression)
method which functions much like table.query_create. Make your order expression the same as the index defintion so that you will get the speed you want. After that you can process the results using a while .not. table.fetch_eof(), end while loop.

With table.order, you can dispense with the index_primary_put() commands which will fail in the event that the indexname should change. You will still get the performance as long as a matching index exists.

I'm not sure why the script doesn't work as you expect. I only use fetch_find() in circumstances where I expect that only a single record of that value will exist or not. Otherwise I use a query.

Finian

Tom Henkel
01-31-2005, 05:33 AM
Thanks, Finian,

I think that we have worked this out. Steve andrews and Hubert, my programmers have worked it out. We are attempting to put together a list box for the user to select from. In this particular table,ter may not be any one specific unique key for the records. We know that names will be availabel, and maybe more than once. It is a particularly difficult situation, but, as I said, they did work it out. We will try your solution, however.

Tom

Finian Lennon
01-31-2005, 02:16 PM
If you are doing any kind of a list box, then table.external_record_content_get() with the same query and order parameters is probably the best place to start.

Finian