0

I am new to NodeJS technology, while working on nodejs project, I got below issue.

I have implemented ibm_db module (to establish DB2 connection), and using "prepared statements" to execute 'SELECT' queries. Below query is executed without errors but console.log(result) is giving result as {fetchMode : 4}, but I am expecting COLUMN_1 results here. Can someone tell me if I am missing anything here.

db.prepare('SELECT COLUMN_1 FROM TABLE_A WHERE COLUMN_2=?', function(err, stmt){
        if(err){
            console.log(err);
        }
        stmt.execute(['CA'], function(err, result){
            console.log(result);
        });
});
6
  • try logging the error here: May be there is some error? stmt.execute(['CA'], function(err, result){ console.log(err, result); }); Commented Dec 29, 2015 at 4:41
  • @SKY just now I checked that, there is no error occurred. Commented Dec 29, 2015 at 4:45
  • Am little new to DB2 and ibm_db module, what does fetchMode: 4 stand for? Commented Dec 29, 2015 at 4:53
  • Do you need to call this: result.closeSync(); Commented Dec 29, 2015 at 5:03
  • @SKY I have no idea on fetchMode. Commented Dec 29, 2015 at 5:09

1 Answer 1

1

Using an extra fetch inside of execute callback makes it possible for me to see the correct and wanted result of the query statement. Here an example:

db.prepare('SELECT COLUMN_1 FROM TABLE_A WHERE COLUMN_2=?', function(err, stmt){
    if(err){
        console.log(err);
    }
    stmt.execute(['CA'], function(err, result){
        result.fetch(function (err, data) {
            if (err) {
                console.error(err);
            }
            console.log(JSON.stringify(data));

            result.closeSync();
        });
    });
});

The following site gave me the hint: https://groups.google.com/d/msg/node-ibm_db/AhZeeN6jFTM/MrRXSIW3DQAJ

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.