pjs.bindParameters()
This API binds parameters to a prepared SQL statement.
Before using this API, you must call pjs.prepare(), so that you can pass in the handle from that call.
The API can also be called in the form of a method attached to a statement handle object as follows: stmt.bindParameters(). pjs.bindParameters() can accept field names as input/output parameters, stmt.bindParameters() cannot.
Parameters
The handle created by pjs.prepare(). This parameter is omitted if the API is called as a statement method.
An array of parameters for each SQL parameter marker. Each element in the array must be either:
An array in the form
[field, SQL_PARAM_TYPE]. Note, this form is only valid for input parameters. IfSQL_PARAM_TYPEis not provided,SQL_PARAM_INPUTis used.Added in PJS-7.25.0. An object in the form
{field, SQL_PARAM_TYPE}. Note, this form can be used for either inputs or outputs. IfSQL_PARAM_TYPEis not provided,SQL_PARAM_INPUT_OUTPUTis used.
Example
pjs.define("productsp_out", { type: 'data structure', qualified: true, dim: 50, elements: {
"prid": { type: "packed decimal", length: 5, decimals: 0, initValue: 105 },
"prname": { type: "char", length: 30 },
"prdesc": { type: "char", length: 60 }
}})
pjs.define("searchQuery", { type: "char", length: 30 });
pjs.clear(productsp_out);
searchQuery = '%' + 'Garmin' + '%';
var c1 = pjs.prepare("select prid, prname, prdesc from demolib/productsp where prdesc like ? order by prid");
pjs.bindParameters(c1, [
[searchQuery.trim(), SQL_PARAM_INPUT]
]); // example of alternate simplified syntax: c1.bindParameters(searchQuery.trim());
pjs.execute(c1);
pjs.fetch(c1, productsp_out, 50);
pjs.close(c1);Example usage of output parameters
pjs.define("prname", { type: 'char', length: 30, initValue: '' });
pjs.define("prid", { type: 'packed decimal', length: 5, decimals: 0, initValue: 101 });
pjs.define("output", { type: 'char', length: 4, initValue: 'FAIL' });
pjs.clear(prname);
let cursor = pjs.prepare("call procedure(?,?)");
cursor.bindParameters([
{prname},
{prid, SQL_PARAM_INPUT}
]);
cursor.execute();
pjs.close(cursor);
Requirements
When using an IBM i database, this API requires the Profound.js Connector module.