Skip to content

How to chain multiple sql query  #490

@inttyl

Description

@inttyl

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
            });
        }
    };`

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions