Node JS Oracle Query Results

I have an oracle query in Node js (using the oracledb module).  I want to return an object,  column_name : column_value.  I found the Javascript and Oracle website (https://jsao.io/) and it defines { outFormat : oracledb.OBJECT }.  I have that in my code but not able to get the values in a result set, example:
function(err, connection) {
        if (err) {
             console.error(err.message); return;
       }
      connection.execute (
        "select id, first_name, last_name, age      " +
        "from myTable where id = 10",  { outFormat : oracledb.OBJECT }.  function(err, result) {
            console.log(result.rows);
          }
}

Error:  cannot read the property rows of 'undefined'.  If I remove the outFormat info, I get all the rows back, but only the value, I need the results like { first_name: bob, last_name: smith, age:25} or something like that.
Thanks in advance for the Node help - very painful!
kevbob650Asked:
Who is Participating?
 
slightwv (䄆 Netminder) Commented:
I was hoping a JavaScript Expert would had posted over night since my JavaScript is rusty and I've never used  Node js.

That said, I found this example which is similar to the link you posted:
https://github.com/oracle/node-oracledb/blob/master/doc/api.md

What made this one interesting is the comment:
[],  // No bind variables

If made me look at the code in the link you posted.

It appears there is a parameter between the SELECT and the "outFormat: oracledb.OBJECT}" for bind variables used in the SELECT.

Since your statement doesn't have any, from the "No bind variables" syntax.


function(err, connection) {
         if (err) {
              console.error(err.message); return;
        }
       connection.execute (
         "select id, first_name, last_name, age      " +
         "from myTable where id = 10",  { outFormat : oracledb.OBJECT }, [], function(err, result) {
             console.log(result.rows);
           }
 }

Open in new window

0
 
slightwv (䄆 Netminder) Commented:
Is that a copy/paste from the actual code?

I have ZERO experience using the "oracledb module" that you describe.  I know Oracle and I know a little Javascript.

In looking at the link you posted this looks wrong if it the actual code:
{ outFormat : oracledb.OBJECT }.  function(err, result)

The "period" before the function in your code looks like a "comma" in the examples in the link.
0
 
kevbob650Author Commented:
Yeah, that's a comma in my code as it should be.  Sorry, I might have typed a period there.  I don't know how to get the results.  I would normally test with console.log(result.rows) but it fails.  I've tried every console.log combo I can think of but nothing works.  "result" seems to be the problem?
0
 
kevbob650Author Commented:
Thanks for all your effort, this is a tough one and not a lot of good info on the nodejs.  But I'll take this as a solution and get you some points. I was able to find a work-around by using the array index, so I'm good to go for now. More node questions coming I'm sure!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.