node-oracledb icon indicating copy to clipboard operation
node-oracledb copied to clipboard

Problems using bind parameters

Open hardy21 opened this issue 8 years ago • 5 comments

I'm transitioning from orawrap to node-oracledb and I'm having a few issues. I've tried a few things in my code but I can't have it work properly when using SELECT statements and parameters.

Here is an example using direct fetch:

//General settings
oracledb.outFormat = oracledb.OBJECT;
oracledb.maxRows = 5000;


// Create pool
oracledb.createPool(
    {
        user: dbConfig.get("user"),
        password: dbConfig.get("password"),
        connectString: dbConfig.get("connectString"),
        poolMax: 35,
        poolMin: 2,
        poolIncrement: 5,
        poolTimeout: 60
    },
    function (err, pool) {

        if (err) throw err;
        
    }
);

// I have multiple requests similar to this in my code 
router.get('/get_elements/:id',
    (req:express.Request, res:express.Response) => {

        var id = req.params.id;

        oracledb.getConnection((err:any, connection:any) => {

            connection.execute(
            "SELECT * FROM shot_experiment where id = :id",
            [id],
            (err:any, result:any) => {
                if (err) {
                    var errStr:string = "Internal error encountered: " + err.message;
                    log.error(errStr);
                    res.status(500).send(errStr);
                } else if (result.rows.length === 0) {
                    var errStr:string = "Element for ID " + req.params.id + " not found";
                    log.error(errStr);
                    res.status(500).send(errStr);
                } else {
                    res.json(result.rows[0]);
                }
                doRelease(connection);
            }
            );
        });
    });

function doRelease(connection:any)
{
    connection.close(
        function(err:any) {
            if (err)
                console.error(" Connection close ERROR: " + err.message);
        }
    );
}

With the code above, the server exits with:

Process finished with exit code -1073741819 (0xC0000005)

I've also tried using fetchOneRowFromRS without success.

hardy21 avatar Jan 10 '18 00:01 hardy21

@hardy21 The code looks fine to me at first glance, though I'm not a TypeScript developer. Seems like the app is crashing. I recommend starting by commenting out the route handler and see if the code to create the pool runs without crashing (add a console.log there to confirm).

Then start adding code back or remove more code if necessary.

dmcghan avatar Jan 10 '18 02:01 dmcghan

In general, make sure the connection is open until data has been fetched.

oracledb.maxRows = 5000;

And transition to node-oracledb v2, see https://blogs.oracle.com/opal/node-oracledb-v2-query-methods-and-fetch-tuning

cjbj avatar Jan 10 '18 02:01 cjbj

It appears the problem is coming from the 'SELECT *'. This table has 276 columns. When I query just a few columns, it succeeds. How can I handle this case?

I also have a query like this that fails:

SELECT a.*, b.names FROM table_name a LEFT OUTER JOIN occupation b on a.id = b.id where a.id = :id

It is querying the same table as above and joining it with a second table.

BTW, I have not transition to v2 yet.

hardy21 avatar Jan 12 '18 01:01 hardy21

@hardy21 follow the debugging comments from @dmcghan. If you still have problems, you will need to post much more detail.

At an outside guess, try reducing maxRows to see if you are hitting some Node or system memory limitation: you are currently causing Node (and Oracle) to allocate memory equivalent to 5000 x the potential width of your data. If this is a factor, use a ResultSet.

cjbj avatar Jan 12 '18 02:01 cjbj

Closing. Let us know if this is still an issue.

cjbj avatar Jan 18 '18 02:01 cjbj