$.udb.executeSQLStatement()

  • 22 July 2022
  • 2 replies
  • 178 views

This article is about the executeSQLStatement() function of the udb object.

$.udb.executeSQLStatement()

Executes a SQL statement.

On USoft 10, do not use this technique for queries. For queries, prefer a SQLDataSource object that you access like so:

$.udb('MySQLDataSource').executeQuery()

Returns a Promise object or the 'this' object. From USoft 10.0.1I, returns a udbPromise instead of a Promise object.

In the case of queries, does not return record result values. You can "catch” the result values in a SQLDataSource (USoft 10) or in a VariableSetDataSource (USoft 9, see USoft 9 alternative to SQLDataSource).

Make sure this function returns the promise instead of just executing with an undefined result. Otherwise, further operations may not wait until it completes. For a full discussion, click here.

Syntax

.executeSQLStatement( sql-statement, options )

options ::= {
hostvars: hostvars,
waitState: wait-state,
promise: promise,
success: success-function,
error: error-function
}

wait-state ::= { true | false }
promise ::= { true | false }

The required sql-statement identifies the SQL statement to be executed.

Options is a 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.

Promise determines the return value of this function. If promise has the value 'true' (the default), a Promise object is returned. If promise has the value 'false', the ‘this’ object is returned instead.

Success-function is a function called after the operation has successfully completed.

Error-function is a function called if an error occurs.

Example

$.udb.executeSQLStatement( 'MySQL', {hostvars: {ID:'NL01234'} } )
.then(function() {
...
});

 


2 replies

    

Read here how to create/define a SQL statement:

 

Reply