我正在读取oracle ref Cursor并将其存储在p_ref out参数中,并使用resultset.toquerystream()
方法中的流,我正在读取数据并将数据推入数组变量中,一旦到达流的末尾,我将发送数据
它对于1000条记录的小型数据集工作正常,但是由于出现错误ERR_EMPTY_RESPONSE而失败,因为您可以看到我将数据存储在数组中,并在结束时返回数据
但失败并显示“ ERR_EMPTY_RESPONSE”
oracledb.getConnection(
ds.settings,
function (err, connection) {
if (err) {
cb(err.message, []);
return;
}
let count = 0;
let params = {
p_ref: {type: oracledb.CURSOR, dir: oracledb.BIND_OUT}
};
let cursor = null;
let queryStream = null;
let data = [];
connection.execute(
sql,
params,
{outFormat: oracledb.OBJECT},
function (err, result) {
if (err) {
cb(err.message, []);
doRelease(connection);
return;
}
cursor = result.outBinds.p_ref;
queryStream = cursor.toQueryStream();
queryStream.on('data', function (row) {
count++;
data.push(row);
});
queryStream.on('error', function (err) {
if (!cbCalled) {
cbCalled = true;
cb(err.message);
doRelease(connection);
}
});
queryStream.on('end', function () {
console.log('Rows selected: ' + count);
cb('', data);
doRelease(connection);
});
queryStream.on('close', function () {
if (!cbCalled) {
console.log(count);
doRelease(connection);
}
});
}
);
}
);
此处引用https://github.com/oracle/node-oracledb/blob/master/doc/api.md
var stream = connection.queryStream('SELECT employees_name FROM employees');
stream.on('error', function (error) { // handle any error... });
stream.on('data', function (data) { // handle data row... });
stream.on('end', function () { // release connection... });
stream.on('metadata', function (metadata) { // access metadata of query });
答案 0 :(得分:0)
尝试从“结束”事件中删除对doRelease()的调用。