PC SOFT

WINDEVWEBDEV AND WINDEV MOBILE
ONLINE HELP

Home | Sign in | English UK

  • Overview
  • Creating a composite key
  • Composite key and link
  • Value of composite key
  • Overview
  • Adding a record containing a composite key
  • Adding a record that contains a composite key into a linked data file
  • Building the value of a composite key to implement a search or a filter
  • WLanguage properties associated with composite keys
  • Using a composite key to perform exact-match searches
  • Exact-match search performed by HReadSeekFirst
  • Exact-match search and HReadSeek
  • Using a composite key to perform generic searches
  • Generic search performed by HReadSeekFirst
  • Generic search performed by HReadSeek
  • Using a composite key to create filters
  • Functions for creating filters
  • Filter between two values (bounds)
  • Filter from a given value
  • Filter on the first key components
  • Remark: Filter with selection condition
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
Overview
A composite key is a key item containing several other items. These items can be text items or numeric items.
A composite key is used to simplify the searches performed on several criteria.
The composite keys are binary items. Their value cannot be directly displayed (in a trace or in a control).
This page presents the following topics:
Creating a composite key
A composite key is created in the data model editor directly.
To create a composite key in the description of a data file:
  1. Open the description of the data file items:
    • Select the data file in the editor.
    • Open the popup menu (right click) and select "Description of items".
  2. Click . A screen appears, allowing you to build the composite key.
  3. The list of items found in the data file is displayed in the table on the left. Double-click the items that must be included in the composite key. These items are displayed in the table on the right.
  4. Reorganize (if necessary) the items that belong to the composite key.
    Caution: the order of items is important because it defines the sort order. For example, the "Name + State" composite key will be sorted on the name then on the state.
  5. Specify the search direction and the search parameters for each key component.
  6. Validate. The composite key is displayed in the list of data file items.

Composite key and link

Composite keys can be used in the links between data files. When describing the analysis, the composite key found in the linked data file appears not as a composite key but as a binary key. You will not be able to access the different components of composite key in the linked data file.
Remarks:
  • The management of referential integrity is supported for a composite key used in a link.
  • The management of modifications in cascade is not supported for a composite key used in a link.
Value of composite key

Overview

A composite key is stored as a binary string. Its value cannot be displayed (neither in a control nor in the debugger, ...).

Adding a record containing a composite key

When adding or modifying a record containing a composite key, the value of the composite key is automatically defined according to the values of different key components. No specific programming is required.

Adding a record that contains a composite key into a linked data file

When a record that contains a composite key is added into a linked data file, the value of the key must be built. Indeed, in the linked data file, the composite key is not considered as a composite key but as a binary key. Therefore, a value must be assigned to it.
This value can be assigned:
  • directly. For example, a record has been added in the Customer data file. To add the key value into the linked data file, simply perform a direct assignment:
    LinkFile.NameDate = Customer.NameDate
  • using HBuildKeyValue. This function is used to build the value of composite key from its components.

Building the value of a composite key to implement a search or a filter

When a filter or a search is implemented on a composite key, the value of composite key must be defined (to define the lower bound and the upper bound of filter for example).
Several methods can be used to build the value of a composite key:
  • Method 1: Using a list of values in HFilter.
  • Method 2: Using the FOR EACH statement.
  • Method 3: Using HBuildKeyValue.
  • Method 4: Using HConvertX (method kept for backward compatibility with WINDEV 5.5)
Method 1: List of values
All you have to do is specify the list of values that must be taken by each component of composite key for the filter or for the search. The composite key is directly built in the syntax of function.
Example: Find all the records in the Customer data file whose last name is between "AA" and "Barnaby" and whose first name is between "Philomene" and "Tartuffe".
HFilter(Customer, LastNameFirstName, ["AA", "Philomene"], ["Barnaby", "Tartuffe"])
In this example, "AA","Zorro" is returned by the filter while "Philomene","Zorro" is not returned.
Example: Find all the records in the Tasks data file whose tasks are included between 03/15/2011 00:00 and 03/25/2011 00:00.
HFilter(Tasks, TaskStarDateTaskStartTime, [20110315,0000], [20110325,0000])
Method 2: Using the FOR EACH statement
Specify the list of values that must be taken by each key component for the filter or for the search. The composite key is directly built in the syntax of function.
Example: Finding the prospect customers living in state 69.
FOR EACH Contacts WHERE CCState = ["Prospect", 69]
...
END
Method 3: Using HBuildKeyValue
The value of a composite key can be built by HBuildKeyValue. To do so, the relevant data file, the key name and the values of components must be specified in this function.
For example, the following code line is used to build the value of composite key ("NAMEDATE") corresponding to "CUSTOMERNAME+ORDER_DATE" of Customer data file:
HBuildKeyValue(Customer, NAMEDATE, "SMITH","03/11/99")
Method 4: Using HConvertX (method kept for backward compatibility with WINDEV 5.5)
You must:
  • entirely fill the text components with the hMinVal constant.
  • convert the numeric components with HConvert.
Example:
MyCompositeKey = Complete(Customer.CustomerLastName, Dimension(Customer.LastName), hMinVal)) + ...
Complete(Customer.FirstName, Dimension (Customer.FirstName), hMinVal)

WLanguage properties associated with composite keys

The following properties are used to manage the composite keys by programming:
Binary..Binary is used to find out whether an item is a binary item or not.
Component..Component is used to configure the different components of a composite key.
CompositeKey..CompositeKey is used to find out whether an item is a composite key.
KeyExpression..KeyExpression is used to configure the different components of a composite key.
NbComponent..NbComponent is used to find out the number of elements found in a composite key.
Using a composite key to perform exact-match searches

Exact-match search performed by HReadSeekFirst

To perform an exact-match search on the value of a composite key, you must:
  1. Build the value of the searched key with HBuildKeyValue. All the values of key components must be specified.
  2. Use HReadSeekFirst.
Remark: By default, HReadSeekFirst is used to perform an exact-match search.
ValCompKey is Buffer
ValCompKey = HBuildKeyValue(Customer, Name_ZC, "Smith", "34000")
HReadSeekFirst(Customer, Name_ZC, ValCompKey)
WHILE HFound() = True
...
HReadNext(Customer, Name_ZC)
END

Exact-match search and HReadSeek

To perform an exact-match search on the value of a composite key, you must:
  1. Build the value of the searched key with HBuildKeyValue. All the values of key components must be specified.
  2. Use HReadSeek with the hIdentical constant.
Remark: By default, HReadSeek is used to perform a generic search. To perform an exact-match search, the hIdentical constant must be specified.
ValCompKey is Buffer
ValCompKey = HBuildKeyValue(Customer, Name_ZC, "Smith", "34000")
HReadSeek(Customer, Name_ZC, ValCompKey, hIdentical)
WHILE HFound() = True
        ...
        HReadNext(Customer, Name_ZC)
END
Using a composite key to perform generic searches

Generic search performed by HReadSeekFirst

To perform a generic search on the value of a composite key, you must:
  1. Build the value of the searched key with HBuildKeyValue. Only the values of first key components can be specified.
  2. Use HReadSeekFirst with the hGeneric constant.
Remark: By default, HReadSeekFirst is used to perform an exact-match search. To perform a generic search, the hGeneric constant must be specified.
ValCompKey is Buffer
ValCompKey = HBuildKeyValue(Customer, Name_ZC, "Moore")
HReadSeekFirst(Customer, Name_ZC, ValCompKey, hGeneric)
WHILE HFound() = True
        ...
        HReadNext(Customer, Name_ZC)
END

Generic search performed by HReadSeek

To perform a generic search on the value of a composite key, you must:
  1. Build the value of the searched key with HBuildKeyValue. Only the values of first key components can be specified.
  2. Use HReadSeek.
Remark: By default, HReadSeek is used to perform a generic search. To perform an exact-match search, the hIdentical constant must be specified.
ValCompKey is Buffer
ValCompKey = HBuildKeyValue(Customer, Name_ZC, "Moore")
HReadSeek(Customer, Name_ZC, ValCompKey)
WHILE HFound() = True
        ...
        HReadNext(Customer, Name_ZC)
END
Using a composite key to create filters

Functions for creating filters

In addition to HFilter, several WLanguage functions can be used to create specific filters. These functions can handle the composite keys:
HFilterDefines and enables a filter on a data file, view or query.
HFilterIdenticalDefines and enables a filter used to find the exact value of a string item.
HFilterIncludedBetweenDefines and enables an "Included between" filter on a file, view or query.
HFilterStartsWithDefines and enables a "Start with" filter on a file, view or query.

Filter between two values (bounds)

To filter records between two specific values of a composite key, you must:
  1. Create the values of each bound with HBuildKeyValue.
  2. Create the filter with HFilter and specify the two bounds.
  3. Browse the selected records.
sFilterKey1 = HBuildKeyValue(CUSTOMER, NAME_ZC, "MOORE", "34000")
sFilterKey2 = HBuildKeyValue(CUSTOMER, NAME_ZC, "MOORE", "34999")
sSearchKey= HFilter(Customer, NAME_ZC,  sFilterKey1,  sFilterKey2)
HReadFirst(Customer, sSearchKey)
WHILE NOT HOut()
        ...
        HReadNext(Customer, sSearchKey)
END

Filter from a given value

To filter the records from a given value (without specifying any upper bound), you must:
  1. Create the value of lower bound with HBuildKeyValue.
  2. Create the filter with HFilter while specifying the lower and upper bounds. In this case, the upper bound is equal to the hMaxVal constant.
  3. Browse the selected records.
sFilterKey = HBuildKeyValue(CUSTOMER, NAME_ZC, "MOORE", "34000")
sSearchKey = HFilter(Customer, NAME_ZC, sFilterKey, hMaxVal)
HReadFirst(Customer, sSearchKey)
WHILE NOT HOut()
        ...
        HReadNext(Customer, sSearchKey)
END

Filter on the first key components

To filter the records on the first components of a composite key and to perform a sort on the following components, you must:
  1. Create the minimum and maximum values of composite key with HBuildKeyValue. Only the first components must be specified.
  2. Create the filter with HFilter while specifying the lower and upper bounds. In this case, the hMinVal constant must be added to the lower bound and hMaxVal must be added to the upper bound. Remarks: hMinVal is equivalent to Char(0) and hMaxVal is equivalent to Char(255).
  3. Browse the selected records.

Remark: Filter with selection condition

If the filter condition affects several items corresponding to a composite key of the data file, the search key automatically selected by the filter will be this composite key.
Minimum version required
  • Version 14
This page is also available for…
Comments
Click [Add] to post a comment