Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


Execute This API executes a prepared statement. This must It should be be called after binding parametersparameter binding.

The API can also be called in the form of a method attached to a statement object as follows: stmt.execute().

Parameters
  1. Handle . Must be a handle from a prepare statement only.

Return Value

...

  1. from a prepared statement. This parameter can be omitted if the API is called as a statement method.

Exception Handling

If there is a problem creating the data area, an Error will be thrown with the following properties:

  • message - The IBM i message text.
  • error - The message id.
  • help - The message help text.

...

SQL diagnostics are reported in the SQLCA:

https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_73/db2/rbafzfielddescsqlca.htm

SQLCA fields are defined in Profound.js programs with the names in lowercase. sqlcode will be set to zero if execution was successful.

Example
SearchTerm
Code Block
languagejavascript
titleCalled directly
var searchTerm = '%' + search + '%';
var  Statementsql = 'SELECT * FROM PRODUCTSP ';
  Statement += 'WHERE products WHERE prname LIKE ? OR prdesc LIKE ?';

var Statementc1 += 'UPPER(PRNAME) LIKE ? ';
  Statement += 'OR ';
  Statement += 'UPPER(PRDESC) LIKE ? ';
  Statement += 'OR ';
  Statement += 'UPPER(PRIMAGE) LIKE ? ';
  Statement += ' FOR FETCH ONLY';

 pjs.prepare(sql);
pjs.setStmtAttr(c1, SQL_ATTR_CURSOR_SCROLLABLE, SQL_TRUE);
pjs.bindParameters(c1, [searchTerm, searchTerm]);

pjs.execute(c1);


Code Block
languagejavascript
titleCalled as a method
var searchTerm = '%' + search + '%';
var sql = 'SELECT * FROM products WHERE prname LIKE ? OR prdesc LIKE ?';

var c1 = pjs.prepare(Statementsql);
  pjsc1.setStmtAttrsetAttr(c1, SQL_ATTR_CURSOR_SCROLLABLE, SQL_TRUE);
  pjsc1.bindParameters(c1, [
    [SearchTerm, SQL_PARAM_INPUT],
    [SearchTerm, SQL_PARAM_INPUT],
    [SearchTerm, SQL_PARAM_INPUT]
  [searchTerm, searchTerm]);

  pjsc1.execute(c1);


Requirements

When using an IBM i database, this API requires the Profound.js Connector module.