我正在使用我的应用程序的oracledb驱动程序与此库https://github.com/sagiegurari/simple-oracledb
结合使用我希望通过批量发送查询结果,但我一直收到错误:
错误:发送后无法设置标头。
这是我的代码:
router.get('/', function (req,res) {
"use strict";
oracledb.getConnection(connAttrs.database, 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.query("Select * from solvedtasks",{},{
splitResults: true, //True to enable to split the results into bulks, each bulk will invoke the provided callback (last callback invocation will have empty results)
bulkRowsAmount: 1000 //The amount of rows to fetch (for splitting results, that is the max rows that the callback will get for each callback invocation)
},
function onResults (err, results) {
if (err) {
res.set('Content-Type', 'application/json');
res.status(500).send(JSON.stringify({
status: 500,
message: "Error getting the user profile",
detailed_message: err.message
}));
} else if(results.length)
{
res.send(results);
}
else {
// Release the connection
console.log("done");
connection.release(
function (err) {
if (err) {
console.error(err.message);
} else {
console.log("GET /SolvedTasks : Connection released");
}
});
}
});
});
});
这个错误显然是因为它不止一次地执行res.send(结果)。我只得到前1000行,然后发生错误。任何想法如何解决这个问题,继续以批量发送结果,但没有得到错误?