Function DbEval() Foundation
Evaluates a code block for each record in a work area.
DbEval( <bBlock>, ;
[<bForCondition>], ;
[<bWhileCondition>], ;
[<nCount>], ;
[<xRecordID>], ;
[<lRest>] ) --> NIL
The return value of DbEval() is always NIL.
The database function DbEval() evaluates a code block and increments the record pointer of a work area after each execution of the code block. When the function is used without the alias operator, it moves the record pointer in the current work area. By default, DbEval() begins with the first logical record and evaluates the code block <bBlock> for each record until the last logical record is reached. The number of records for which the code block is evaluated can be influenced by the optional arguments.
By specifying code blocks for <bForCondition> or <bWhileCondition>, a logical condition can be defined which must return the value .T. (true) for the code block <bBlock> to be evaluated. The <bForCondition> code block is evaluated for all data records. When it returns .T. (true), <bBlock> is executed. When <bWhileCondition> is specified, <bBlock> is only executed until <bWhileCondition> returns .F. (false), causing DbEval() to terminate.
Alternatively the number of records can be explicitly determined with <nCount> or <lRest>. Specifying <xRecordID> positions the record pointer on this record and the code block <bBlock> is evaluated for this and following records.
DbEval() passes no arguments to the code blocks.
// The example shows DbEval() with a FOR condition. All customers
// in a customer file having the name "Smith" are listed.
PROCEDURE Main
USE Customer NEW
DbEval( {|| QOut(LastName,FirstName) } , ; // <bBlock>,
{|| "SMITH" $ Upper(LastName) } ) // <bForCondition>
USE
RETURN
// The example shows a command based on DbEval() which calls
// DbDelete() from a code block. Many other commands using
// DbEval() can be found in STD.CH.
#command DELETE ;
[ FOR <for>] ;
[ WHILE <whl>] ;
[ NEXT <nxt>] ;
[RECORD <rcd>] ;
[ <rst: REST>] ;
[ ALL ] ;
=> dbEval( {|| dbDelete()}, ;
<{for}>, <{whl}>, <nxt>, <rcd>, <.rst.>)
// In the example, a UDF is illustrated in which the RecNo()
// of all records fulfilling a condition are written
// into an array with DbEval(). The example lists all customers
// from a customer file which have not yet paid an invoice.
PROCEDURE Main
LOCAL aRecno
USE Customer ALIAS Cust NEW EXCLUSIVE
INDEX ON CustNo TO CustNo
SET INDEX TO CustNo
USE Invoice ALIAS Inv NEW
// get RecNo(), for PAYMENT=0
aRecno := Inv->( CollectRecID( {|| Payment == 0} ) )
// output customer name
AEval( aRecno, {|n| Inv->( DbGoto(n) ), ;
Cust->( DbSeek(Inv->CustNo) ), ;
Cust->( QOut(LastName,FirstName) );
};
)
CLOSE Cust
CLOSE Inv
RETURN
FUNCTION CollectRecID( bFor, bWhile, nCount, lRest )
LOCAL aArray := {}
IF PCount() > 0
DbEval( {|| AAdd( aArray, RecNo() ) } , ;
bFor, bWhile, nCount, , lRest )
ENDIF
RETURN aArray
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.