RE: Database key wildcard search
- Posted by Matthew Lewis <matthewwalkerlewis at YAHOO.COM> Dec 18, 2001
- 562 views
void wrote: > Is it possible to search a record with a partial key (key with > wildcards). > > now we have: > rec = db_find_key("find_this_key") > > a function like this would be very useful: > rec = db_find_key_wildc("find_th?s_???") > > It should be possible to build such a function, but key_pointer > structure is a bit too complicated for me, can someone offer some help? > > (I think an integer 'starting_rec' is needed to do multiple searches: > rec = db_find_key_wildc("find_th?s_???", starting_rec) You can almost do this: rec = db_find_key("find_th") should return a negative value (assuming it doesn't exist). You can then start looking at records starting at the absolute value of rec: -- Begin code include wildcard.e function wildkey( sequence wc, sequence wcfull ) atom rec, found, size found = 0 size = db_table_size() rec = db_find_key( wc ) if rec > 0 then return rec else rec = -rec if rec > size then return 0 end if key = db_key( rec ) while match(wc,key) = 1 do if wildcard_match( wc_full, key ) = 1 then return rec end if rec += 1 if rec > size then return 0 end if key = db_key( rec ) end while end if return 0 end function ? wildkey( "find_th", "find_th?s_???" ) -- End code wc is the search string up to the first wildcard, and wc is the full wildcard. Matt Lewis