我正在使用node-oracledb( 3.1.2 )模块。除更新查询外,其他一切正常。我能够触发选择并插入查询,但是当我尝试触发更新查询时,似乎查询已被挂起(没有错误,没有结果)。我正在编写以下代码:
用于创建连接:
module.exports.createErpConnection = async () => {
try {
connection = await oracleDB.getConnection({
user: constants.databaseCredentials.user,
password: constants.databaseCredentials.password,
connectString: `${constants.databaseCredentials.connectString}/${constants.databaseCredentials.databaseName}`
});
if (connection) {
response.status = 1;
response.connection = connection
} else {
response.status = 0;
response.message = constants.databaseStatus.ERP_DATABASE_CONNECTION_NOT_ESTABLISHED
}
} catch (exception) {
response.status = 0;
response.message = exception;
} finally {
return response;
}
};
引发更新查询:
async function updateProductStatInErp(connection) {
let sql = `UPDATE product_master SET UPDATED_STAT='N'`;
let options = {outFormat: oracledb.OBJECT, autoCommit: true};
const res = await connection.connection.execute(sql, {}, options)
// I am not getting either response nor error
}
我还需要做任何其他事情来触发更新查询吗?
答案 0 :(得分:0)
仅在try and catch块中编写 execute 语句即可解决此问题。这是代码:
try {
const res = await connection.connection.execute(sql, {}, options)
console.log('======= 185 =======', res)
} catch (exception) {
console.log('====== 186 =====', exception)
}
Result =>> ====== 185 ======= { rowsAffected: 490 }