$.udb.executeSQLStatement()
This article is about the executeSQLStatement() function of the $.udb object.
$.udb.executeSQLStatement()
Executes a SQL statement.
The functionality of .executeSQLStatement() has been largely superceded by the introduction of SQLDataSource, making this function largely deprecated. Because applications being upgraded to USoft 11 may still contain usage of .executeSQLStatement() it is still included and part of the API, but future versions will no longer have it anymore. Therefore, please migrate to SQLDataSources instead.
When executing data queries, it does not return record result values. Please use a SQLDataSource for that. The use of a VariableSetDataSource as an "Output Data Source" as specified in the ExecuteSQLStatement action in the Web Designer is still possible, but not recommended.
Returns a UdbPromise object.
Make sure to use the .then() clause or the await keyword to make sure that any further operations can be executed after the query execution is completed. Otherwise, it will not wait for that.
Syntax
$.udb.executeSQLStatement( *sql-statement-id*, [options] )
.then(() => {
// success
})
.catch(() => {
// failure
})
.finally(() => {
// executed after success / failure is handled
});
options ::= {
[hostvars]: *hostvars*,
[waitState]: *wait-state*
}
*wait-state* ::= { true | [false] }
The required sql-statement-id identifies the SQL statement to be executed.
Options is an optional struct that can have the following items, all of which are optional.
Hostvars is a struct containing name-value pairs that specify input values for the SQL statement.
Wait-state automatically adds a loading icon to the application window while the query is being executed. This is especially useful if the server needs an unusually long time to complete.
Example
$.udb.executeSQLStatement( 'MySQL', {
hostvars: {
ID:'NL01234'
}
})
.then(() => {
return $.udb.commit({ quiet: true });
})
.catch(() => {
// something went wrong with the query
});
Related events
| Event | Applies to | Occurs when |
|---|---|---|
| beforesqlstatement | Page objects | Before each call to $.udb.executeSQLStatement() |