|
|
|
|
|
- Overview
- Null and the queries
- Ignoring the parameters: Null in HExecuteQuery
- Query parameters coming from an edit control: Null if empty
- Null and the variants
- Null and the numeric values
- Null and the WLanguage functions
- Null and the dynamic objects
The Null keyword can be used according to different methods in WLanguage: Ignoring the parameters: Null in HExecuteQuery When running a query with parameters with HExecuteQuery, some query parameters do not have to be specified. The query conditions that use parameters that are not specified or whose value is Null will be ignored. Example: Let the query "Customers_first_name" have the following SQL code: SELECT * FROM CLIENT WHERE NOM = {Param1} AND PRENOM = {Param2} - Case 1: The 2 parameters are given
HExecuteQuery(Clients_nom_prénom, hQueryDefault, "Dupond", "Jean")
will run the query:
SELECT * FROM CLIENT WHERE NOM = 'Dupond' AND PRENOM = 'Jean'
- Case 2: Only the name is given
HExecuteQuery(Clients_nom_prénom, hQueryDefault, "Dupond")
will execute the query
SELECT * FROM CLIENT WHERE NOM = 'Dupond'
- Case 3: Only the first name is given
sNom is Variant = Null
HExecuteQuery(Clients_nom_prénom, hQueryDefault, sNom, "Jean")
Or
HExecuteQuery(Clients_nom_prénom, hQueryDefault, Null, "Jean")
will execute the query
SELECT * FROM CLIENT WHERE PRENOM = 'Jean'
Query parameters coming from an edit control: Null if empty In order for your query to be run even if no value was typed by the user, check "NULL if empty" for the edit controls ("Details" tab of control description). When this option is checked, if the control is empty, the value of the parameter passed to the query will correspond to the NULL constant. No error will occur when running the query: the conditions that depend on this parameter will be ignored. For example, the SQL code run is: SELECT NomDesRubriques
FROM NomDesFichiers
WHERE Rubrique = {Param1} The "Ex1" query is run in the "Btn_OK" button by HExecuteQuery. The WLanguage code used is as follows: HExecuteQuery(Ex1, hQueryDefault, SAI_ChampSaisie1)
In this code, EDT_EditControl1 corresponds to the control in which the user must enter the query parameter. For this example, the table below describes the use of "NULL if empty": | | | Value entered by the user in EDT_EditControl1 | "NULL if empty" option checked for EDT_EditControl1 | SQL code run |
---|
No value | Checked option | SELECT NameOfItems FROM NameOfFiles | No value | Option unchecked | SELECT NameOfItems FROM NameOfFiles WHERE Item = ' ' | A value is entered | Option checked or unchecked | SELECT NameOfItems FROM NameOfFiles WHERE Item = 'ValueEntered' |
To specify that a Variant variable contains no value, use the NULL constant. Remarks: - For a variant type, NULL means "Not assigned"
- For a numeric type, NULL means "equal to 0" (see below)
vVal is Variant
IF vVal = Null THEN ...
END
vVal = 0
IF vVal = Null THEN ...
END
vVal = 5
IF vVal = Null THEN ...
END
Null and the numeric values Used with numeric values, Null enables you to compare a value to 0. The equality operators and the comparison operators can be used (= and <>). Remarks: - For a variant type, NULL means "Not assigned" (see above)
- For a numeric type, NULL means "equal to 0"
nVal is int
IF nVal = Null THEN ...
END
nVal = 5
IF nVal = Null THEN ...
END
Null and the WLanguage functions Some WLanguage functions accept Null as parameter to specify that the parameter takes no value. For example: | | TreeAdd, TreeInsert | Null allows you to display no image for the different levels of added elements. | TreeListItem | Null is used to list the children from the root of the treeview. | TreeModify | Null allows you not to modify the image defined by TreeAdd | INIWrite | Null is used to remove a keyword or a section from the INI file |
Null and the dynamic objects For the dynamic objects (class, structure, array, automation object, ...), Null is used to find out whether the object is allocated or not. For example:
MonObjetDynamique is object Automation dynamic
...
IF MonObjetDynamique = Null THEN
MonObjetDynamique = new object Automation dynamic MonServeur
END
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|