
Variable database query options for end users are built into many applications. Since the selection result depends on the data entered, the scope of the result and the query duration are unpredictable. Wildcard entries, for example, can be problematic here, as the selection process can take several minutes and deliver a huge amount of results that are of no use to the end user.
Since version 5.7.06, the result set (and thus also the execution time) of a selection can be limited. To do this, the maximum number of records in the result set is passed as an optional argument to the SelRun() command. If this limit is exceeded during execution, the query terminates and SelRun() returns _rLimitReached as the result.
Limited result
With a limit of 1000 records, the selection is terminated prematurely when the 1001st record is found. If exactly 1000 records are found, the result is _rOK. The result set for _rLimitReached is sorted according to the selection definition and can be used in exactly the same way as a complete result set. However, this limited set represents a random excerpt from the potential total result set. It is therefore not the “first” x records in relation to any sorting.
Preselections
The limit does not affect the execution of preselections, as the intermediate result of a preselection does not allow any conclusions to be drawn about the expected final result set. This also applies to a selection that works exclusively with preselections and whose result is unsorted. Since only key values and no data records are read in this case, the limit does not apply.
Limit = 0
The specification of 0 as the limit is permitted, in which case the selection ends with the first record found. This can be useful if the application wants to determine whether there is a matching record in a table at all. In this case, it may not be necessary to read all records in the table; the selection ends with the first match.
The limit can be used with all options except _SelUnion, _SelInter and _SelMinus, so it can also be used with server-side execution (_SelServer).