ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / Managing databases / HFSQL / HFSQL functions
  • Generic search/Exact-match search
  • Exact-match search in Access
  • Performing a search on a composite key
  • Search on an array item
  • Search and filter
  • Looping through records that match a condition
  • Optimizing iterations
  • Previous versions
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Positions on the first file record whose value for a specific item is greater than or equal to a sought value (generic search). The record is read and the corresponding HFSQL variables are updated.
In most cases, HReadSeek sets the position in the data file to loop through the records that match a condition. HReadNext is used to read the next record corresponding to the condition.Several cases may occur after the call to HReadSeek:
  • a record corresponding to the condition was found, locked (if necessary) and loaded in memory: HFound returns True.
    Java Access by JDBC: The management of locks is not available for databases accessed by JDBC.
  • the data file is empty or there is no record corresponding to the condition: no reading is performed and HOut returns True.
This function can be used with the data files, HFSQL views or queries.
Remarks:
  • By default, HReadSeekFirst and HReadSeekLast are used to perform exact-match searches.
  • By default, HReadSeek is used to perform a generic search on strings. This search is not generic on integers, reals, dates, currencies, etc.
// Find the first record
// for which the CUSTOMER name is MOORE
HReadSeek(CUSTOMER, NAME, "MOORE")
IF HFound() THEN
Trace("Customer MOORE found")
ELSE
Trace("Customer MOORE not found")
END
Syntax
<Result> = HReadSeek(<Data file> , <Item> , <Sought value> [, <Options>])
<Result>: Boolean (optional)
Corresponds to:
  • True if the sought record was found and read. The file buffer is loaded with the data of the record found. In this case, HError is set to 0 and HFound is set to True.
  • False in the following cases:
    • error while accessing the file (unable to read for example). HError returns an error code. HErrorInfo returns more details about the error. In this case, HFound cannot be used.
    • the access to the file was performed but no record was found. In this case, HError is set to 0 and HFound is set to False.
    Caution: In this case, the file buffer cannot be used.
<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.
For an exact-match search, this parameter can correspond to a non-key item.
Hyper File 5.5 To perform generic searches on a composite key, all the components of the composite key must be text components. Otherwise, an exact-match search is performed.
<Sought 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.
hIdenticalExact-match search (see the Notes)
A generic search is performed by default (constant not specified).
Java Access by JDBC: This constant is not available.
hKeepFilterThe filter set 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, performance issues may arise for large files.
Hyper File 5.5 This variable cannot be used.
hLimitParsing
ODBCNative Connectors (Native Accesses) The iteration will stop when the last searched 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.
This constant is recommended when performing a simple search (without looping through the found elements).
HFSQL Client/Server This constant is not available.
hLockNoNo lock: the record can be read or modified by another application during the reading.
PHP The management of locks is not available.
Java Access by JDBC: This constant is not available.
hLockReadWriteLock 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.
ODBC Lock in write-only. Operating mode equivalent to the hLockWrite constant.
PHP The management of locks is not available.
Java Access by JDBC: This constant is not available.
hLockWriteLock in write mode: the record currently read can be read by another application but it cannot be modified.
The lock mode is ignored if a query is used.
PHP The management of locks is not available.
Java Access by JDBC: This constant is not available.
hNoRefresh
PHPODBCNative Connectors (Native Accesses) HReadSeek does not refresh the content of the table or query. If possible, the query is not re-run. All the saved positions are stored.
ODBCNative Connectors (Native Accesses) The lock options will have no effect if the locks are not supported by the OLE DB provider or by the Native Connector.
Java Access by JDBC: Locks cannot be managed in databases accessed by JDBC.
Remarks
WINDEVWEBDEV - Server codeReports and QueriesUniversal Windows 10 AppiPhone/iPadUser code (UMC)PHPAjaxHFSQL ClassicHFSQL Client/ServerHyper File 5.5OLE DBNative Connectors (Native Accesses)

Generic search/Exact-match search

A generic search or an exact-match search will be performed according to <Sought value>.
  • Generic search: search for all the records that start with the specified value
    To perform a generic search, the desired value must be specified in <Sought value>.
    Remark: For backward compatibility with WINDEV 5.5, the generic search of an empty string ("") is equivalent to the use of HReadFirst.
  • Exact-match search: search for all the records that exactly correspond to the specified value.
    To perform an exact-match search, the size of the search argument must be exactly the same as the size of the key. To perform an exact-match search, you also have the ability to use the hIdentical constant.
    To perform an exact-match search, you also have the ability to use HReadSeekFirst.
Caution: If you are using Hyper File 5.5 files or files in Hyper File 5.5 format migrated to HFSQL Classic, the implementation of generic searches and exact-match searches may change. For more details, see the Hyper File 5.5 and HFSQL Classic: How to manage the space characters in the searches? table
WINDEVWEBDEV - Server codeReports and QueriesUser code (UMC)PHPAjaxNative Connectors (Native Accesses)

Exact-match search in Access

To perform an exact-match search on an ACCESS database, it is recommended to use NoSpace if there are space characters at the end of the sought value.
WINDEVWEBDEV - Server codeReports and QueriesUniversal Windows 10 AppiPhone/iPadJavaUser code (UMC)PHPAjaxHFSQL ClassicHFSQL Client/ServerHyper File 5.5OLE DBNative Connectors (Native Accesses)

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:
HReadSeek(<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
HReadSeek(CUSTOMER, LASTNAME_FIRSTNAME, ["MOORE","Vince"])
 
WHILE HFound(CUSTOMER)
// Process
HReadNext(CUSTOMER, LASTNAME_FIRSTNAME)
END

2. Using HBuildKeyValue
If the sought item is a composite key, the value to find can be built by HBuildKeyValue.
Hyper File 5.5 To perform generic searches on a composite key, all the components of the composite key must be text components. Otherwise, an exact-match search is performed.
WINDEVWEBDEV - Server codeReports and QueriesUniversal Windows 10 AppiPhone/iPadJavaUser code (UMC)PHPAjaxHFSQL ClassicHFSQL Client/ServerHyper File 5.5OLE DBNative Connectors (Native Accesses)

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.
WINDEVWEBDEV - Server codeReports and QueriesUniversal Windows 10 AppiPhone/iPadJavaUser code (UMC)PHPAjaxHFSQL ClassicHFSQL Client/ServerHyper File 5.5OLE DBNative Connectors (Native Accesses)

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.
WINDEVWEBDEV - Server codeReports and QueriesUniversal Windows 10 AppiPhone/iPadJavaUser code (UMC)PHPAjaxHFSQL ClassicHFSQL Client/ServerHyper File 5.5OLE DBNative Connectors (Native Accesses)

Looping through records that match a condition

In most cases, HReadSeek 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:
WINDEVWEBDEV - Server codeReports and QueriesUniversal Windows 10 AppiPhone/iPadUser code (UMC)PHPAjaxHFSQL ClassicHFSQL Client/ServerHyper File 5.5OLE DBNative Connectors (Native Accesses)

Optimizing iterations

To optimize the first iterations on a data file, use HOptimize on this data file.
WINDEV

Previous versions

This function replaces HReadSeekLock and HReadSeekNoLock, which were kept for compatibility with WINDEV 5.5.
Component: wd290hf.dll
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 10/26/2022

Send a report | Local help