ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / Managing databases / HFSQL / HFSQL functions
  • When to use <Source>.BuildKeyValue?
  • Generic search
  • Building a composite key used in a filter with bounds
  • Building a composite key without using <Source>.BuildKeyValue
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
<Source>.BuildKeyValue (Function)
In french: <Source>.ConstruitValClé
ODBCNot available with this kind of connection
Builds the value of a composite key to implement a filter (<Source>.Filter) or to perform a search (<Source>.ReadSeekFirst, <Source>.ReadSeekLast, etc.).
This function can be replaced with an array of values, easier to use. For example:
FileName.ReadSeekFirst(LINKEDCOMPKEY, ["Last name", "First name"])
Are equal to:
FileName.ReadSeekFirst(LINKEDCOMPKEY, ...
FileName.BuildKeyValue(LINKEDCOMPKEY, "Last name", "First name"))
Tip: To loop through a data file using a composite key, use the FOR EACH statement with a composite key (syntax 5).
For more details on composite keys in WINDEV, see Composite keys.
Reminder: The composite keys are binary strings whose content cannot be displayed directly.
Example
bufSoughtVal is Buffer
 
// Build the composite key
bufSoughtVal = Customer.BuildKeyValue(LastName_FirstName, "MOORE", "Vince")
 
// Build a String/Integer composite key
bufSoughtVal = Customer.BuildKeyValue(LASTNAME_CUSTNUM,"MOORE",12128)
 
// Build an Integer/Integer composite key
bufSoughtVal = Order.BuildKeyValue(ORDERID_ORDERID, 12119,593)
Syntax
<Result> = <Source>.BuildKeyValue(<Composite key> , <Value of components>)
<Result>: Buffer
Value of the composite key.
<Source>: Type corresponding to the specified source
Name of HFSQL data file used.
<Composite key>: Character string
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 <Source>.BuildKeyValue?

<Source>.BuildKeyValue can be used to perform searches on binary string keys linked to composite keys.
For example:
  • 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:
FileB.ReadSeekFirst(LINKEDCOMPKEY, FileA.BuildKeyValue(COMPKEY, ...
"Last name", "First name"))
or
bufKey is Buffer
bufKey = FileA.BuildKeyValue(COMPKEY, "Last name", "First name")
FileB.ReadSeekFirst(LINKEDCOMPKEY, buKey)
or
FileB.ReadSeekFirst(LINKEDCOMPKEY, FileA.COMPKEY)
if FileA is positioned on the record to search for in FileB.
You can also use an array of values instead of <Source>.BuildKeyValue:
FileB.ReadSeekFirst(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 used in a filter, call <Source>.BuildKeyValue.
  • 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":
    Customer.Filter(...
    Customer.BuildKeyValue(LastNameFirstName, "Moore", "Vince") + hMinVal, ...
    Customer.BuildKeyValue(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":
    Customer.Filter(LastNameFirstName, ...
    Customer.BuildKeyValue(LastNameFirstName, "Moore" + hMinVal), ...
    Customer.BuildKeyValue(LastNameFirstName, "Moore"+ hMaxVal)
Remarks:
  • hMinVal is equivalent to Charact(0)
  • hMaxVal is equivalent to Charact(255)

Building a composite key without using <Source>.BuildKeyValue

You can use an array of values to build the value of a composite key without using <Source>.BuildKeyValue.
For example:
FileB.ReadSeekFirst(LINKEDCOMPKEY, ["Last name", "First name"])
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