こんにちは、あなたは美しい人です。
OracleDB に接続された node.js を使用して REST API を作成しようとしていますが、これらのばかげたバインド変数を機能させようとして頭を悩ませています。
これが私のコードです:
app.get('/mailsummary/:SCHEMA', function (req, res) {
"use strict";
oracledb.getConnection(connAttrs, function (err, connection) {
if (err) {
// Error connecting to DB
res.set('Content-Type', 'application/json');
res.status(500).send(JSON.stringify({
status: 500,
message: "Error connecting to DB",
detailed_message: err.message
}));
return;
}
connection.execute("select * from :SCHEMA.event@db3", [req.params.SCHEMA], {
outFormat: oracledb.OBJECT // Return the result as Object
}, function (err, result) {
if (err || result.rows.length < 1) {
res.set('Content-Type', 'application/json');
var status = err ? 500 : 404;
res.status(status).send(JSON.stringify({
status: status,
message: err ? "Error getting vendor mailing summary." : "Vendor or DB does nto exist.",
detailed_message: err ? err.message : ""
}));
} else {
res.contentType('application/json').status(200).send(JSON.stringify(result.rows));
}
// Release the connection
connection.release(
function (err) {
if (err) {
console.error(err.message);
} else {
console.log("GET /mailsummary/" + req.params.SCHEMA + " : Connection released");
}
});
});
});
});
何らかの理由でエラーが発生します
OracleDB : ORA-01036: illegal variable name/number
バインド変数を削除し、静的な値を割り当てて、SQL ステートメントの後に "req.params.SCHEMA" を削除し、括弧を空白のままにすると、機能します。
connection.execute("select * from peeps.event@db3", [], {
outFormat: oracledb.OBJECT // Return the result as Object
バインド変数を引き込む方法で単純なものにならなければならないことはわかっていますが、髪を引き抜いています。
オビ=ワン・ケノービを助けてください... あなたは私の唯一の希望です.
ありがとう!