Description |
SQLExecute (Magic xpa 4.x)
Executes an SQL statement. This function lets you dynamically execute SQL statements without having a dedicated task. To execute an SQL statement on a local database, use the ClientSQLExecute function.
|
Syntax:
|
SQLExecute (database name, SQL statement, [variable], …)
|
Parameters:
|
database name – An Alpha string containing the database name
|
|
SQL statement – An Alpha string
|
|
variable: variable reference. This is optional and an unlimited number of variables can be used. For example: ‘A‘VAR.
|
Returns:
|
Logical.
The function returns False if the SQL execution fails or if there is an error in executing the statement.
The function returns True if the execution succeeds. The SQL statement result is stored in the optional parameters.
For example:
-
An SQL statement that does not return a value: SQLExecute(‘my db',drop table ABC’).
-
An SQL statement that returns a single value: SQLExecute(‘my db',‘select count(*) from ABC’,'A'Var).
-
An SQL statement that returns multiple values (multiple columns): SQLExecute(‘my db',‘select var1,var2 from ABC’,'A'Var,'B'Var).
|
Note:
|
-
Instead of using a hard-coded database name (such as 'mydb'), it is recommended to use the DbName('xxx'DSOURCE,3) function. This way, if the database is changed, no change will be required in the programs.
-
If the SQL statement returns a value, the value will be stored in the variable's optional parameters that were defined.
-
The values set by the function are based on the SQL statement's returned value. For example, a ‘Select count(*)’ statement will return a Numeric value.
-
If there is an error in the syntax, the function is ignored.
-
If the result contains multiple rows, only the values from the first row are returned.
-
If additional parameters were provided (more than the result columns), the redundant variables will be cleared (updated with NULL or the default value, according to the variable).
-
The error code and message will be available via the ErrDbmsCode and ErrDbmsMessage functions.
|
Exceptions:
|
This function is not supported for Space and DB2/400 databases.
|
See also:
|
The Online and Rich Client Samples projects (program SQ17 and RSQ17)
|
Since version: 3.1
|
|
---|