...
Code Block | ||||
---|---|---|---|---|
| ||||
var productId = 123; pjs.define("prdesc", { type: "char", length: 60 }); pjs.define("prprice", { type: "packed", length: 7, decimals: 2 }); pjs.query("SELECT prdesc, prprice FROM PRODUCTS WHERE prid = ?", productId, 1, prdesc, prrice); |
Case of column names in result set 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 either use configuration "keepColNameCase" (in effect for the entire instance ) or use API pjs.setOptions() (in effect to the 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.
Default behavior: column names are in lowercase
Code Block | ||
---|---|---|
| ||
// Example web service
function app(req, res) {
let result = pjs.query(`select name as "custName", custno as "custNumber"
from custadrp
where custno = 1234`);
res.json(result[0]);
}
exports.run = app;
// data returned:
{
"custname": "My Company",
"custnumber": 1234
} |
To keep case of column names by using pjs.setOptions()
Code Block | ||
---|---|---|
| ||
// Example web service
function app(req, res) {
pjs.setOptions({keepColNameCase: true}); // to keep case of column names as is; in effect for this session
let result = pjs.query(`select name as "custName", custno as "custNumber"
from custadrp
where custno = 1234`);
res.json(result[0]);
}
exports.run = app;
// data returned:
{
"custName": "My Company",
"custNumber": 1234
} |