RE: Database key wildcard search

new topic     » goto parent     » topic index » view thread      » older message » newer message

Sorry, forgot to show how to find all matches...(also had a bug in case the
exact 'wc' was found)...

-- Begin code
 
include wildcard.e

function next_wild( sequence wc, sequence wcfull, atom rec, atom size )
    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
    return 0
end function

function wildkey( sequence wc, sequence wcfull )
    atom rec, size
    
    size = db_table_size()
    rec = db_find_key( wc )
    if rec < 0 then
        rec = -rec
    end if
    return next_wild( wc, wcfull, -rec, size )
end function

function all_wildkey( sequence wc, sequence wcfull )
    sequence keys
    atom rec
    size = db_table_size()
    rec = db_find_key( wc )
    keys = {}
    if rec < 0 then
        rec = -rec
    end if
    rec = next_wild( wc, wcfull, rec, size )
    while rec do
        keys &= rec
        rec += 1
        rec = next_wild( wc, wcfull, rec, size )
    end while
    return keys
end function

? wildkey( "find_th", "find_th?s_???" )
? all_wildkey( "find_th", "find_th?s_???" )

-- End code

Matt Lewis

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu