ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / Managing databases / HFSQL / HFSQL functions
  • 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
  • Looping through records that match a condition
  • Exact-match search in Access
  • Locks
  • Optimizing iterations
  • Native XML Connector
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 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 sets the position in the data file to loop through the records that match 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.
Remark: the search can be canceled by <Source>.CancelSeek.
PHP Special case: management of locks:
  • PHP In PHP, the management of locks is not available.
Example
// 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 occurs. This problem can be caused by:
<Source>: Type corresponding to the specified source
Name of the HFSQL data file, 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.
Hyper File 5.5 The search can only be performed on a key item.
<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.
hForwardOnly
Native Connectors (Native Accesses) This constant can only be used with Native Connectors.
Optimizes simple iterations that do not use the following features:
  • Reading the previous record.
  • Modifying a record.
  • Saving position.
If one of these features is used, the result may differ from the expected one.
For example, this constant can be used to populate a Table control programmatically.
hGenericGeneric search (see the Notes)
An exact-match search is performed by default (constant not specified).
hKeepFilterThe 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.
Hyper File 5.5 This variable cannot be used.
By default, the iteration performed after <Source>.ReadSeekFirst ignores the filter.
hLimitParsingThe iteration will stop when the last search value is found or if no value matches 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).
hLockNoNo lock: the record can be read or modified by another application during the reading.
PHP 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.
OLE DB Lock in write-only. Operating mode equivalent to the hLockWrite constant.
PHP 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 This constant is not available.
hNoRefresh
OLE DBNative Connectors (Native Accesses) <Source>.ReadSeekFirst does not refresh the content of the table or query. If possible, the query is not re-run. All the saved positions are stored.
PHP The management of locks is not available.
OLE DBNative 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.
OLE DB The lock mode specified by <Source>.ReadSeekFirst will remain effective during the calls to <Source>.ReadPrevious and <Source>.ReadNext.
To change the lock mode, use:
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 on the CUSTOMER data file sorted by name:
Sought valueOptions<Source>.ReadSeekFirst sets the position on the record.<Source>.Found returns<Source>.Out returnsExplanations
Davon1TrueFalseDavon exists.
The end of data file was not reached yet.
Davo1FalseFalseDavo does not exist. Position on the first greater value (Davon).
The end of data file was not reached yet.
MoorhGeneric8TrueFalseMoor 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.
MoorThe record was not found (no move, the current record does not change).FalseFalseMoor does not exist.
The end of data file was not reached yet.
NorbertThe record was not found (no move, the current record does not change).FalseTrueNorbert does not exist.
Position on the first greater value (this value does not exist): the end of data file has been reached.

For more details, see the Hyper File 5.5 and 7: How to manage the space characters in the searches? table

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 operation is continued by <Source>.ReadNext, the next records will correspond to the values greater than or equal to the search value. In this case, <Source>.Out must be checked after each read operation to find out whether the end of the 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>.BuildKeyValue
Example:
bufSoughtVal is Buffer = Customer.BuildKeyValue(LastName_FirstName, sLastName, sFirstName)
Customer.SeekFirst(LastName_FirstName, bufSoughtVal)
WHILE Customer.Found()
Customer.Delete()
Customer.Next(LastName_FirstName)
END
Hyper File 5.5 To perform generic searches on a composite key, all the components of composite key must be Text components. Otherwise, an exact-match search is performed.

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.

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 apply this filter in the rest of the iteration (even if the search key is not optimized for the filter), use the hKeepFilter constant.
Hyper File 5.5 If a filter is enabled, the filter is ignored by the search.

Looping through records that match a condition

In most cases, <Source>.ReadSeekFirst sets the position in the data file to loop through the records that match a condition. <Source>.ReadNext and <Source>.ReadPrevious 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:
WEBDEV - Server codeAjaxOLE DBNative 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.
WEBDEV - Server codeAjaxHFSQL ClassicHFSQL Client/ServerHyper File 5.5OLE DBNative Connectors (Native Accesses)

Locks

The locks apply only when a record was found.
By default (no lock mode specified in <Options>), the record is not locked.
If a lock is requested (hLockWrite or hLockReadWrite constant), the record will be read only if this record is not already locked.
Reminder: A locked record can be unlocked by <Source>.UnlockRecNum.
OLE DBNative Connectors (Native Accesses) Lock options will have no effect if the OLE DB provider or Native Connector (also called Native Access) does not support locks.
WEBDEV - Server codeAjaxHFSQL ClassicHFSQL Client/ServerHyper File 5.5OLE DBNative Connectors (Native Accesses)

Optimizing iterations

To optimize the first iterations on a data file, use <Source>.Optimize on this data file.
WEBDEV - Server codeNative Connectors (Native Accesses)

Native XML Connector

The behavior of <Source>.ReadSeekFirst depends on <Source>.ActivateAutoFilter and <Source>.DeactivateAutoFilter.
<Source>.ActivateAutoFilter is enabled by default.
Therefore, to read the content of XML file, read the content of main file (the parent) then read the content of linked files (the children).
By default, when reading a file, a filter is automatically applied to the linked files in order to only read the records corresponding to the main file.
For example:
The email of this person can be retrieved when looping through the Person file.
To do so, simply set the position on the "Person" file and apply <Source>.ReadSeekFirst to the "Email" file.
In this case, the record read in the "Email" file will correspond to the first email associated with the current record in the "Person" file.
If this mechanism is disabled (<Source>.DeactivateAutoFilter), the record read in the "Email" file will correspond to the first record found in the Email file (and not to the child of the record read in the "Person" file).
Component: wd290hf.dll
Minimum version required
  • Version 25
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 07/06/2023

Send a report | Local help