Env. Oracle 21c, Node v20
The problem is that the parameter values are not being passed from the client to the server. However, when hard-coding the values results are returned. Help greatly appreciated. Thanks!
Function roughly outlined here.
<code>const oracledb = require('oracledb');
const mypw = ... // the hr schema password
async function getRecords(req, res) {
let connection;
// client inputs
let p1 = req.query.p1;
let p2 = req.query.p2;
try {
connection = await oracledb.getConnection({
user: "myuser",
password: mypw,
connectString: "localhost/DB1"
});
const result = await connection.execute(
`BEGIN myproc(:p1, :p2, :p_cursor); END;`,
{ // bind variables
p1: { dir: oracledb.BIND_IN, type: oracledb.STRING },
p2: { dir: oracledb.BIND_IN, type: oracledb.STRING },
p_cursor: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR },
},
[],
);
console.log(result.rows);
res.send(result.rows); // <-- empty array
} catch (err) { // catches errors in getConnection and the query
res.send(err);
} finally {
if (connection) { // the connection assignment worked, must release
try {
await connection.release();
} catch (e) {
console.error(e);
}
}
};
}
</code>
<code>const oracledb = require('oracledb');
const mypw = ... // the hr schema password
async function getRecords(req, res) {
let connection;
// client inputs
let p1 = req.query.p1;
let p2 = req.query.p2;
try {
connection = await oracledb.getConnection({
user: "myuser",
password: mypw,
connectString: "localhost/DB1"
});
const result = await connection.execute(
`BEGIN myproc(:p1, :p2, :p_cursor); END;`,
{ // bind variables
p1: { dir: oracledb.BIND_IN, type: oracledb.STRING },
p2: { dir: oracledb.BIND_IN, type: oracledb.STRING },
p_cursor: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR },
},
[],
);
console.log(result.rows);
res.send(result.rows); // <-- empty array
} catch (err) { // catches errors in getConnection and the query
res.send(err);
} finally {
if (connection) { // the connection assignment worked, must release
try {
await connection.release();
} catch (e) {
console.error(e);
}
}
};
}
</code>
const oracledb = require('oracledb');
const mypw = ... // the hr schema password
async function getRecords(req, res) {
let connection;
// client inputs
let p1 = req.query.p1;
let p2 = req.query.p2;
try {
connection = await oracledb.getConnection({
user: "myuser",
password: mypw,
connectString: "localhost/DB1"
});
const result = await connection.execute(
`BEGIN myproc(:p1, :p2, :p_cursor); END;`,
{ // bind variables
p1: { dir: oracledb.BIND_IN, type: oracledb.STRING },
p2: { dir: oracledb.BIND_IN, type: oracledb.STRING },
p_cursor: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR },
},
[],
);
console.log(result.rows);
res.send(result.rows); // <-- empty array
} catch (err) { // catches errors in getConnection and the query
res.send(err);
} finally {
if (connection) { // the connection assignment worked, must release
try {
await connection.release();
} catch (e) {
console.error(e);
}
}
};
}
Create a function as described above. Tested in Postman with query parameters. Records are in the database, so I expected that data to be returned.