- 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 on an array item
- Search and filter
- Browsing the records corresponding to a condition
- Exact-match search in Access
- Locks
- Optimizing the browse operations
- Native XML Connector
<Source>.ReadSeekFirst (Function) In french: <Source>.LitRecherchePremier
Not available with this kind of connection
Positions on the first record of a data file whose value for a specific item is strictly equal to a sought value (exact-match search). The record is read and the corresponding HFSQL variables are updated. In most cases, <Source>.ReadSeekFirst is used to set the position in the data file to perform a browse loop among the records that correspond to a condition. <Source>.ReadNext is used to read the next record corresponding to the condition. Several cases may occur after the call to <Source>.ReadSeekFirst: <Source>.ReadSeekFirst can be used with the data files, HFSQL views or queries. Versions 15 and later New in version 15 Versions 17 and later New in version 17 Versions 18 and later New in version 18 Remark: From version 19, HFSQL is the new name of HyperFileSQL. Versions 21 and later New in version 21
// Find the first record for which // the Customer name is MOORE Customer.ReadSeekFirst(Name, "MOORE") IF Customer.Found() = False THEN Error("Customer not found") RETURN ELSE // Continue the process on the customer named MOORE END
Syntax
<Result> = <Source>.ReadSeekFirst(<Item> , <Sought value> [, <Options>])
<Result>: Boolean - True if the record was found (corresponds to the value returned by <Source>.Found).
- False if a problem occurred. This problem can be caused by:
<Source>: Type corresponding to the specified source Name of HFSQL data file, view or query used. <Item>: Character string (with or without quotes) Name of item on which the search will be performed. This item can be a search key or not.
<Sought value>: Type corresponding to the value Value of 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.
| | hLockReadWrite | Lock in read/write: the record currently read cannot be read or modified by another application. The lock mode is ignored if a query is used.
| hLockWrite | Lock in write mode: 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.
| hLockNo | No lock (even if HStartLock was called): the record can be read or modified by another application during the reading.
| Versions 17 and laterhForwardOnly New in version 17hForwardOnly hForwardOnly | | 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 or if no value corresponds to the search. The current record will correspond to this last record found. <Source>.Found will return False and <Source>.Out will return True. This constant is used to optimize search speed in Client/Server mode and on external databases (accessed via OLE DB or via Native Connectors). | hKeepFilter | The filter set by <Source>.Filter will be taken into account, even if the search key is not optimized for the filter. Reminder: <Source>.Filter returns the search key optimized for the filter. Caution: in this case, performance issues may arise for large files. By default, the browse performed after <Source>.ReadSeekFirst ignores the filter. | hNoRefresh | |
Remarks Generic search/Exact-match search - Generic search (mainly on the Character String items): Finds all records starting with the specified value.
For example: When a generic search is performed on "Smith" (for the NAME item), all records whose Name item starts with "Smith" will match the search. Therefore, the record that contains "Smither" will match the search (<Source>.Found returns True). Remark: For backward compatibility with WINDEV 5.5, the generic search of an empty string ("") is equivalent to the use of <Source>.ReadFirst. - Exact-match search: Finds all records that exactly correspond to the specified value.
For example: When an exact-match search is performed on "Smith" (for the NAME item), <Source>.Found returns True for the records whose item exactly matches "Smith". - Examples of searches performed on CUSTOMER file sorted by name:
 | | | | | | Sought value | Options | <Source>.ReadSeekFirst sets the position on the record. | <Source>.Found returns | <Source>.Out returns | Explanations | Davon | | 1 | True | False | Davon exists. The end of data file was not reached yet. | Davo | | 1 | False | False | Davo does not exist. Position on the first greater value (Davon). The end of data file was not reached yet. | Moor | hGeneric | 8 | True | False | Moor does not exist but the search is a generic search and Moore is found (among others). The end of data file was not reached yet. | Moor | | The record was not found (no move, the current record does not change). | False | False | Moor does not exist. The end of data file was not reached yet. | Norbert | | The record was not found (no move, the current record does not change). | False | True | Norbert does not exist. Position on the first greater value (this value does not exist): the end of data file has been reached. |
See the Hyper File 5.5 and 7: How to manage the space characters in the searches? table for more details 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 browse is continued by <Source>.ReadNext, the next records will correspond to the values greater than or equal to the sought value. In this case, <Source>.Out must be checked after each read operation to find out whether the end of data file has been reached.
If the search is performed on a non-key item: 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:
HReadSeekFirst(<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 Customer.ReadSeekFirst(LastName_FirstName, ["MOORE", "Vince"])
2. Using <Source>.BuildKeyValueExample:
bufSoughtVal is Buffer = Customer.BuildKeyValue(LastName_FirstName, sLastName, sFirstName) Customer.SeekFirst(LastName_FirstName, bufSoughtVal) WHILE Customer.Found() Customer.Delete() Customer.Next(LastName_FirstName) END
3. Using HConvert- fill the text components on their entire size with Charact(0).
- convert the numeric components with HConvert.
Example:
MyCompositeKey = Complete(Customer.CustomerLastName, Dimension(Customer.LastName), Charact(0)) + ... Complete(Customer.FirstName, Dimension(Customer.FirstName), Charact(0))
Search on an array item 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. Search and filter If a filter is enabled ( <Source>.Filter), the filter is taken into account by the search only if the key used is identical. To take this filter into account in the rest of browse (even if the search key is not optimized for the filter), use the hKeepFilter constant.
Browsing the records corresponding to a condition In most cases, <Source>.ReadSeekFirst is used to set the position in the data file to perform a browse loop among the records that correspond to a condition. <Source>.ReadNext and <Source>.ReadPrevious are used to read the next and previous records corresponding to the condition. To ignore the search while going to the next or previous record, use one of the following functions:
This page is also available for…
|
|
|