PC SOFT

WINDEVWEBDEV AND WINDEV MOBILE
ONLINE HELP

Home | Sign in | English UK

  • 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
  • Browsing the records corresponding to a condition
  • The views and RPC on HFSQL
  • Optimizing the browse operations
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
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 is used to position in the data file in order to perform a browse loop among the records corresponding to 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.

  • 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.
Notes:
  • By default, HReadSeekFirst and HReadSeekLast are used to perform exact-match searches.
  • By default, HReadSeek is used to perform a generic search on the character strings. This search is not a generic search on the integers, the reals, the dates, the currencies, ...
Note: From version 19, HFSQL is the new name of HyperFileSQL.
// 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(<File name> , <Item name> , <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.
<File name>: Character string (with or without quotes)
Name of data file, HFSQL view or query used.
<Item name>: Character string (with or without quotes)
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 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.
hLockWriteLock 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.
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.
hLockNoNo lock (even if HStartLock was called): the record can be read or modified by another application during the reading.
hIdenticalExact-match search (see the Notes)
A generic search is performed by default (constant not specified).
hLimitParsing
ODBCNative Connectors (Native Accesses) 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.
This constant is recommended when performing a simple search (without browsing the elements found).
HFSQL Client/Server This constant is not available.
hKeepFilterThe 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.
Hyper File 5.5 This variable cannot be used.
hNoRefresh
ODBCNative Connectors (Native Accesses) HReadSeek does not refresh the content of the table or query. The query is not re-run if possible. 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 Access.
Remarks
Reports and QueriesHFSQLHFSQL 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 requested value must be specified in <Sought value>.
    Note: 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. See the Hyper File 5.5 and HFSQL Classic: How to manage the space characters in the searches? table for more details
Reports and QueriesNative Connectors (Native Accesses)

Exact-match search in Access

To perform an exact-match search on an ACCESS database, we recommend that you use NoSpace if space characters are found at the end of the sought value.
Reports and QueriesHFSQLHFSQL 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.
3. Using HConvert (backward compatibility with WINDEV 5.5)
To build the value of a composite key without using HBuildKeyValue, you must:
  • fill the text components on their entire size with Charact(0).
  • convert the numeric components with HConvert.
Example:
MyCompositeKey = Complète(Customer.CustomerLastName, Dimension(Customer.LastName), Charact(0)) + ...
        Complète(Customer.FirstName, Dimension(Customer.FirstName), Charact(0))
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.
Reports and QueriesHFSQLHFSQL Client/ServerHyper File 5.5OLE DBNative Connectors (Native Accesses)

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.
Reports and QueriesHFSQLHFSQL 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.
Reports and QueriesHFSQLHFSQL Client/ServerHyper File 5.5OLE DBNative Connectors (Native Accesses)

Browsing the records corresponding to a condition

In most cases, HReadSeek is used to position in the data file in order to perform a browse loop among the records corresponding to a condition. HReadNext and HReadPrevious 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:
Reports and QueriesHFSQLHFSQL Client/ServerHyper File 5.5

The views and RPC on HFSQL

The search on a HFSQL view via a remote access (RPC on HFSQL) operates according to two different methods:
  • if the group of records selected by the view has not been previously brought back to the local computer, a call to the server is performed in order to search for the specified value.
    This solution is recommended if the size of the view is important and/or if a small number of searches must be performed.
  • if the group of records selected by the view has been previously brought back to the local computer, the search is performed on the local computer directly (no need to call the server).
    This solution is recommended if the size of the view is not very important and/or if a large number of searches must be performed.
    To bring back all the records selected by the view to the local computer, you can:
    • call HCreateView and specify a significant number of records per page (<Page size> parameter) then start the search with HReadFirst (recommended method).
    • create a loop used to browse all the records selected by the view (HReadFirst and HReadNext).
      Note: This solution triggers an important exchange of data during the first access to the view.
Reports and QueriesHFSQLHFSQL Client/ServerHyper File 5.5OLE DBNative Connectors (Native Accesses)

Optimizing the browse operations

To optimize the time of the first browses performed on a data file, use HOptimize on this data file.
Component : wd240hf.dll
Minimum version required
  • Version 9
This page is also available for…
Comments
Consulta usando chave primária ou estrangeira
HReset(t002_repostas)
IF HReadSeek(t002_repostas, T002_Questionario_ID, Questionario_ID, hIdentical) = True THEN
achou = True
ELSE
achou = False
END
BOLLER
05 Sep. 2019
Outros exemplos de usar o Hreadseek com chave composta
HReset(t002_repostas)
BufChaveComposta is Buffer = HBuildKeyValue(t002_repostas,T002_ChaveComposta, Questionario_ID, Pergunta_ID,Cliente_ID,Profissionais_ID)
IF HReadSeek(t002_repostas,T002_ChaveComposta,BufChaveComposta,hIdentical) = True THEN
achou = True
ELSE
achou = False
END

Ou a mesma consulta pode ser feita assim:

HReset(t002_repostas)
IF HReadSeek(t002_repostas,T002_ChaveComposta, [Questionario_ID, Pergunta_ID,Cliente_ID,Profissionais_ID]
,hIdentical) = True THEN
achou = True
ELSE
achou = False
END
BOLLER
05 Sep. 2019
BUSCA EM CHAVE COMPOSTA MISTA COM TEXTO E NUMERO
//BUSCA EM CHAVE COMPOSTA MISTA COM TEXTO E NUMERO
ok is boolean

valorNovo = gnOrdem + 1

gsFruta = """"+gsFruta+""""

bufSearch is Buffer = HBuildKeyValue(t000_frutas,t000_kunica, gsFruta, gnOrdem)

IF HReadSeekFirst(t000_frutas,t000_kunica,bufSearch) = True
IF HFound(t000_frutas) = True
t000_frutas.t000_ordem = valorNovo
ok = HModify(t000_frutas)
END
END
BOLLER
01 Aug. 2019
Example
//Busca com Hreadseek ja posiciona o ponteiro no primeiro registro
//Se fizer com Hexecutequery ou HexecuteSqlQuery é necessário dar um
//for para movimentar o ponteiro para o primeiro e próximos registros

// search for the login in the file
HReadSeek(GPU_08_Users,Login,Lower(EDT_Login))

// if the user exists
IF HFound(GPU_08_Users) THEN

// initialize the controls
EDT_FormerPassword=GPU_08_Users.Password

// changes the plane
MyWindow..Plane=3

END
BOLLER
17 Apr. 2019