Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Section
Column
width60%

API Overview

The pjs.query() API is a shortcut for executing an SQL statement and automatically fetching the results. The results are returned by default as a primitive JavaScript array or object. However, if the 4th parameter is specified, the results are instead returned into a set of strongly defined fields, a strongly defined array, or a strongly defined data structure.

This API first prepares the SQL statement, binds parameters (if any), executes the statement, and then fetches the records.

This API also has the capability to INSERT or UPDATE records using a primitive JavaScript object that represent fields and their corresponding values.

Note
If the SQL statement is an INSERT or an UPDATE, parameter 3 and parameter 4 are not applicable.
Column
width40%

Contents

Info
iconfalse
Table of Contents
maxLevel6
minLevel2
indent15px
stylenone
separatorbraces
Warning
titleImportant!

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

Section
Column
width25%

Parameters

  1. SQL statement string
    1. The SQL statement must be valid for the database you are using
  2. parameter or array of parameters to bind (optional)
  3. number of records to fetch (optional)
    (warning) This parameter only works with the IBM i DB2 database driver.
    (info) If omitted, SQL_FETCH_ALL is assumed.
  4. one or more Profound.js strongly typed field names (optional)
    (warning) This parameter only works with the IBM i DB2 database driver.
    (info) 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.
Column
width25%

Return Value

  1. If parameter 4 is specified, the API does not return a value.
  2. If 1 record is requested, the API returns a JavaScript object that represents the fetched record or null if no record was found.
  3. If more than 1 record is requested, the API returns an array of JavaScript objects, where each Object represents a record. If no records were fetched, an empty array is returned.

...