Versions Compared

Key

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

...

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)(warning) This parameter only works with the IBM i DB2 database driver.
    (info) (info) If omitted, SQL_FETCH_ALL is assumed.
  4. one or more Profound.js strongly typed field names (optional)
    (warning)(warning) This parameter only works with the IBM i DB2 database driver.
    (info) (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.


...

Code Block
languagejavascript
titleAdd a record using a primitive JavaScript object
var record = {
  id: counter,
  firstname: fname,
  lastname: lname
}
pjs.query("INSERT INTO table SET ?", record);
Add a Record
Code Block
languagejavascript
titleAdd a record using a primitive JavaScript object
// Load various types of data values into a table with four columns.


var version = "12345";

var record = {};
record.OneField = version;                         // variable
record.TwoField = data[1].__SOMEFIELD;             // object property
record.RedField = "Suspended";                     // literal
record.BlueField = cvtDate (data[1].DUEDATE);     // function call

pjs.query ("INSERT INTO table SET ?", record)
Update a Record
Code Block
languagejavascript
titleUpdate a record using a primitive JavaScript object
var fieldsToUpdate = {};
fieldsToUpdate.firstname = fname;
fieldsToUpdate.lastname = lname;
pjs.query("UPDATE table SET ? WHERE id = ?", [ fieldsToUpdate, currentId ]);

...