...
Section |
---|
Column |
---|
| Parameters- SQL statement string
- parameter or array of parameters to bind (optional)
- number of records to fetch (optional)
If omitted, SQL_FETCH_ALL is assumed. - one or more Profound.js strongly typed field names (optional)
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 |
---|
| Return Value- If the parameter 4 is specified, the API does not return a value.
- If 1 record is requested, the API returns a JavaScript object that represents the fetched record or null if no record was found.
- 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.
|
|
Examples
...
Example 1
Code Block |
---|
language | javascript |
---|
title | Load a grid where screen fields match database fields |
---|
|
pjs.defineDisplay("display", "mydisplay.json");
var records = pjs.query("SELECT * FROM ORDERS");
display.grid1.replaceRecords(records); |
Example 2
Code Block |
---|
language | javascript |
---|
title | Retrieve product description through a primitive JavaScript object |
---|
|
var productId = 123;
var record = pjs.query("SELECT prdesc FROM PRODUCTS WHERE prid = ?", productId, 1);
if (record != null) {
var description = record.prdesc;
} |
Example 3
Code Block |
---|
language | javascript |
---|
title | Retrieve product description into a strongly typed field |
---|
|
var productId = 123;
pjs.define("prdesc", { type: "char", length: 60 });
pjs.query("SELECT prdesc FROM PRODUCTS WHERE prid = ?", productId, 1, prdesc);
var description = prdesc; |
Example 4
Code Block |
---|
language | javascript |
---|
title | Retrieve multiple strongly typed fields |
---|
|
var productId = 123;
pjs.define("prdesc", { type: "char", length: 60 });
pjs.define("prprice", { type: "packed", length: 7, decimals: 2 });
pjs.query("SELECT * FROM PRODUCTS WHERE prid = ?", productId, 1, prdesc, prrice); |
Example 5
Code Block |
---|
language | javascript |
---|
title | Retrieve records that match search critertia |
---|
|
search = '%' + search.trim() + '%'; // adjust for LIKE search
var records = pjs.query("SELECT * FROM EMPLOYEES WHERE firstname LIKE ? OR LASTNAME LIKE ?", [search.trim(), search.trim()]); |
Example 6
Code Block |
---|
language | javascript |
---|
title | Add a record using a primitive JavaScript object |
---|
|
var record = {
id: counter,
firstname: fname,
lastname: lname
}
pjs.query("INSERT INTO table SET ?", record); |
The following example is (s) are available with Profound.js version 3.0.3 and later.
Example 7
Code Block |
---|
language | javascript |
---|
title | Update a record using a primitive JavaScript object |
---|
|
var fieldsToUpdate = {};
fieldsToUpdate.firstname = fname;
fieldsToUpdate.lastname = lname;
pjs.query("UPDATE table SET ? WHERE id = ?", [ fieldsToUpdate, currentId ]); |