updating oE db_find_key

Managing Records


include eds.e 
namespace eds 
public function db_find_key(object key, object table_name = current_table_name) 

finds the record in the current table with supplied key.

  1. key : the identifier of the record to be looked up.
  2. table_name : optional name of table to find key in

An integer, either greater or less than zero:

  • If above zero, the record identified by key was found on the current table, and the returned integer is its record number.
  • If less than zero, the record was not found. The returned integer is the opposite of what the record number would have been, had the record been found.
  • If equal to zero, an error occured.

If the current table is not defined, it returns 0 .


A fast binary search is used to find the key in the current table. The number of comparisons is proportional to the log of the number of records in the table. The key is unique--a table is more like a dictionary than like a spreadsheet.

You can select a range of records by searching for the first and last key values in the range. If those key values don't exist, you'll at least get a negative value showing io:where they would be, if they existed.

For example, suppose you want to know which records have keys greater than "GGG" and less than "MMM". If -5 is returned for key "GGG", it means a record with "GGG" as a key would be inserted as record number 5 . -27 for "MMM" means a record with "MMM" as its key would be inserted as record number 27. This quickly tells you that all records, >= 5 and < 27 qualify.

Example 1:
rec_num = db_find_key("Millennium") 
if rec_num > 0 then 
    ? db_record_key(rec_num) 
    ? db_record_data(rec_num) 
    puts(2, "Not found, but if you insert it,\n") 
    printf(2, "it will be #%d\n", -rec_num) 
end if 
See Also:

db_insert, db_replace_data, db_delete_record, db_get_recid

Not Categorized, Please Help


Quick Links

User menu

Not signed in.

Misc Menu