PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

  • Overview
  • Creating a composite key
  • Composite key and link
  • Value of a composite key
  • Overview
  • Adding a record containing a composite key
  • Adding a record containing a composite key into a linked 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
  • Note: 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:
Versions 17 and later
WINDEV MobileiPhone/iPad This feature is now available for the iPhone/iPad applications.
New in version 17
WINDEV MobileiPhone/iPad This feature is now available for the iPhone/iPad applications.
WINDEV MobileiPhone/iPad This feature is now available for the iPhone/iPad applications.
Versions 18 and later
WINDEV MobileAndroid This feature is now available for the Android applications.
New in version 18
WINDEV MobileAndroid This feature is now available for the Android applications.
WINDEV MobileAndroid This feature is now available for the Android applications.
Creating a composite key
A composite key is created in the data model editor directly.
To create a composite key in a file description:
  1. Display the description of the file items ("Structure of files .. Items").Display the description of file items:
    • Select the data file in the editor.
    • Display the popup menu (right mouse click) and select "Description of items".
  2. Click . A screen allowing you to build the composite key is displayed.
  3. The list of existing items 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 file items.

Composite key and link

The composite keys can be used in the links between files. When describing the analysis, the composite key found in the linked file appears not as a composite key but as a binary key. You will not be able to access the different components of the composite key in the linked file.
Note: The management of referential integrity is supported for a composite key used in a link.
Value of a 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 the different key components. No specific programming is required.

Adding a record containing a composite key into a linked file

When a record containing a composite key is added into a linked file, the value of the key must be built. Indeed, in the linked file, the composite key is not considered as being a composite key but as being a binary key. Therefore, a value must be assigned to it.
This value can be assigned:
  • directly. For example, a record was added into the Customer file. To add the value of the key into the linked file, all you have to do is perform a direct assignment:
    LinkFile.NameDate = Customer.NameDate
  • via HBuildKeyValue. This function is used to build the value of the 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 the composite key must be defined (to define the lower bound and the upper bound of the filter for example).
Several methods allow you 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 the composite key for the filter or for the search. The composite key is directly built in the syntax of the function.
Example: Find all the records in the CUSTOMER file whose last name is found between "AA" and "Barnaby" and whose first name is found 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 file whose tasks are included between 15/03/2011 00:00 and 25/03/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 the 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 name of the key and the values of components must be specified in this function.
For example, the following code line is used to build the value of the composite key ("NAMEDATE") corresponding to "CUSTOMERNAME+ORDER_DATE" of Customer 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 sought key with HBuildKeyValue. All the values of key components must be specified.
  2. Use HReadSeekFirst.
Note: 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 sought key with HBuildKeyValue. All the values of key components must be specified.
  2. Use HReadSeek associated with the hIdentical constant.
Note: 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 sought key with HBuildKeyValue. Only the values of the first key components can be specified.
  2. Use HReadSeekFirst associated with the hGeneric constant.
Note: 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 sought key with HBuildKeyValue. Only the values of the first key components can be specified.
  2. Use HReadSeek.
Note: 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, a view or a 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 whiile specifying the lower bound and the upper bound. 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 whiile specifying the lower bound and the upper bound. In this case, the hMinVal constant must be added to the lower bound and hMaxVal must be added to the upper bound. Notes: hMinVal is equivalent to Char(0) and hMaxVal is equivalent to Char(255).
  3. Browse the selected records.

Note: Filter with selection condition

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