PDA

View Full Version : Can't seem to get keylookup to work



avianmanagement
2018-11-02, 05:37
I have two tables danimal and dtaxon

Index key in dtaxon is called PRIMARY
I want to return the common name from the dtaxon table when passed the foreigne key for it from danimal

Using the following code in the console simply return .F. . What am I doing wrong here?

open database aim
use danimal in 0
? keylookup("dtaxon","PRIMARY",danimal.cfk_dtaxon,ccommon,"not found")

barrymavin
2018-11-02, 05:53
Hi David,

KEYLOOKUP(<workarea> | <"alias"> | <"table">, <"indextagname">, <keyExpr>, <resultExpr> [, <notfoundExpr>])

That should all work. Sorry my previous reply was incorrect. The table is opened if it isn't already open.

avianmanagement
2018-11-02, 06:01
Hi Barry,

In the documentation is only seems to be opeing one table
open database southwind
use orders in 0
? keylookup("employees","employeeid",orders.employeeid, lastname, "not found")

If I try

open database aim
use danimal in 0
use dtaxon in 0
? keylookup("dtaxon","PRIMARY",danimal.cfk_dtaxon,ccommon,"not found")

It still returns .F.

Maybe the name of the index being PRIMARY is an issue as maybe a keyword ?

barrymavin
2018-11-02, 06:18
No the index tag name is not a problem.

Try seeking to danimal.cfk_dtaxon in dtaxon and inspecting it.

barrymavin
2018-11-02, 06:22
It will return false if it cannot find the index tag.

avianmanagement
2018-11-02, 06:37
Display index for dtaxon is showing as blank for some reason. I imported the tables.

Danimal index shows when I use display index.

I'll play around and find out what there is no index on that table.

Would it be possible for the system to create the index on the fly if it was not there ?

avianmanagement
2018-11-02, 06:40
select dtaxon
display index
Show nothing

create index dtaxon on dtaxon (ccommon)

shows
Production DBX file: dtaxon.dbx
Master Index TAG: DTAXON
Key: CCOMMON
Type: Character
Len: 158


create index dtaxon on dtaxon (Primary)

shows

Fri Nov 2 14:38:42 2018
**** Lianja error ****
create index dtaxon on dtaxon (primary)
^
Expression was expected

So it looks as though I'll have to alter the primary key name in all my tables, this was imported from VPM

avianmanagement
2018-11-02, 06:47
Works fine when I have the index there.

Thanks Barry