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


HTML Comment
hiddentrue

This column is for a table of contents or notice. If neither are needed, delete this column. If only one is needed, delete the other. If more are needed, you can add what you like, remember to check how long it becomes by clicking "Preview" in the bottom right corner. While preview, the page should be checked at half page and maximize to check that the formatting is not distorted. You may need to make some adjustments to compensate.




Warning
titleImportant!

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

Parameters

Info

This API can accept an optional database connection definition object to select between multiple database connections. To select the database connection, call pjs.getDB() and pass the result as the first parameter, followed by the parameters documented below. If a database connection definition object is not passed, the default database connection is used.

...

  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.


Info
titleLimitations

16MB of data is the limit for the whole result from a pjs.query() request with the IBM i Connector. (The limit is not 16MB per column).


Examples

Load a Grid
Code Block
languagejavascript
titleLoad a grid where screen fields match database fields
pjs.defineDisplay("display", "mydisplay.json");
var records = pjs.query("SELECT * FROM ORDERS");
display.grid1.replaceRecords(records);

...

Case of column names in result set for IBMi database

Prior For IBMi database, prior to Profound.js release 5.7.0, the names of the columns in the result set returned by pjs.query() and other Profound.js APIs are always in lowercase. Since Profound.js release 5.7.0, you can use either use  configuration "keepColNameCase"(in effect for the entire instance ) or use API pjs.setOptions() (in effect for the current Profound.js session) to instruct pjs.query() and other SQL APIs to keep the case of the columns names as is, as resulted from the SQL statement.  For backward compatibility and to avoid breaking current user code, the default behavior is the "old" behavior; that is, the column names are always in lowercase.

...