-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Labels
Description
Hi,
I am pretty new to oracledb with NodeJS.
I want to do mutiple sql call that are dependant.
Before executing the query sqltoExecute, I need to configure the connection by executing a query that set "set role " and then another one to "set package" and finally execute my query sqltoExecute.
I am trying to find some examples but failed to find any.
Below, a snipper of the code I tried to execute but it fails since it only execute the first query , it fails to execute the second "then" that execute the query " sqlQueries.sqlQuerySetPackage()"
I am using on NodeJS 4.4.7 on Ubuntu 14.
Thanks for help.
exports.testChainingSqlQueries = function(config, sqlToExecute, callback) {
if (config) {
oracledb.getConnection(config)
.then(function(conn){
return conn.execute(
sqlQueries.sqlQuerySetRole()
)
.then(function(result){
console.log("Execution Succes : "+ sqlQueries.sqlQuery1());
return conn;
})
.catch(function(err){
console.log("Error Executing "+ sqlQueries.sqlQuery1() );
return conn.close();
})
})
.then(function(conn){
return conn.execute(
sqlQueries.sqlQuerySetPackage()
)
.then(function(result){
console.log("Execution Succes : "+ sqlQueries.sqlQuery2());
return conn;
})
.catch(function(err){
console.log("Error executing : "+ sqlQueries.sqlQuery2());
return conn.close();
})
})
.then(function(conn){
return conn.execute(
sqlToExecute
)
.then(function(result){
console.log("Execution Succes : "+ sqlToExecute);
callback(result, null);
return conn.close();
})
.catch(function(err){
console.log("Error executing : "+ sqlToExecute);
return conn.close();
})
});
} else {
callback(null, {
message: "Configuration is invalid ",
config: config
});
}
};`