Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- The Guide To Clipper - <b>index</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
INDEX


Syntax:     INDEX ON <key exp> TO <file>/(<expC>)

Purpose:    To create a file that contains an index to records in the
            current database file.

Arguments:  <key exp> is an expression that returns the key value to
            place in the index for each record in the current database
            file.  The maximum length of the index key expression is 250
            characters.

            <file> is the name of the index file to create.
            Normally, the file extension is (.ntx).  If, however, you
            have linked NDX.OBJ in order to use dBASE III PLUS
            compatible index files, the extension is (.ndx).

Usage:      When an index file is used, the database records appear in
            key expression order although the index does not alter the
            physical order of records in the database file.  This allows
            you to create and maintain many logical orders of records
            automatically.

            Deleted and filtered records: Records that are filtered
            or marked for deletion are included in the index.

            Date indexes: Clipper supports date indexes for both
            (.ntx) and (.ndx) index types.  For a key expression that
            includes a date as a subset of the key, create the
            expression as character type and use DTOS() to convert the
            date to character. For example:

            USE Invoices
            INDEX ON Customer + DTOS(Inv_date) TO Invoice

            Descending order indexes: To create descending order
            indexes or descending suborders, use DESCEND().  This
            function accepts any data type as an argument and returns
            the value in complemented form.  Then when performing a SEEK
            into the index use DESCEND() as a part of the SEEK argument.

            Compatible index files: Clipper supports dBASE III PLUS
            compatible index files by linking NDX.OBJ.

            Unique indexes: When you INDEX with UNIQUE ON, Clipper
            creates an index with uniqueness as an attribute.  As
            indexing proceeds and two or more records have the same key
            value, Clipper includes only the first record in the index.
            Whenever the unique index is updated, REINDEXed, or PACKed,
            only unique records are added.  Note that a unique index
            retains the uniqueness attribute, and is unaffected by
            subsequent settings of UNIQUE.

            Note that this differs from previous versions of Clipper
            where UNIQUE was a global SETting and applied to the
            creation and updating of all open indexes.

            TRIM() in key expressions: Index key sizes under Clipper
            are calculated by evaluating the key expression on a blank
            record.  The TRIM() of a field, therefore, always evaluates
            to a null string ("") when the key size is being
            determined.  This can lead to a size mismatch between the
            target and the defined key length.  You can, however, build
            an index key on the TRIM() of a field as long as you pad the
            key with the number of spaces equal to the length of all the
            trimmed fields.  For example, suppose you have two fields,
            Last and First, each 20 characters in length.  You want to
            INDEX on the following expression:

            TRIM(Last) + First

            The actual expression you INDEX ON is this:

            SUBSTR(TRIM(Last) + First + SPACE(20), 1, 40)

            Note also that attempting to save space in index files by
            using TRIM() has no effect since Clipper allocates space for
            keys in fixed increments.  To create smaller index files,
            create smaller fixed length keys using SUBSTR() in place of
            TRIM().

Library:    CLIPPER.LIB


----------------------------------- Examples -------------------------------

   ? TYPE("Branch")                  && Result: C
   INDEX ON Branch TO Branch

   ? TYPE("Amount")                  && Result: N
   INDEX ON Amount TO Amount

   ? TYPE("Date")                    && Result: D
   INDEX ON Date TO Date


   The following examples create descending order indexes.

   USE Invoices
   INDEX ON DESCEND(Inv_date) TO Inv_stack
   INDEX ON Customer + DESCEND(DTOS(Inv_date)) TO Inv_stack


See Also: REINDEX SET UNIQUE USE DTOS() SOUNDEX()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson