- Generic search/Exact-match search
- Performing a search on a composite key
- Search on an array item
- Search and filter
- Locks
HSeekLast (Function) In french: HRechercheDernier
Not available with this kind of connection
Positions on the last file record whose value for a specific item is less than or equal to a sought value. The record is not read. The number of the current record is only changed when it is returned by the HRecNum function. For functions that manipulate by default the number of the current record (functions HDelete, HRead, HModify,...), the value of this number is not updated: you must use HRecNum(). For example: not to do:
HDelete(Customer, HRecNum())
The reading is performed from the lowest value to the greatest value of search item (see the notes for more details). Caution: The record loaded in memory is not modified. The HFSQL variables (Customer.Name for example, which means the Name item of Customer file) are not updated. In most cases, HSeekLast is used to position in the data file in order to perform a browse loop among the records corresponding to a condition. Several cases may occur after the call to HSeekLast: - a record corresponding to the condition was found, locked (if necessary) and loaded in memory: HFound returns True.
- the data file is empty or there is no record corresponding to the condition: HOut returns True.
- the function tries to lock a record that is already locked in read-only: HErrorLock returns True and HOut returns True.
Remark: From version 19, HFSQL is the new name of HyperFileSQL.
// Find the last record for which the CUSTOMER name is MOORE HSeekLast(CUSTOMER, NAME, "MOORE")
// This example is used to find all the customers // whose turnover is less than a specific value. HSeekLast(CUSTOMER, Turnover, X) WHILE NOT HOut(CUSTOMER) AddCustomerList() HPrevious(CUSTOMER, Turnover) END
Syntax
<Result> = HSeekLast(<File name> , <Name of key item> , <Sought value> [, <Options>])
<Result>: Boolean - True if the positioning was performed (corresponds to the value of HFound).
- False if a problem occurred. This problem can be caused by:
- a positioning problem (empty data file, ...): HFound returns False and HError returns 0.
- an error: HError returns an integer other than 0. HErrorInfo returns more details.
<File name>: Character string (with or without quotes) Name of HFSQL data file used. <Name of key item>: Character string (with or without quotes) Name of key item on which the search will be performed. <Sought value>: Type corresponding to the value Value of sought item. <Options>: Optional constant (or combination of constants) Configures:- the lock mode applied to the sought record
- the type of search performed.
| | hLockReadWrite | Lock in read/write: the record cannot be read or modified by another application.
| hLockWrite | Lock in write mode: the record can be read by another application but it cannot be modified by another application. | hLockNo | No lock (even if HStartLock was called): the record can be read or modified by another application during the reading. | hGeneric | Generic search (see the Notes) An exact-match search is performed by default (constant not specified). | hLimitParsing | The browse will stop as soon as the last sought value is found. The current record will correspond to this last record found. HFound will be set to False and HOut will be set to True. This constant is used to optimize the search speed in Client/Server mode. | hKeepFilter | The filter implemented by HFilter will be taken into account, even if the search key is not optimized for the filter. Reminder: HFilter returns the search key optimized for the filter. Caution: In this case, lack of performances may occur on huge data files. By default, the browse performed after HSeekLast ignores the filter. |
Remarks Generic search/Exact-match search - Generic search (mainly on the Character String items): Finds all the records starting with the specified value.
For example: When a generic search is performed on "Martin" (for the NAME item), all records whose Name item starts with "Martin" will correspond to the search. Therefore, the record containing "Smither" will correspond to the search (HFound returns True). - Exact-match search: Finds all the records that exactly correspond to the specified value.
For example: When an exact-match search is performed on "Smith" (for the NAME item), HFound returns True for the records whose item exactly matches "Smith". - Examples or searches performed on CUSTOMER file sorted by name:
| | | | | | Sought value | Options | HSeekLast positions on the record | HFound returns | HOut returns | Explanations | Durand | | 6 | True | False | Durand exists. The beginning of data file was not reached yet. | Dupuis | | 5 | False | False | Dupuis does not exist. Positioning on the first lower value (Davis). The beginning of data file was not reached yet. | Dupon | hGeneric | 5 | True | False | Davi does not exist but the search is a generic search and Davis is found (among other ones). The beginning of data file was not reached yet. | Dupon | | The record was not found (no move) | False | False | Dupon 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. Positioning on the first lower value (this value does not exist): The beginning of data file was reached. |
Performing a search on a composite key Several methods can be used to perform a search on a composite key: Using a list of values The following syntax is used to perform a search on a composite key:
HSeekLast(<File name>, <Name of composite key>, ... [<Search value of first element of composite key>, <Search value of first element of composite key>, ...])
Example:
// Find the record HSeekLast(CUSTOMER, NAME_FIRSTNAME, ["MOORE", "Vince"])
The search is performed on the first array element (element whose subscript is 1). To perform a search on the other array elements, use the filters or queries. If a filter is enabled ( HFilter), this filter is taken into account during the search.
This page is also available for…
|
|
|