Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 16 Next »

Content Freeze

As of July 25th, 2023, there is a content freeze on this page.

Fetches the last row from the cursor associated with the statement handle.

This API can either fetch data into declared fields / data structures / arrays, or return data as primitive objects / arrays.

This API is only supported when using a IBM i database.

When used to return data into primitive JavaScript objects / arrays, it can be called in the form of a method attached to a statement object as follows: stmt.fetchLast().

Parameters
  1. Statement handle returned from pjs.allocStmt() or pjs.prepare(). The statement handle must be executed with pjs.execute() or pjs.executeDirect() before it can be used to fetch rows. This parameter is omitted if the API is called as a statement object method.
  2. Optionally, one or more Profound.js field names can be passed. If field names are passed, they will be bound to columns in the resulting rows and populated by this API if the fetch is successful. If no Profound.js field names are passed, this API will return fetched rows as an Array of Objects with keys named for the columns and values as JavaScript Numbers for numeric columns, and JavaScript Strings for all other column types. An empty Array is returned if the fetch is not successful.
  3. Following the optional field names, a Number can be passed that specifies the number of rows to fetch. Pass SQL_FETCH_ALL to fetch all rows. If not passed, 1 row will be fetched.


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

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);


Requirements

This API requires the Profound.js Connector module.

  • No labels