|
|
|
|
|
- Overview
- Null and the queries
- Ignoring the parameters: Null in HExecuteQuery
- Parameters of a query 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's consider the query named "Customer_LastName_FirstName" whose SQL code is as follows: SELECT * FROM CUSTOMER WHERE LASTNAME = {Param1} AND FIRSTNAME = {Param2} - Case 1: The 2 parameters are specified
HExecuteQuery(Customer_LastName_FirstName, hQueryDefault, "Smith", "John")
will execute the query:
SELECT * FROM CUSTOMER WHERE LASTNAME = 'Smith' AND FIRSTNAME = 'John'
- Case 2: Only the last name is specified
HExecuteQuery(Customer_LastName_FirstName, hQueryDefault, "Smith")
will execute the query
SELECT * FROM CUSTOMER WHERE LASTNAME= 'Smith'
- Case 3: Only the first name is specified
// use the mandatory variant for the Null variable (not filled) sLastName is Variant = Null HExecuteQuery(Customer_LastName_FirstName, hQueryDefault, sLastName, "Vince")
Or
HExecuteQuery(Customer_LastName_FirstName, hQueryDefault, Null, "Vince")
will execute the query
SELECT * FROM CUSTOMER WHERE FIRSTNAME= 'John'
Parameters of a query 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. Therefore, no error occurs when running the query: the conditions relative to this parameter will be ignored. For example, the SQL code run is: SELECT NameOfItems
FROM NameOfFiles
WHERE Item = {Param1} The "Ex1" query is run in the "Btn_OK" button by HExecuteQuery. The WLanguage code used is as follows: HExecuteQuery(Ex1, hQueryDefault, EDT_EditControl1)
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 ... // The test returns True because the variant is not assigned END Â vVal = 0 IF vVal = Null THEN ... // The test returns False because the variant is assigned // with an integer whose value is 0 END Â vVal = 5 IF vVal = Null THEN ... // The test returns False because the variant is assigned // with an integer whose value is 5 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 vVal = Null THEN ... // The test returns True because nVal=0 END Â nVal = 5 IF vVal = Null THEN ... // The test returns False because nVal=5 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: // Declare a dynamic automation object MyDynamicObject is dynamic Automation object ... Â IF MyDynamicObject = Null THEN // Create a dynamic automation object MyDynamicObject = new object Automation dynamic MyServer END
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|