Forum Stats

  • 3,733,852 Users
  • 2,246,830 Discussions
  • 7,856,896 Comments

Discussions

INSERT - Error: NJS-044: named JSON object is not expected in this context

3784542
3784542 Member Posts: 3
edited September 2018 in Node.js

I am trying to perform an insert statement, and am getting the following error: Error: NJS-044: named JSON object is not expected in this context.

I've used the example insert from the  Github (https://github.com/oracle/node-oracledb/blob/master/examples/em_insert1.js ) and changed out parameters to fit my project.

what's causing this?

var doconnect = function(cb) {

  oracledb.getConnection(serviceConfig, cb);

  console.log("oracle connected");

};


var dorelease = function(conn) {

  conn.close(function(err) {

   if (err) console.error(err.message);

  });

};


var doinsert = function(conn, cb) {

  var sql =

   "INSERT INTO WU_SOURCE_RECORDS VALUES (:SOURCE_RECORD_ID, :DWR_SOURCE_ID, :HISTORY_YEAR, :JAN_ACFT, :FEB_ACFT, :MAR_ACFT, :APR_ACFT, :MAY_ACFT, :JUN_ACFT, :JUL_ACFT, :AUG_ACFT, :SEP_ACFT, :OCT_ACFT, :NOV_ACFT, :DEC_ACFT, :ANNUAL_ACFT, :MEASURE_UNITS)";


  var binds = [

  {

  SOURCE_RECORD_ID: 123456,

  DWR_SOURCE_ID: 987456,

  HISTORY_YEAR: 1999,

  JAN_ACFT: 1,

  FEB_ACFT: 4,

  MAR_ACFT: 2,

  APR_ACFT: 6,

  MAY_ACFT: 1,

  JUN_ACFT: 3,

  JUL_ACFT: 4,

  AUG_ACFT: 0,

  SEP_ACFT: 0,

  OCT_ACFT: 3,

  NOV_ACFT: 2,

  DEC_ACFT: 10,

  ANNUAL_ACFT: 143,

  MEASURE_UNITS: "acre feet"

  }

  ];


  var options = {

  autoCommit: true

   /*bindDefs: {

  a: { type: oracledb.NUMBER },

  b: { type: oracledb.STRING, maxSize: 15 }

  }*/

  };


  conn.execute(sql, binds, options, function(err, result) {

   console.log("in execute");

   console.log(sql, binds, options);

   if (err) {

   console.log(err);

   return cb(err, conn);

  } else {

   console.log("Result is:", result);

   return cb(null, conn);

  }

  });

};


async.waterfall([doconnect, doinsert], function(err, conn) {

  if (err) {

   console.error("In waterfall error cb: ==>", err, "<==");

  }

  if (conn) dorelease(conn);

});

Tagged:

Answers

  • danmcghan-Oracle
    danmcghan-Oracle Member Posts: 43
    edited September 2018

    If you look closely at your binds variable, you'll see you've set it to an array with a single element - an object. That variable should be either an array or an object, but in either case, the values should be scalar values. You probably just need to remove the square brackets so that the variable becomes an object.

Sign In or Register to comment.