- When to use the HBuildKeyValue function?
- Generic search
- Building a composite key used in a filter with bounds
- Building a compound key without using the HBuildKeyValue function
HBuildKeyValue (Function) In french: HConstruitValClé
Not available with this kind of connection
Builds the value of a composite key to implement a filter ( HFilter) or to perform a search ( HReadSeekFirst, HReadSeekLast, etc.). This function can be replaced by an array of values, easier to use. For example:
HReadSeekFirst(FileName, LINKEDCOMPKEY, ["Last name", "First name"])
Equivalent to:
HReadSeekFirst(FileName, LINKEDCOMPKEY, ... HBuildKeyValue(FileName, LINKEDCOMPKEY, "Last name", "First name"))
Tip: To browse a data file according to a composite key, use the FOR EACH statement on composite key (syntax 5). Reminder: The composite keys are binary strings whose content cannot be displayed directly. Remark: From version 19, HFSQL is the new name of HyperFileSQL.
bufSoughtVal is Buffer
// Build the composite key bufSoughtVal = HBuildKeyValue(CUSTOMER, LASTNAME_FIRSTNAME, "MOORE", "Vince")
// Build a String/Integer composite key bufSoughtVal = HBuildKeyValue(CUSTOMER, LASTNAME_CUSTNUM, "MOORE", 12128)
// Build an Integer/Integer composite key bufSoughtVal = HBuildKeyValue(ORDER, ORDERID_ORDERID, 12119,593)
Syntax
<Result> = HBuildKeyValue(<Data file> , <Composite key> , <Value of components>)
<Result>: Buffer Value of the composite key. <Data file>: Character string (with or without quotes) Name of HFSQL data file used. <Composite key>: Character string (with or without quotes) Name of the item corresponding to the composite key <Value of components>: Character string Value that will be assigned to each component of the composite key. This parameter has the following format: <Component 1> , <Component 2>, ..., <Component N>. For example: "MOORE", "Vince". Remarks When to use the HBuildKeyValue function? HBuildKeyValue must be used to perform searches on the linked keys (binary string) to composite keys. Some examples: - FILEA file:
COMPKEY is a composite key of FILEA. Composition: FILEA.LASTNAME+FILEA.FIRSTNAME - FILEB file:
LINKEDCOMPKEY is a binary string key linked to FILEA.COMPKEY.
Performing a search on the value of the composite key:
HReadSeekFirst(FILEB, LINKEDCOMPKEY, HBuildKeyValue(FILEA, COMPKEY, ... "Last name", "First name"))
or
bufKey is Buffer bufKey = HBuildKeyValue(FILEA, COMPKEY, "Last name", "First name") HReadSeekFirst(FILEB, LINKEDCOMPKEY, bufKey)
or
HReadSeekFirst(FILEB, LINKEDCOMPKEY, FILEA.COMPKEY)
if FILEA is positioned on the record that must be found in FILEB. An array of values can be used instead of HBuildKeyValue:
HReadSeekFirst(FILEB, LINKEDCOMPKEY, ["Last name", "First name"])
Generic search When a generic search is performed, there is no need to define the values of all the components. Only the first n values are required (n being included between 1 and the number of key components, including bounds). Building a composite key used in a filter with bounds To build the value of a composite key, use HBuildKeyValue. - If the lower bound and the upper bound of the filter must be identical, the hMinVal and hMaxVal constants must be used to fill the bounds.
The following example is used to find all the records of Customer file corresponding to "Vince Moore":
HFilter(Customer, ... HBuildKeyValue(Customer, LastNameFirstName, "Moore", "Vince") + hMinVal, ... HBuildKeyValue(Customer, LastNameFirstName, "Moore", "Vince") + hMaxVal)
- If the lower bound and the upper bound must be identical and if some key components are not specified, the hMinVal and hMaxVal constants must be used to fill the bounds.
The following example is used to find all the records of Customer file corresponding to "Moore":
HFilter(Customer, LastNameFirstName, ... HBuildKeyValue(Customer, LastNameFirstName, "Moore" + hMinVal), ... HBuildKeyValue(Customer, LastNameFirstName, "Moore" + hMaxVal))
Remarks: - hMinVal is equivalent to Charact(0)
- hMaxVal is equivalent to Charact(255)
Building a compound key without using the HBuildKeyValue function To build the value of a composite key without using HBuildKeyValue, you can: - Solution 1: Using an array of values (recommended solution):
For example:
HReadSeekFirst(FILEB, LINKEDCOMPKEY, ["Last name", "First name"])
- Solution 2: Managing each type of component:
- entirely fill the text components with the hMinVal constant.
- convert the numeric components with HConvert.
For example:
MyCompositeKey = Complete(Customer.CustomerLastName, ... Dimension(Customer.LastName), hMinVal) + ... Complete(Customer.FirstName, Dimension (Customer.FirstName), hMinVal)
Remark: We recommend that you use HBuildKeyValue. The hMinVal constant is equivalent to Charact(0).
This page is also available for…
|
|
|
| |
| //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 |
|
|
|
| |
| |
| |
|
| EXEMPLO DE USO DE CHAVE COMPOSTA |
|
| //NA TABELA COLOCA A CHAVE COMPOSTA COM OS DOIS CAMPOS QUESTIONARIO E GRUPO CRIA UM BUFFER E USA NA BUSCA
valorNovo is int = TABLEGRID_T027_GRUPOS_PERGUNTAS.COL_T027_ORDEM + 1
bufSearch is Buffer = HBuildKeyValue(T027_GRUPOS_PERGUNTAS,T027_CHAVECOMPOSTA, pgnIDQuestionario,gnIDGrupoPergunta)
IF HReadSeekFirst(T027_GRUPOS_PERGUNTAS,T027_CHAVECOMPOSTA,bufSearch) = True IF HFound(T027_GRUPOS_PERGUNTAS) = True T027_GRUPOS_PERGUNTAS.T027_ORDEM = valorNovo HModify(T027_GRUPOS_PERGUNTAS) END END
TableDisplay(TABLEGRID_T027_GRUPOS_PERGUNTAS,taInit) TableDisplay(TABLEGRID_T027_GRUPOS_PERGUNTAS,taReExecuteQuery) |
|
|
|
| |
| |
| |
|
| | bufChaveComposta is Buffer = HBuildKeyValue(GPU_14_SoftPoliceUserItem,ChaveComposta,[CodigoGrupo,1,gnConfiguration_ID,gnCompany_ID,gnSoft_ID,gnWinRepProc_ID,gIDControle]) IF HReadSeek(GPU_14_SoftPoliceUserItem,ChaveComposta,bufChaveComposta,hIdentical) = True THEN Info(GPU_14_SoftPoliceUserItem.FullName) END |
|
|
|
| |
| |
| |
| |
| |
| |
| | |
|