xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

OrdSkipUnique()

Navigates to the next or previous record that has another index value.

Syntax

OrdSkipUnique( [<nDirection>] ) --> lSuccess

Arguments

<nDirection>
This parameter specifies the direction to move the record pointer. If <nDirection> is a negative numeric value, the record pointer is moved up (towards the begin of file). If <nDirection> is NIL, 0 or a positive numeric value, the record pointer is moved down (towards the end of file).

Return

The function returns .T. (true) when the record pointer is moved to the next/previous record having a different index value.

Description

OrdSkipUnique() navigates the record pointer in an indexed database as if the UNIQUE flag was set for the controlling index. If the controlling index is a regular index without the UNIQUE flag, it may contain identical index values for multiple records of the database. As a result, records that have duplicate index values can be navigated to with DbSkip().

If logical database navigation should ignore records having duplicate index values, function OrdSkipUnique() can be used. This function navigates the record pointer from the current record to the first/previous record whose index value differs from the current one.

When OrdSkipUnique() is used for record pointer movement, the visibility of records is the same as if an INDEX is created with the UNIQUE flag.

Info

See also:DbOrderInfo(), INDEX, OrdCreate(), OrdDescend(), OrdIsUnique()
Category: Database functions , Index functions
Source:rdd\dbcmd.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example creates a database and fills it with data from
// the string "cNames", thus creating duplicate index keys. The
// database is scanned from the first to the last record, but
// the next record is navigated to using OrdSkipUnique(). As
// a result, only four records of 14 show up in the result array.

   PROCEDURE Main
      LOCAL i, aResult
      LOCAL cNames := "AADDDDDCCCBBBB"
      LOCAL aStruct := { {"NAME", "C", 10, 0 } }

      // create database and index
      DbCreate( "TEST.DBF", aStruct )
      USE Test EXCLUSIVE
      INDEX ON Name TO Test

      // fill database using string data
      FOR i:=1 TO Len( cNames )
         APPEND BLANK
         REPLACE FIELD->NAME WITH Replicate( cNames[i], 3 )
      NEXT

      // collect result of OrdSkipUnique() navigation
      // in array "aResult"
      GO TOP
      aResult := Array(0)

      DO WHILE .NOT. Eof()
         AAdd( aResult, Trim( FIELD->NAME ) )
         OrdSkipUnique()
      ENDDO

      // Length of input data
      ? Len( cNames )                     // result: 14
      ? LastRec()                         // result: 14

      // Length of output data
      ? Len( aResult )                    // result: 4

      AEVal( aResult, {|c| QOut(c) } )

      // output:
      // AAA
      // BBB
      // CCC
      // DDD

      USE
   RETURN

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