Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

This API executes a non-prepared statement on IBM i, which can be used if there are no parameter markers in your SQL.

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

Note: There is a security risk if you do not sanitize any user input that is passed into this API. This is what prepared statements will do for you automatically.

Parameters
  1. Non-prepared handle (from pjs.allocStmt()). This parameter can be omitted if the API is called as a statement method.
  2. SQL statement string
    1. The SQL statement must be valid for the database you are using

Return Value

This method will return a handle which must be used again in other statements.

Exception Handling

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
Code Block
languagejavascript
titleCalled directly
c1 = pjs.allocStmt();
pjs.setStmtAttr(c1, SQL_ATTR_CURSOR_SCROLLABLE, SQL_TRUE);

pjs.executeDirect(c1, "SELECT prid FROM demolib/productsp ORDER BY prid");
pjs.fetchLast(c1, prid);
 
pjs.close(c1);
Code Block
languagejavascript
titleCalled as a method
c1 = pjs.allocStmt();
c1.setStmtAttr(SQL_ATTR_CURSOR_SCROLLABLE, SQL_TRUE);

c1.executeDirect("SELECT prid FROM demolib/productsp ORDER BY prid");
pjs.fetchLast(c1, prid);
 
c1.close();


Requirements

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