set-vars()
This function executes an SQL statement a on the database being represented by alias b. Placeholders in the form of "¶meterNumber" being defined in the statement are replaced by the values of parameters c to j. Characters that are needed for a valid syntax need to be placed in the statement. The number of selected rows is limited to 1 automatically.
If the database returns a result, each column's value is saved to a variable with the name of form "VAR_columnname" with the name being changed to uppercase. The variables must be defined in advance. The result value of the function is the value of the first column. For a variable name prefix other than VAR_ see parameter n. Important note: Regardless of the type with which the variables are defined in the variable dialogue, they are assigned the type String at runtime after the function has been executed. The type is then retained during runtime, even if the variables are used in other functions, for example. However, the type is not changed in the variable dialogue itself.
Is a column being selected of type BLOB, the parameter m allows to specify if the data being selected should be encoded with Base64 before being added to the result list. If m is true, the function performs the encoding and false will leave the data unchanged. If there are no columns of type BLOB, the parameter has no effect.
Important note: In addition to the use of ¶meterNumber for parameters it is possible to use the naming scheme for 'prepared statements'. The use of this prevents SQL Injection Attacks and should be preferred.
Parameters
Parameter |
Description |
a |
SQL statement to be called. |
b |
Database alias. |
c |
(optional) Parameter &1 of the statement. |
d |
(optional) Parameter &2 of the statement. |
e |
(optional) Parameter &3 of the statement. |
f |
(optional) Parameter &4 of the statement. |
g |
(optional) Parameter &5 of the statement. |
h |
(optional) Parameter &6 of the statement. |
i |
(optional) Parameter &7 of the statement. |
j |
(optional) Parameter &8 of the statement. |
k |
(optional) true if data in columns of type BLOB should be encoded with Base64. Default: false. |
l |
(optional) true for read-only mode. Default: false. |
m |
(optional) true if display names should be used instead of column names (see the third example). Default: false. |
n |
(optional) Different prefix for the variable names. Default: VAR_ |
Examples
Assume a map zipcodes containing all ZIP codes of Germany (imaginary 20000 entries).
Parameter a |
b |
c |
d…j |
k |
l |
m |
n |
Result |
Values of variables |
select zipcode, city, county from zipcodes |
testdb |
|
|
|
|
|
|
01067 |
VAR_ZIPCODE=01067 VAR_CITY=Dresden VAR_COUNTY=Saxony |
select zipcode as zip, city as town, county from zipcodes where zipcode = &1 |
testdb |
80336 |
|
|
|
|
|
Munich |
VAR_ZIPCODE=80336 VAR_CITY=Munich VAR_COUNTY=Bavaria |
select zipcode as zip, city as town, county from zipcodes where zipcode = &1 |
testdb |
80336 |
|
|
|
true |
var__ |
Munich |
var__ZIP=80336 var__TOWN=Munich var__COUNTY=Bavaria |