|
|
|
|
|
- Generic search/Exact-match search
- Search performed on a key item or on a non-key item
- Performing a search on a composite key
- Search and filter
- Search on an array item
- Looping through records that match a condition
- Exact-match search in Access
- Locks
- Optimizing iterations
HReadSeekLast (Function) In french: HLitRechercheDernier
Not available with this kind of connection
Positions on the last record of a data file whose value for a specific item is less than or equal to a sought value (exact-match search). The record is read and the corresponding HFSQL variables are updated. In most cases, HReadSeekLast sets the position in the data file to loop through the records that match a condition. HReadPrevious is used to read the previous record corresponding to the condition. Several cases may occur after the call to HReadSeekLast: - a record corresponding to the condition has been found, blocked (if necessary) and loaded into memory: function HFound returns True.
The management of locks is not available.
JDBC access: lock management is not supported for databases that are accessed through JDBC.
- the data file is empty or there is no record corresponding to the condition: no read is performed and function HOut returns True.
- the function attempts to block a record already blocked in playback: no playback is performed, function HErrorLock returns True and function HOut returns True.
The management of locks is not available.
JDBC access: lock management is not supported for databases that are accessed through JDBC.
This function can be used with the data files, HFSQL views or queries. Note: the search can be cancelled by pressing HCancelSeek.
HReadSeekLast(Customer, Name, "MOORE")
HReadSeekLast(Customer, Turnover, X)
WHILE NOT HOut(Customer)
AddCustomerList()
HReadPrevious(Customer, Turnover)
END
Syntax
<Result> = HReadSeekLast(<Data file> , <Item> , <Search value> [, <Options>])
<Result>: Boolean - True if the record was found (corresponds to the value of HFound).
- False if a problem occurs. This problem can be caused by:
- or a positioning problem (empty data file, etc.): function HFound returns Faux and function HError returns 0.
- an error: HError returns an integer other than 0. HErrorInfo returns more details.
<Data file>: Character string Name of data file, HFSQL view or query used. <Item>: Character string Name of item on which the search will be performed. This item can be a search key or not.
<Search value>: Type corresponding to the value Value of the sought item. <Options>: Optional constant (or combination of constants) Used to configure:- the lock mode applied to the sought record.
- the type of search performed.
| | hForwardOnly | | hGeneric | Generic search (see the Notes) An exact-match search is performed by default (constant not specified). | hKeepFilter | The filter set by HFilter will be taken into account, even if the search key is not optimized for the filter. Reminder: HFilter returns the optimized search key for the filter. Caution: in this case, on large data files, performance problems may occur.. By default, the iteration performed after HReadSeekLast ignores the filter. | hLimitParsing | The iteration will stop when the last searched value is found. The current record will correspond to this last record found. HFound will return False and HOut will return True. This constant is used to optimize the search speed in Client/Server mode. | hLockNo | No blocking: the recording can be played back or modified by another application during playback..
| hLockReadWrite | Read/write lock: the record being read cannot be read or modified by another application. The lock mode is ignored if a query is used.
| hLockWrite | Write lock: the record currently read can be read by another application but it cannot be modified by another application. The lock mode is ignored if a query is used.
| hNoRefresh | |
Remarks Generic search/Exact-match search - Generic search (mainly for string fields): Finds all records beginning with the specified value.
For example: When performing a generic search for the string "Martin" in the NAME field, all records whose Name field begins with "Martin" will match the search. Therefore, the record that contains "Smither" will match the search (HFound returns True). Note For compatibility with version 5.5, the generic search for an empty string ("") is equivalent to using the HReadLast function. - Exact-match search: Finds all records exactly matching the specified value.
For example: When performing an exact-match search on the string "Martin" for the field NAME, function HFound returns True only for records where the field is exactly "Martin". - Examples of searches on the CUSTOMER data file sorted by name:
 | | | | | | Search value | Options | HReadSeekLast positions on the record. | HFound returns | HOut returns | Explanations | Davon | | 6 | True | False | Davon exists. The beginning of data file was not reached yet. | Davo | | 5 | False | False | Davo does not exist. Positioning on the first lower value (Moore). The beginning of data file was not reached yet. | Moor | hGeneric | 5 | True | False | Moor does not exist but the search is generic, and Moore is found (among others). The beginning of data file was not reached yet. | Moor | | The record was not found (no move). | False | False | Moor does not exist. The beginning of data file was not reached yet. | Bernard | | The record was not found (no move). | False | True | Bernard does not exist. Set to the first lower value (this value does not exist): the start of the data file is reached. |
Search performed on a key item or on a non-key item The search can be performed on a key item or a non-key item. If the search is performed on a key item: - the search is fast and the result is sorted.
- if the iteration is continued by HReadPrevious, the next records will correspond to the values less than or equal to the search value. In this case, HOut must be checked after each read operation to find out whether the beginning of the file has been reached.
If the search is performed on a non-key item: - the selected item will appear in red in the code editor and a warning will appear in the "Compilation error" pane.
Note: The automatic completion only offers the key items. - if the iteration is continued by HReadPrevious, the next records will correspond to the values equal to the search value.
Performing a search on a composite key Several methods can be used to perform a search on a composite key: 1. Using a list of values The following syntax is used to perform a search on a composite key: HReadSeekLast(<File name>, <Name of composite key>, [<Search value of first element of composite key>, <Search value of first element of composite key>, ...]) Example:
HReadSeekLast(CUSTOMER, LASTNAME_FIRSTNAME, ["MOORE","Vince"])
2. Using HBuildKeyValueExample:
bufValRech is TO Buffer = HBuildKeyValCue(CUSTOMER, LAST_NAME, sLastname, sFirstname)
HReadSeekLast(CUSTOMER, LASTNAME_FIRSTNAME, bufSoughtVal)
WHILE HFound(CUSTOMER)
HDelete(CUSTOMER)
HPrevious(CUSTOMER, LASTNAME_FIRSTNAME)
END
Search and filter If a filter is enabled ( HFilter), the filter is taken into account by the search only if the key used is identical. To apply this filter in the rest of the iteration (even if the search key is not optimized for the filter), use the hKeepFilter constant.
Search on an array item The search is performed on the first array element (element with index 1). To perform a search on the other array elements, use the filters or queries. Looping through records that match a condition In most cases, HReadSeekLast sets the position in the data file to loop through the records that match a condition. HReadNext and HReadPrevious are used to read the next and previous matching records. To ignore the search while going to the next or previous record, use one of the following functions:
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|