xHarbour Reference Documentation > Command Reference |
Searches a value in an index.
SEEK <expression> [LAST] [SOFTSEEK]
The SEEK command searches a value in the controlling index. When the value is found, the record pointer is positioned on this record and function Found() returns .T. (true). When the value is not found in the index, the record pointer is positioned on Lastrec()+1 (without SOFTSEEK) or on the record having the next higher index value (with SOFTSEEK). In either case, function Found() returns .F. (false). If SOFTSEEK is used and no higher index value is found, the record pointer is positioned on Lastrec()+1, and function Eof() returns .T. (true).
The LAST option is useful if the searched value is found in multiple records. By default, the record pointer is positioned on the first of multiple records matching the search value. With the LAST option specified, the record pointer is positioned on the last of multiple records matching the search value.
Note: When the index expression yields a value of data type Character, the search value can be a character string that contains one character up to the length of the index value. When the searched value is shorter than the index value, the search includes only Len(<expression>) characters.
See also: | DbSeek(), Eof(), Found(), LOCATE, SET SCOPE, SET SOFTSEEK, Set() |
Category: | Database commands , Index commands |
Source: | rdd\dbcmd.c |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// The example demonstrates different search conditions and values based // on the names "Jane Doe" and "John Doe" PROCEDURE Main USE Test INEX ON Upper(Lastname+FirstName) TO Test ? Len( FIELD->LASTNAME) // result: 15 SEEK "A" ? Found(), Eof(),Trim(Lastname) // result: .F., .T., "" SEEK "A" SOFTSEEK ? Found(), Eof(),Trim(Lastname) // result: .F., .F., "Doe" SEEK "DOE" ? Found(), Eof(),Trim(Firstname) // result: .T., .F., "Jane" SEEK "DOE" LAST ? Found(), Eof(),Trim(Firstname) // result: .T., .F., "John" RETURN
http://www.xHarbour.com