Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node.js oracledb Does Not Insert nor Update

Tags:

node.js

oracle

node-oracledb version 1.2 node v0.12.7

Selects work as expected. For Updates and Inserts, Though we get rowsAffected: 1, the insert or Update is not effected.

var oracledb = require('oracledb');

oracledb.getConnection( { user: "HRTest", password: "********", connectString: "localhost/XE" }, function (err, connection) { if (err) { console.error(err.message); return; } connection.execute( "UPDATE TBCUSTOMERDetails set FIRSTNAME=:fn WHERE id=:id ", {fn: 'new name', id: 1},

function (err, result) { if (err) { console.error(err.message); return; } console.log(result); connection.release( function (err) { if (err) { console.error(err.message); throw(err); } else console.log("released connection"); }); // end release }); // end function });</code></pre>
like image 925
ukuta Avatar asked Nov 18 '15 10:11

ukuta


2 Answers

Thanks daivrz, committing fixed the issue, the default on node-oracle is false.

var oracledb = require('oracledb');
oracledb.autoCommit = true;
like image 166
ukuta Avatar answered Nov 04 '22 07:11

ukuta


The native settings for the oracledb driver set the autoCommit to false. You can either set the autoCommit to true at the beggining of the script or call it in the connection.execute() callback.

connection.execute(
            "UPDATE TBCUSTOMERDetails set FIRSTNAME=:fn  WHERE id=:id ",
            {fn: 'new name', id: 1},
        {autoCommit: true},
        function (err, result) {
            if (err) {
                console.error(err.message);
                return;
            }
            console.log(result);
like image 38
SpicestMemeLord Avatar answered Nov 04 '22 05:11

SpicestMemeLord