xHarbour Reference Documentation > Command Reference xHarbour Developers Network  

SEEK

Searches a value in an index.

Syntax

SEEK <expression> [LAST] [SOFTSEEK]

Arguments

<expression>
This is an arbitrary expression whose value is searched in the controlling index. The data type of the value must match with the data type of the index expression.
LAST
This option determines the record to begin the search with if there are multiple records having the same index value. By default, the search starts with the first of multiple records.
SOFTSEEK
This option controls the position of the record pointer when the searched value is not found. If omitted, the record pointer is positioned on the ghost record (Lastrec()+1). When SOFTSEEK is specified and the value is not found, the record pointer is positioned on the record with the next higher index value.

Description

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.

Info

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

Example

// 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

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe