[英]Issue with executing prepared statement in Node JS with ibm_db module
I am new to NodeJS technology, while working on nodejs project, I got below issue. 我是NodeJS技术的新手,在从事nodejs项目时,出现以下问题。
I have implemented ibm_db module (to establish DB2 connection), and using "prepared statements" to execute 'SELECT' queries. 我已经实现了ibm_db模块(用于建立DB2连接),并使用“ prepared statement”来执行“ SELECT”查询。 Below query is executed without errors but console.log(result)
is giving result as {fetchMode : 4}
, but I am expecting COLUMN_1 results here. 下面的查询执行没有错误,但是console.log(result)
给出的结果为{fetchMode : 4}
,但是我期望这里有COLUMN_1结果。 Can someone tell me if I am missing anything here. 有人可以告诉我我是否在这里缺少任何东西。
db.prepare('SELECT COLUMN_1 FROM TABLE_A WHERE COLUMN_2=?', function(err, stmt){
if(err){
console.log(err);
}
stmt.execute(['CA'], function(err, result){
console.log(result);
});
});
Using an extra fetch inside of execute callback makes it possible for me to see the correct and wanted result of the query statement. 在执行回调中使用额外的访存可以使我看到查询语句的正确和想要的结果。 Here an example: 这里是一个例子:
db.prepare('SELECT COLUMN_1 FROM TABLE_A WHERE COLUMN_2=?', function(err, stmt){
if(err){
console.log(err);
}
stmt.execute(['CA'], function(err, result){
result.fetch(function (err, data) {
if (err) {
console.error(err);
}
console.log(JSON.stringify(data));
result.closeSync();
});
});
});
The following site gave me the hint: https://groups.google.com/d/msg/node-ibm_db/AhZeeN6jFTM/MrRXSIW3DQAJ 以下网站给了我提示: https : //groups.google.com/d/msg/node-ibm_db/AhZeeN6jFTM/MrRXSIW3DQAJ
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.