db - Petewg/harbour-core GitHub Wiki

Back to Home

Database handling functions db***() , hb_db***(), f***() & ord***()

Database functions

  • dbAppend([<lUnLockAll>]) ➜ <lSuccess>
    this function attempts to add a new empty record to the end of the database in the current or aliased work area.
    By default the [<lUnLockAll>] argument is .T., which means that all pending locks are released. In "pending locks" included all previously locks made either explicitly by one or more RLock() or by a precedent dbAppend() call. However, if the work-area is shielded by an FLock() or the so-called "ghost record" (LastRec()+1), for some inconceivable reason, is locked, the append operation will fail the dbAppend() will return .F. and NetErr() will emit a .T.!

  • __dbApp(<cNameName>, [<aFields>], [<bFor>], [<bWhile>], [<nNext>], ;
    [<nRecord>], [<lRest>], [<cRDD>], [<nConnection>], [<cCodePage>], ;
    [<xDelimiter>]) ➜ <lSuccess>

    This function is the "functionalized" counterpart of APPEND FROM command. In fact, the APPEND FROM command is literally transcribed by preprocessor as __dbApp(...), via a #command found into /include/std.ch header file, which file is automatically included/preprocessed by the compiler on every compilation. It has the advantage that it can be used in expressions and/or code-blocks as argument, where the command APPEND FROM cannot.

  • dbClearFilter() ➜ NIL
    clears any active filter condition for the current or aliased work area.

  • dbClearIndex() ➜ NIL
    closes all indexes open in the current work area.

  • dbClearRelation() ➜ NIL
    clears all active relations in the current work area.

  • dbCloseAll() ➜ NIL
    close all open databases, associated indexes and format files and moves the work area pointer to the first position.

  • dbCloseArea() ➜ NIL
    closes an open database (if any) in the selected or aliased work area.

  • dbCommit() ➜ NIL
    physically updates (i.e. writes any changes to disk) a database and all related index buffers for the current or aliased work area only. NOTE: using this function as soon as possible after updating a database file, ensures that any changes made would be immediately visible to other processes. It's recommended to be invoked before UNLOCK-ing record/file.

  • dbCommitAll() ➜ NIL
    Flushes the memory buffer and performs a hard-disk write for all work areas. IOW, it's same as above but affects ALL work areas.

  • __dbCopy(<cNameName>, [<aFields>], [<bFor>], [<bWhile>], [<nNext>], [<nRecord>], [<lRest>], ;
    [<cRDD>], [<nConnection>], [<cCodePage>], [<xDelimiter>]) ➜ <lSuccess>

    This function is the "functionalized" counterpart of COPY TO command. In fact, the COPY TO command is transcribed as a call to this function via a #command found into /include/std.ch header file, which file is automatically included/preprocessed by the compiler on every compilation. It has the advantage that it can be used in expressions, where the command cannot.

  • dbCreate(<cFileName>,<aStruct>,[<cRDD>],[<lKeepOpen>],[<cAlias>],[<cDelimArg>],[<cCodePage>],[<nConnection>]) ➜ <lSuccess>
    Create a database file (a dbf) from a database structure array.
    <cFileName> is the name of the database file to be created. If an extension is not specified, .dbf is assumed.
    <aStruct> is an array that contains the structure of database as a series of sub-arrays, one per field. Each sub-array contains the definition of each field's attributes and has the following structure:

    Position Metasymbol Dbstruct.ch
    1 cName DBS_NAME
    2 cType DBS_TYPE
    3 nLength DBS_LEN
    4 nDecimals DBS_DEC

    <cRDD> specifies the replaceable database driver (RDD) to use, specified as a character expression. If not specified DBFNTX is used.
    4-th argument <lKeepOpen> is Boolean flag indicating if file should stay open (any Boolean value will enable this behavior). 5-th is alias and if not given then the work area will stay open but without any alias, not even the filename of created database (this is a notably different behavior than what happens when USE command or dbUseaArea() function are invoked, where if no alias provided, by default, the name of database file is used as alias).
    Note 1: the dbCreate() function does not check for duplicate field names. It could perfectly create fields with the same name, without any warning, with all unpredictable consequences of such an action. Developer alone has the responsibility to not use the same field name twice.
    Note 2: If <cRDD> is different than default DBFNTX, it must have been explicitly requested and linked (using a REQUEST statement in source code), before can it be used.

  • dbCreateIndex(<cIndexName>,<cKeyExpr>,<bKeyExpr>,[<lUnique>],[<cOrderName>]) ➜ NIL
    Legacy function that directly does call of ordCreate() function.

  • dbDelete() ➜ NIL
    Mark a record for deletion in a database. In network enabled applications record lock is required before invoke dbDelete()

  • dbDrop() ➜ <lSuccess>
    !depreciated! use 'hb_dbDrop()' instead, (look for it down, at hb_db** functions).

  • dbEdit([<nTop>], [<nLeft>], [<nBottom>], [<nRight>], [<acColumns>], [<cUserFunction>], [<acColumnSayPictures> | <cColumnSayPicture>], [<acColumnHeaders>|<cColumnHeader>], [<acHeadingSeparators>|<cHeadingSeparator>], [<acColumnSeparators>|<cColumnSeparator>], [<acFootingSeparators>|<cFootingSeperator>], [<acColumnFootings>|<cColumnFooting>]) ➜ lResult
    Returns .T. or .F. if no dbf is open or invalid column specified.
    Detailed documentation of this function can be found at this link of Harbour Reference Guide.

  • dbEval(<bBlock>, [<bForCondition>], [<bWhileCondition>], [<nNextRecords>], [<nRecord>], [<lRest>]) ➜ NIL
    evaluates <bBlock> for all records in the current work area. A matching scope can be defined with <bFor>/<bWhile> blocks.

  • dbExists() ➜ lExists
    depreciated! use 'hb_dbExists()' instead.

  • Dbf() ➜ cAlias
    returns the alias name of the currently selected work area. Compatibility function superseded by the Alias()

  • dbFieldInfo(<nInfoType>, <nFieldPos>) -➜ xFieldInfo
    returns a field information from the replaceable database driver (RDD).
    Refer to dbinfo.ch and dbstruct.ch header files for available <nInfoTypes>.
    See also Field Handling Legacy functions down this page

  • dbFileGet(<nFieldPos>, <cTargetFile>, <nMode>) ➜ lSuccess
    <nFieldPos> is the position of the field in the database file, <cTargetFile> is the name of the file where the field data will be written, including an optional drive, directory and extension. If <cTargetFile> does not exist, it is created. If it exists and can be opened in exclusive mode the file is written to without warning or error. (check NetErr()).
    <nMode> can be: 1=APPEND or 0=OVERWRITE (default).

  • dbFilePut(<nFieldPos>, <cSourceFile>)➜ lSuccess
    Insert the contents of a file into a field. <nFieldPos> is the position of the field in the database file, <cSourceFile> is the name of the file containing the data to insert, including an optional drive, directory and extension. If the file does not exist, RTE occurs. NetErr() could checked for other errors.

  • dbFilter() ➜ cFilter
    returns a character string containing the filter expression of a work area, or a null string ("") when no filter is set.

  • DbfSize() ➜ nSize
    returns the size of a dbf file opened in current wrkarea or 0 if no dbf is opened.

  • dbGoBottom() ➜ NIL
    moves to the last logical record in the current work area.

  • dbGoTo(<nRecno>) ➜ NIL
    Position record pointer to a specific identity which for Xbase .dbfs is record number. In other data formats, <xIdentity> is the unique primary key value.

  • dbGoTop() ➜ NIL
    Move to the first logical record.

  • dbInfo(<nInfoType>, [<expNewSetting>]) ➜ uCurrentSetting
    return and optionally change information about a database file opened in a work area.
    The <nInfoType> argument determines the type of information, as specified by constants defined in the dbinfo.ch header file. Worth to note that not all those constants (and the supplied by them info) are supported on all RDDs.

  • __dbLocate(<bFor>,[<bWhile>],[<nNext>],[<nRecno>],[<lRest>]) ➜ NIL
    This is the "functionalized" version of LOCATE command.

       (alias)->( __dbLocate( {|| (alias)->Fieldname == xVal } ) )

    Suggested for use in cases where the relevant command is not convenient or applicable, f.e. into code-blocks or in expressions, --not to mention that it'd possibly be an attractive option for any 'command-haters' out there... :-)

  • dbOrderInfo(<nInfoType>, [<cIndexFile>], [<cOrder> | <nPosition>], [<expNewSetting>]) ➜ uCurrentSetting
    return and optionally change information about orders and index files. Refer to 'dbinfo.ch' header file for more.

  • dbRecall() ➜ NIL
    removes the deletion flag from a record marked as deleted. Requires record lock if shared (network) is enabled.

  • dbRecordInfo(<nInfoType>, [<nRecord>], [<expNewSetting>]) ➜ uCurrentSetting
    return and optionally change information about a record. See 'dbInfo()' and 'dbinfo.ch' for more.

  • dbReindex() ➜ NIL
    rebuilds all open indexes in the current work area.

  • dbRelation(<nRelation>) ➜ cLinkExpression
    returns a character string containing the relation expression specified with <nRelation>, or a null string ("") when no relation exists for <nRelation>.

  • dbRename(<cTable> [,<cIndex>], <cNewName>, [<cRDD>], [<nConnect>]) ➜
    Refer to 'hb_dbRename()' for more.

  • dbRLock([<nRecno>]) ➜ lSuccess
    If <nRecno> is not given, all active record locks are removed and the current record is locked. When <nRecno> is given, the function places a lock on this record and adds it to the list of active record locks. This list can be retrieved with function 'DbRLockList()'.

  • dbRLockList() ➜ aRecordLocks
    returns a list of locked records in the database work area.

  • dbRSelect(<nRelation>) ➜ nWorkArea
    returns the work area number of the relation specified with <nRelation> or zero if no relation is defined.

  • dbRUnlock([<nRecno>]) ➜ NIL
    releases record lock for <nRecno>. If no <nRecno> is passed function, all active record locks are released. (same as 'DbUnlock()').

  • dbSeek(<expKey>, [<lSoftSeek>], [<lFindLast>]) ➜ lFound

    • <expKey> is a value of any type that will be searched and specifies the key value (index key) associated with the desired record. If such a record is found, it becomes the current record and the function returns .T. (true); in any other case it returns .F. (false).
      Searching is performed on logical records which are considered in indexed order. If a filter is set, only records which meet the filter condition are considered. If the work area has more than one active index, the operation uses the controlling order as set by dbSetOrder() or the SET ORDER command.

    • <lSoftSeek> is an optional logical value which specifies whether a "soft seek" is to be performed or not, and directly affects where the record pointer shall positioned, in case the searched <expKey> value is not found.

      • for a normal not soft seek (i.e. when lSoftSeek==.F.), the record pointer is positioned to LastRec() + 1 and the Eof() returns .T. (true).
      • for a soft seek (i.e. when lSoftSeek==.T.), the record pointer is positioned to the first record whose key value is greater than the specified key value. If no such a record exists, the record pointer is positioned to LastRec() + 1 and the Eof() returns .T. (true), (in other words, result is same as normal (not soft) seek).
        If <lSoftSeek> is omitted, the current global _SET_SOFTSEEK setting is used.
    • <lFindLast> is an optional logical value that can specified as .T. (true) to seek the last occurrence of the specified key value. The default is .F. (false), which means to seek the first occurrence. Note: This parameter may not supported in all RDDs.

  • dbSelectArea(<nArea>|<cAlias>) ➜ NIL
    selects <nArea> or <cAlias> and set it as current work area.

  • dbSetDriver([<cRddName>]) ➜ cPreviousRDD
    retrieves and/or selects the default replaceable database driver.

  • dbSetFilter([<bCondition>], [<cCondition>]) ➜ NIL
    sets a filter condition in form of the code block . If <bCondition> is NIL (empty), it clears any active filter.

  • dbSetIndex(<cIndexName>) ➜ NIL
    Opens an index file, it does not change the controlling index, unless it is the first index to open.

  • dbSetOrder(<nOrdernum>) ➜ NIL
    Selects the controlling index.

  • dbSetRelation(<nArea> | <cAlias>, <bRelation>, <cRelation>, [<lScoped>]) ➜ NIL
    relates a parent work area with the child work area <nArea> or <cAlias>. Existing relations remain active.

  • dbSkip(<nRecords>) ➜ NIL
    Positive values for <nRecords> move the record pointer forwards (towards the end of file), negative values move it backwards. The default value is 1.

  • dbStruct() ➜ aStruct
    returns a two-dimensional array of four columns, filled with structural information of each field in the current database as follow: {cFieldName, cType, nLength, nDecimals}. See also 'DBSTRUCT.CH'.

  • dbTableExt() ➜ cFileExtension
    returns the default database file extension of the current RDD, f.e. .dbf.

  • dbUnlock() ➜ NIL
    releases all file and record locks, in the current work area.

  • dbUnlockAll() ➜ NIL
    releases all file and record locks, in all opened work areas.

  • dbUseArea([<lNewArea>], [<cRddName>], <cDatabase>, [<cAlias>], [<lShared>], [<lReadOnly>], [<cCodePage>], [<nConnection>]) ➜ lSuccess
    Attempts to open a database file and returns true (.T.) on success, otherwise false (.F.).
    This function is same, in functionality, as the standard USE command, yet more flexible.
    If <lNewArea> specified true (.T.) the file is opened in a new work area otherwise if is false (.F.) or omitted, the current area is used, which means any dbf that already is opened in the area will close.
    <cRddName> is optional name of the database driver which will be used. If omitted, the current default driver is used.
    <cDatabase> is the name of the database (.dbf) file to be opened.
    <xcAlias> is optional character value that defines the alias to be associated with the work area. If omitted, the filename without path and extension is used.
    <lShared> is optional logical value that specifies whether the file will be shareable to other users or not. If omitted, the current global _SET_EXCLUSIVE setting is used. <lReadonly> is the optional logical value that specifies whether the work area and the dbf file is writable or not. If omitted, it defaults to false (.F.), i.e., the file can be updated.
    <cCodePage> is the Harbour CP to be used by the work area.
    [<nConnection> (TODO!)

Harbour db_* extensions

  • hb_dbCreateTemp(<cAlias>, <aStruct>, [<cRDD>], [<cCodePage>], [<nConnection>]) ➜ lSuccess
    Creates a new temporary .dbf file, with structure specified by <aStruct>. The file is being created inside the temporary folder designated by the %temp% environment variable. After successful creation, it is opened, in exclusive mode, with the given cAlias alias and eventually, is deleted automatically, upon closing. All indexes created for this table, should ideally have the temporary flag on, so those get deleted too, when they closed.

  • hb_dbDetach([<nWorkArea>|<cAlias>], [<xCargo>]) ➜ lSuccess
    the function detaches a work-area from current thread and move it to special hidden holder. If no <nWorkArea>|<cAlias> specified, then the current work-area is used by default; if no work-area is in use (i.e. no file is open in area), a runtime error occurs (RTE: DBCMD/2001). Before detaching, all relations (parent and child) to detached workarea are cleared. Detached work-area can be restored from holder using hb_dbRequest() function (see bellow). For a working sample of "dbDetach/dbRequest" functions, see this sample found into Harbour/tests/mt/ folder).

  • hb_dbDrop(<cDbf>, [<cIndex>], [<cRDD>], [<nConnection>]) ➜ lSuccess
    Deletes database files and/or indexes. To delete a <cIndex> only, <cDbf> must defined as empty string "", otherwise RTE occurs.

  • hb_dbExists(<cDbf>, [<cIndex>], [<cRDD>], [<nConnection>]) ➜ lExist
    Checks if the given <cDbf> and/or <cIndex> exists. To check the existence of a <cIndex> only, the 1st argument <cDbf> must be specified/passed as empty string "", otherwise, if completely omitted or left uninitialized (i.e., NIL) then a "bad parameter" runtime error occurs. (note : including an extension to <cDbf> or <cIndex> filenames is optional; if no extension defined then assumed the default extension used by the current RDD).

  • hb_dbGetFilter() ➜ bCode|NIL
    returns codeblock used as work area filter or NIL if no filter is active.

  • hb_dbPack([<bBlock>, [<nEvery>]) ➜ NIL
    packs (i.e. physically removes records marked for deletion) a .dbf opened in current work area. <bBlock> is a code Block to execute after either every record or every <nEvery> group of records have already been processed. (Note: Actual function doing the zapping is the __DBPack() to which is internally "translated" the hb_dbPack())

  • hb_dbRename(<cDbf>, [<cIndex>], <cNewName> [<cRDD>], [<nConnection>]) ➜ lSuccess
    Renames a .dbf and/or index. To rename a <cIndex> only, <cDbf> must defined as empty string "", otherwise RTE occurs.

  • hb_dbRequest([<cAlias>], [<lFreeArea>], [<@xCargo>], [<lWait>|nWait]) ➜ lSuccess
    restores <cAlias> area from the holder (see hb_dbDetach() above) and attach it to calling thread. If no <cAlias> specified, then the oldest detached area into holder's queue is tried to be restored (FIFO method). If either the <cAlias> specified cannot be found or there is no area in the queue, the function will fail and return a .F. value. If the function succeeds, returns .T. and the restored work-area becomes current.
    The <lFreeArea> argument determines whether a new area or the current one will be used for restore. Default is .F., which means the restore will be done in the current work area, and any other file that might be open in this area, will be closed (worth to note that this closing will be done even if the function fails to restore the requested alias, --presumably because it's always being performed, before the restore attempt).
    <@xCargo> can be used to retrieve a possibly transmitted message/data between threads / processes.
    4-th parameter <lWait> flag specifies whether the function should wait (when lWait == .T.) until the requested working area becomes available or return immediately, (when lWait == .F., which is the default). Alternatively, instead of a Boolean flag, this 4-th parameter accepts a numeric value specifying timeout in seconds waiting for the requested area to become available, before returning.

  • hb_dbZap() ➜ NIL
    Unconditional (!) and permanent zapping (i.e., physically clearing all data) of a .dbf file, which is open in current work area. The deletion process includes not only the opened dbf file but any related memo and opened indexes files. (Note: Actual function doing the zapping is the __DBZap() to which is internally "translated" the hb_dbZap())

Field handling functions

  • FCount() ➜ nFields
    Returns the number of fields in the current work area.

  • FieldBlock(<cFieldName>) ➜ bFieldBlock
    returns a code block that, when evaluated, sets or gets the value of the given field. If <cFieldName> does not exist in the specified work area, it returns an empty block.

  • FieldDec()
    see hb_FieldDec() downward this page.

  • FieldGet(<nFieldPos>) ➜ xFieldValue or NIL
    returns the value of the field in the <nFieldPos> position or NIL for invalid <nFieldPos>.
    (see also the hb_FieldGet() function, below).

  • FieldLen()
    see hb_FieldLen() downward this page.

  • FieldName(<nFieldPos>) ➜ cFieldName
    returns the name of the field in the position as a character string, or a null string ("") for invalid <nFieldPos>.

  • FieldPos(<cFieldName>) ➜ nFieldPos
    returns the ordinal position of the field <cFieldName> in the work area. If there is no field with this name returns 0.

  • FieldPut(<nFieldPos>, <expAssign>) ➜ xValueAssigned or NIL
    returns the value assigned to the specified field, or NIL for invalid <nFieldPos>.
    (see also the hb_FieldPut() function, below).

  • FieldType()
    see hb_FieldType() downward this page.

  • FieldWBlock(<cFieldName>, <nWorkArea>) ➜ bFieldWBlock
    returns a code block accessing the field variable <cFieldName> in the <nWorkArea>, or NIL when an illegal parameter is passed. The code block accepts one parameter used to assign a value to the field.

Harbour field_* extensions

  • hb_FieldDec(<cField|nField>) ➜ nDecs
    retrieves the number of decimal places of a specified field in current or aliased workarea; it can be passed as field-name (character) or field-position (numeric).

  • hb_FieldGet(<cFieldName> | <nFieldPos>) ➜ xFieldValue or NIL
    harbour extension (added 2022-10-17) with same functionality as FieldGet() (see above), which allows, optionally, the use of field name (<cFieldName>) instead of field index (<nFieldPos>).

  • hb_FieldLen(<cField|nField>) ➜ nLenght
    retrieves the length of a specified field in current or aliased workarea; it can be passed as field-name (character) or field-position (numeric).

  • hb_FieldType(<cField|nField>) ➜ cType
    retrieves the data type of a specified field in current or aliased workarea; it can be given as field-name (character) or field-position (numeric).

  • hb_FieldPut(<cFieldName> | <nFieldPos>, <expAssign>) ➜ ValueAssigned or NIL
    harbour extension (added 2022-10-17) with same functionality as FieldPut() (see above), which allows, optionally, the use of field name (<cFieldName>) instead of field index (<nFieldPos>).

  • FLock() ➜ lSuccess
    returns .T. if the entire file in a work area successfully locked, otherwise .F.

  • Found() ➜ lSuccess
    returns .T. if the last search operation in a work area was successful. Returns .F. if nothing found or no work area is used.
    See also: dbSeek(), __dbSeek() and __dbLocate()

Order management functions

  • ordCondSet( [<cForCondition>], [<bForCondition>], [<lAllRecords>], [<bWhileCondition>], [<bEval>], [<nInterval>], [<nStart>], [<nNext>], [<nRecord>], [<lRest>], [<lDescend>], [<reserved>], [<lAdditive>], [<lCurrent>], [<lCustom>], [<lNoOptimize>], [<cWhileCondition>], [<lTemporary>], [<lUseFilter>], [<lExclusive>]) ➜ lSucces
    set the condition and scope for an order and returns true on success, false on error.

  • ordCount([<cOrderBagName>]) ➜ nOpenIndexes
    Returns the number of indexes that are open in a work area.
    NOTE: This function is a new Harbour function implemented in the original CA-Cl*pper namespace. This should have been marked as HB_EXTENSION, but it's not.

  • ordCreate(<cOrderBagName>,[<cOrderName>],<cKeyExpr>,[<bKeyExpr>],[<lUnique>]) ➜ NIL
    creates an order in an order-bag for the database open in the current work area.
    <cOrderBagName> is the name of the index file on disk, containing one or more orders. If no extension specified then is used the default extension of the used RDD (f.e.: .ntx for DBFNTX RDD)
    <cOrderName> is the name of the order; optional if <cOrderBagName> has specified.
    <cKeyExpr> is an expression that returns the key value which identifies the order and can represent character, date, logical, or numeric data types.
    <bKeyExpr> optional code block that evaluates to a key value that is placed in the order; it is macro-compiled from cKeyExpr, if omitted.
    <lUnique> is an optional logical value that specifies whether a unique order is to be created. If omitted, defaults to the current global _SET_UNIQUE.
    NOTE: this function accepts an other four (undocumented) arguments! To the best of my knowledge, they're used for Relational integrity constraint, perhaps intended to RDDs (?) that support such functionality; I've put it here, just as a reference: cConstrName --> Name of relational integrity constraint, cTargetName --> Name of target relation table, aRelationKey --> Array of columns in source table to match target primary key, lEnabled --> Is constraint enabled? That's all I was able to decipher after reading the sources!

  • ordDescend([<cOrder>|<nPosition>],[<cIndexFile>],[<lNewDescend>]) ➜ lCurrentDescend
    this function enables (when lNewDescend==.T.) or disables (lNewDescend==.F.) the descending seeking in an order/index during runtime; does not affect the actual descending flag created by the indexing processes which flag is 'physically' stored into the index file.
    If an invalid value for <cOrder>|<nPosition> is specified or the <cIndexFile> (if passed) is not open, a run-time error occurs. All arguments are optional.
    the function always returns the current state, i.e. the state before any change.

  • ordDestroy(<cOrderName>|<nOrderNum>[,<cOrderBagName>]) ➜ lResult
    this functions destroys (i.e. physically removes) the specified order from the current or from the given orderBag.
    <cOrderName>|<nOrderNum> is the name or the ordinal number of the order to be removed from the current or specified work area.
    <cOrderBagName> is the name of a disk file containing the orders. It might be specified as the file name with or without the path name. If no extension included, the default extension of the current RDD is used.
    Warning: in Harbour Reference Guide it is, incorrectly, pointed out that "ordDestroy() is not supported for DBFNDX and DBFNTX". I do not know about DBFNDX (never have used it), but in DBFNTX rdd, this function is perfectly supported!. Also, the returned value of ordDestroy() is Boolean (true or false, denoting, obvioulsy, the result of the operation) and not NIL as it is noted there. (TODO: try to edit the content in there!)

  • ordIsUnique([<cOrder> | <nPosition>], [<cIndexFile>]) ➜ lUnique
    The function returns the status of the indicated order's unique flag as a logical value.
    <cOrder> | <nPosition> is either the name of the order or its position in the order list. If omitted or NIL, the controlling order is assumed. Specifying an invalid order will raise a runtime error. <cIndexFile> is the name of an index file, including an optional drive and directory (no extension should be specified). If <cIndexFile> is not open by the current process, a runtime error is raised. Use this argument with <cOrder> to remove ambiguity when there are two or more orders with the same name in different index files.

  • ordKey( <cOrderName>|<nOrder> [, <cOrderBagName>] ) ➜ cIndexKey
    returns the key expression of an order.
    <cOrderName> is the name of the order or alternatively <nOrder> is the position in the order list.
    <cOrderBagName> is the name of index file in the disk that contains one or more orders. Is required only when multiple index files are opened and contain indexes with the same <cOrderName>.

  • ordKeyAdd([<cOrder>|<nPosition>],[<cIndexFile>],[<expKeyValue>]) ➜ lOk
    adds keys to a custom built order which is an order that is not automatically maintained by the DBFCDX driver. You can determine if an order is custom built using DBORDERINFO(DBOI_CUSTOM, ...). When you create such an order, it is initially empty. You must then manually add and delete keys using ORDKEYADD() and ORDKEYDEL().

  • ordKeyCount([cOrderName] [, cOrderBagName]) ➜ TotalKeys
    returns total number of order keys.

  • ordKeyDel([<cOrder>|<nPosition>],[<cIndexFile>],[<expKeyValue>]) ➜ lOk
    deletes a key from a custom built order which is an order that is not automatically maintained by the DBFCDX driver.

  • ordKeyGoto(<nOrderKeyPos>) ➜ lOk
    moves order key-pointer to a new order position.

  • ordKeyNo([cOrderName] [, cOrderBagName]) ➜ nOrderKeyPos
    returns the current key number (positional).

  • ordKeyRelPos( [nNewPos] ) ➜ nOldPos
    returns relative position in index file (in the range from > 0.0 to < 1.0). Returned value is same as the result of division ordKeyNo() / ordKeyCount() but much faster.

  • ordKeyVal() ➜ uKeyValue|NIL
    returns the current record's key value.
    The data type of the value is the same as that of the key expression used to create the order. However, the function returns NIL when:

    • There is no controlling order
    • The record pointer is at the end of file (in which case, the Eof() function returns true .T.)
    • There is no key defined for this record (for example, the record pointer has been moved to a record that does not meet the order's 'for' condition or that lies outside of its specified scope)

    The value returned by ordKeyVal() is retrieved from the controlling order, action which is faster than accessing the actual record into database file.
    NOTE: This function is a new Harbour function (does not exist in the original CA-Cl*pper).

  • ordListAdd(<cOrderBagName>,[<cOrderName>]) ➜ NIL
    opens an index file in a used work area and adds all contained indexes to the list of open indexes. Does not affect the controlling index, unless it is the first opening index file in the work area.

  • ordListClear() ➜ NIL
    closes all indexes opened in a work area.

  • ordListRebuild() ➜ NIL
    This function rebuilds (recreates) all the orders (indexes) in the current or aliased order list. It is equivalent to REINDEX command. To rebuild a single order, ordCreate() should be used.

  • ordName( [<nOrder>] [,<cIndexFile>] ) ➜ cIndexName
    returns the name of the specified order in the current order list or the specified order bag if opened in the current order list.

  • ordNumber( [<cOrderName>] [, <cOrderBagName>] ) ➜ nOrder
    returns an integer that represents the position of the specified order in the order list.

  • ordSetFocus([<cOrderName>|<nOrder>] [,<cOrderBagName>])➜ cPrevOrderNameInFocus
    selects an index opened in a work area as the controlling index.

  • ordSetRelation(<nArea>|<cAlias>, <bKey>, [<cKey>]) ➜ NIL
    creates a relation between the current work area (parent) and a secondary work area (Child) specified with <nArea> or <cAlias>.

  • ordSkipRaw([<nRecords>]) ➜ NIL
    Move the record pointer, ignoring currently active filter, if any. See also dbSkip() function.

  • ordSkipUnique([<nDirection>|<nRecords>]) ➜ lSuccess**
    Move the record pointer to the next or previous unique key in the controlling order.
    <nDirection> specifies whether the function will skip to the next or previous key. If omitted or specified as 1 causes the record pointer to skip forward to the next unique key. A negative value forces a backward move towards previous unique key.
    Returns .T. (true) on success or .F. (false) otherwise.
    This function allows to make a non-unique order look like a unique order. Each time it's used, record pointer is moving to the next (or previous) unique key exactly as if was skipping through a unique order. This function eliminates the problems associated with maintaining a unique order, while provides fast access to unique keys.
    NOTE: If no index is active (natural order) then passed parameter is number of records to skip just like in dbSkip().

  • ordWildSeek( <cWildCardString>, [<lCurrentRec>], [<lBackwards>] ) ➜ lFound
    Searches the controlling index for a given string pattern and returns .T. if a record matching the <cWildCardString> was found or .F. if nothing found.
    As implied by its name, the searched <cWildCardString> can contain wildcard characters (such as the question mark ?, that matches exactly one character in the position it is placed and the asterisk character *, that matches zero or more characters from the position it is put and forward). Worth to noted that in case of no matching key found, the record pointer is always moved to the ghost record (i.e., beyond end of file) ignoring the SOFTSEEK setting. We'd say that ordWildSeek() performs a "HARDSEEK", unlike the regular dbSeek() function which honors the global SOFTSEEK setting and also offers a separate parameter to suitably adapt the pointer positioning.
    Optional parameter <lCurrentRec> specifies whether the search shall start from the current record (when .T.) or from the first (or last, see below <lBackwards>) record. Default is .F., i.e. start from top (or bottom).
    <lBackwards> flag determines the direction the lookup is performed. If it's .F. (which is the default value) the search goes forwards up to the end of file, if it's .T., the search is backward, i.e., towards the beginning of file.
    NOTE: This function is a Harbour extension (does not exist in the original CA-Cl*pper).  


Back to Home

⚠️ **GitHub.com Fallback** ⚠️