Summary
In this module, you learned how to retrieve data from the database and
how to use the Get
function to retrieve a record by its primary key.
Use the functions FindFirst
and FindLast
instead of Find('-')
and Find('+')
for performance reasons. If you only want to check whether
a record exists or not, you can use the IsEmpty
function.
To retrieve a dataset, use the FindSet
function. You can use a
repeat until
statement to loop over the records. Therefore, you need
the Next
statement to complete the task.
You learned how to sort with the SetCurrentKey
function and filter
with the SetRange
and SetFilter
functions. The SetRange
function
can be used to filter with a start and an end value, while the SetFilter
can be used to search with the >
, <
, &
and |
signs.
If you don't specify a start value for the SetRange
, you remove
the filter on that field.
To manipulate data, you can use the Insert
, Modify
, ModifyAll
,
Delete
, and DeleteAll
statements. Before you insert data, you should
use the Init
function to initialize all default values. These
statements by default don't run the triggers that are defined in the
table. You need to specify the RunTrigger parameter and then set it to
true. A Modify or a Delete action happens without warning.
Additionally, you discovered important field functions. By default,
FlowFields aren't calculated in code; you need to use the
CalcFields
function on FlowFields.
The OnValidate
trigger isn't run when you assign a value to a
field, but you can use the Validate
function to run the OnValidate
trigger or use the Validate
function to assign and run in one
statement.