AYUDA EN LÍNEA
 WINDEVWEBDEV Y WINDEV MOBILE

Este contenido se ha traducido automáticamente.  Haga clic aquí  para ver la versión en inglés.
Ayuda / WLanguage / Administrar bases de datos / HFSQL
  • 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 AppJavaReportes y ConsultasCódigo de Usuario (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Código Navegador
WINDEV Mobile
AndroidWidget Android iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Otros
Procedimientos almacenados
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 context 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 to the linked data file, simply perform a direct assignment:
    FichierLiaison.NomDate = Client.NomDate
  • 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 HFilter.
  • Method 2: Using the FOR EACH statement.
  • Method 3: Using the HBuildKeyValue function .
  • 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(Client, NomPrenom, ["AA","Philomène"], ["Barnabé","Tartuffe"])
In this example, "AA","Zorro" is returned by the filter while "Philomene","Zorro" is not.
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(Taches, DateDébutTacheHeureDébutTache, [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 CCDépartement = ["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 line of code is used to build the value of composite key ("NAMEDATE") corresponding to "CUSTOMERNAME+ORDER_DATE" of Customer data file:
HBuildKeyValue(Client, NOMDATE, "MOULIN","03/11/85")
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:
MaCléComposée = Complete(Client.NomClient, Dimension(Client.Nom), hMinVal)) + ...
	Complete(Client.Prénom, Dimension (Client.Prénom), hMinVal)

WLanguage properties associated with composite keys

The following properties are used to manage composite keys through programming:
BinaryEl Binario Property se utiliza para determinar si un elemento es binario.
ComponentLa propiedad Component configura los diferentes componentes de una clave compuesta.
CompositeKeyLa propiedad CompositeKey determina si un campo es una clave compuesta.
KeyExpressionLa KeyExpression Property se utiliza para set los diferentes componentes de una clave compuesta.
NbComponentEl NbComponent Property se utiliza para get el número de elementos de una clave compuesta.
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 search key with HBuildKeyValue. All the values of key components must be specified.
  2. Use the HReadSeekFirst function.
Remark: By default, HReadSeekFirst is used to perform an exact-match search.
ValCléComp is Buffer
ValCléComp = HBuildKeyValue(Client, Nom_CP, "Moulin", "34000")
HReadSeekFirst(Client, Nom_CP, ValCléComp)
WHILE HFound() = True
	...
	HReadNext(Client, Nom_CP)
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 search key with HBuildKeyValue. All the values of key components must be specified.
  2. Call 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.
ValCléComp is Buffer
ValCléComp = HBuildKeyValue(Client, Nom_CP, "Moulin", "34000")
HReadSeek(Client, Nom_CP, ValCléComp, hIdentical)
WHILE HFound() = True
	...
	HReadNext(Client, Nom_CP)
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 search key with HBuildKeyValue. Only the values of first key components can be specified.
  2. Call 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.
ValCléComp is Buffer
ValCléComp = HBuildKeyValue(Client, Nom_CP, "Moulin")
HReadSeekFirst(Client, Nom_CP, ValCléComp, hGeneric)
WHILE HFound() = True
	...
	HReadNext(Client, Nom_CP)
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 search key with HBuildKeyValue. Only the values of first key components can be specified.
  2. Use the HReadSeek function.
Remark: By default, HReadSeek is used to perform a generic search. To perform an exact-match search, the hIdentical constant must be specified.
ValCléComp is Buffer
ValCléComp = HBuildKeyValue(Client, Nom_CP, "Moulin")
HReadSeek(Client, Nom_CP, ValCléComp)
WHILE HFound() = True
	...
	HReadNext(Client, Nom_CP)
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:
Filtro HFDefine y activa un filtro en un archivo de datos, vista o consulta.
HFilterIdenticalDefine y habilita un filtro utilizado para encontrar el valor exacto de un elemento de cadena.
HFilterIncludedBetweenDefine y activa un filtro de tipo "Comprendido entre" en un archivo de datos, vista o consulta.
HFilterStartsWithDefine y activa un filtro de tipo "Comienza por" en un archivo, vista o consulta.

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.
sCléFiltre1 = HBuildKeyValue(CLIENT, NOM_CP, "MOULIN", "34000")
sCléFiltre2 = HBuildKeyValue(CLIENT, NOM_CP, "MOULIN", "34999")
sCléParcours = HFilter(Client, NOM_CP, sCléFiltre1, sCléFiltre2)
HReadFirst(Client, sCléParcours)
WHILE NOT HOut()
	...
	HReadNext(Client, sCléParcours)
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.
sCléFiltre = HBuildKeyValue(CLIENT, NOM_CP, "MOULIN", "34000")
sCléParcours = HFilter(Client, NOM_CP, sCléFiltre, hMaxVal)
HReadFirst(Client, sCléParcours)
WHILE NOT HOut()
	...
	HReadNext(Client, sCléParcours)
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.
Versión mínima requerida
  • Versión 14
Esta página también está disponible para…
Comentarios
Haga clic en [Agregar] para publicar un comentario

Última modificación: 04/04/2024

Señalar un error o enviar una sugerencia | Ayuda local