- 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
- Note: Filter with selection condition
Composite keys
 Disponible solo con estos tipos de conexión
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:
A composite key is created in the data model editor directly. To create a composite key in the description of a data file: - Open the description of the data file items:
- Select the data file in the editor.
- Open the context menu (right click) and select "Description of items".
- Click
. A screen appears, allowing you to build the composite key. - 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.
- Reorganize (if necessary) the items that belong to the composite key.
Please note The order of the sort items is very important, as it determines the sort order. For example, the "Name + State" composite key will be sorted on the name then on the state. - Specify the search direction and the search parameters for each key component.
- 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.
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 to the linked data file, simply perform a direct assignment:
LinkFile.NameDate = Customer.NameDate
- via the HBuildKeyValue function . 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 function HFilter.
- Method 2: Use FOR EACH instruction.
- Method 3: Use the HBuildKeyValue function.
- Method 4: Use of HConvertX function (method retained for 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 Search for all records in the customer data file whose first and last names are between "AA", "Barnabé", "Philomène" and "Tartuffe". HFilter(Customer, LastNameFirstName, ["AA", "Philomene"], ["Barnaby", "Tartuffe"])
In this example, "AA","Zorro" is returned by the filter while "Philomene","Zorro" is not. Example Search for all records in the data file Tasks with tasks between 03/15/2011 00:00 and 03/25/2011 00:00. HFilter(Tasks, TaskStarDateTaskStartTime, [20110315,0000], [20110325,0000])
Method 2: Using the FOR ALL instruction 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 Search for prospective customers living in the Rhône department. FOR EACH Contacts where CCState = ["Prospect", 69]
...
END
Method 3: Using the HBuildKeyValue function 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 line of code 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 the HConvertX function (method retained for 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 composite keys through programming:
| | Binary | The Binary property determines if an item is binary. | Component | La propiedad Component configura los diferentes componentes de una clave compuesta. | CompositeKey | La propiedad CompositeKey determina si un campo es una clave compuesta. | KeyExpression | La propiedad KeyExpression se utiliza para establecer los distintos componentes de una clave compuesta. | NbComponent | The NbComponent property is used to get the number of elements 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: - Build the value of the search key with HBuildKeyValue. All the values of key components must be specified.
- Use the HReadSeekFirst function.
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: - Build the value of the search key with HBuildKeyValue. All the values of key components must be specified.
- Call HReadSeek with the hIdentical constant.
Note: By default, the HReadSeek function 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: - Build the value of the search key with HBuildKeyValue. Only the values of first key components can be specified.
- Call HReadSeekFirst 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: - Build the value of the search key with HBuildKeyValue. Only the values of first key components can be specified.
- Use the HReadSeek function.
Note: By default, the HReadSeek function 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:
| | HFilter | Defines and enables a filter on a data file, view or query. | HFilterIdentical | Defines and enables a filter used to find the exact value of a string item. | HFilterIncludedBetween | Defines and enables an "Included between" filter on a file, view or query. | HFilterStartsWith | Defines 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: - Create the values of each bound with HBuildKeyValue.
- Create the filter with HFilter and specify the two bounds.
- 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: - Create the value of lower bound with HBuildKeyValue.
- Create the filter with HFilter while specifying the lower and upper bounds. In this case, the upper bound is equal to the hMaxVal constant.
- 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: - Create the minimum and maximum values of composite key with HBuildKeyValue. Only the first components must be specified.
- 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: hValMin is equivalent to Caract(0) and hValMax is equivalent to caract(255).
- Browse the selected records.
Note: 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.
Esta página también está disponible para…
|
|
|