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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.