Skip to content

Numeric overflow incorrectly handled in thick mode #1659

@mrfitz42

Description

@mrfitz42
  1. What versions are you using?

    database version: Oracle 19c Enterprise edition version 19.21.0.0.0

    process.platform: 'linux'
    process.version: 'v20.11.0'
    process.arch: 'x64'
    require('oracledb').versionString: '6.4.0'
    require('oracledb').oracleClientVersionString: undefined

  2. Is it an error or a hang or a crash? No

  3. What error(s) or behavior you are seeing?

    Do not get expected ORA-01426 errors in thick mode. Do see NJS-115 errors in thin mode.
    CREATE TABLE no_example (id NUMBER, float64_1 NUMBER, float64_2 NUMBER)

Running in thick mode
binds: [ 101, 1e+25, -1e+25 ]  ,result: 1
binds: [ 102, 1.7976931348623157e+308, -1.7976931348623157e+308 ]  ,result: 1
binds: [ 103, -1.7976931348623157e+308, 1.7976931348623157e+308 ]  ,result: 1
Query results: 
[
  [ 101, 9.999999999999999e+24, -9.999999999999999e+24 ],
  [ 102, 1.0000000000000001e+126, 0 ],
  [ 103, 0, 1.0000000000000001e+126 ]
]

Running in thin mode
binds: [ 101, 1e+25, -1e+25 ]  ,result: 1
binds: [ 102, 1.7976931348623157e+308, -1.7976931348623157e+308 ]  ,result: Error: NJS-115: value cannot be represented as an Oracle Database number
binds: [ 103, -1.7976931348623157e+308, 1.7976931348623157e+308 ]  ,result: Error: NJS-115: value cannot be represented as an Oracle Database number
Query results: 
[ [ 101, 1e+25, -1e+25 ] ]
  1. Include a runnable Node.js script that shows the problem.
// based on examples/example.js
const oracledb = require('oracledb');

// Optionally run in node-oracledb Thick mode
if (process.env.NODE_ORACLEDB_DRIVER_MODE === 'thick') {
  oracledb.initOracleClient();  // enable node-oracledb Thick mode
}

console.log(oracledb.thin ? 'Running in thin mode' : 'Running in thick mode');

async function run() {
  var self = this;
  let connection;
  try {

    let sql, binds, options, result;

    connection = await oracledb.getConnection({
      user: process.env.NODE_ORACLEDB_USER,
      password: process.env.NODE_ORACLEDB_PASSWORD,
      connectString: process.env.NODE_ORACLEDB_CONNECTIONSTRING,
    });

    const stmts = [
      `DROP TABLE no_example`,
      `CREATE TABLE no_example (id NUMBER, float64_1 NUMBER, float64_2 NUMBER)`
    ];

    for (const s of stmts) {
      try {
        await connection.execute(s);
      } catch (e) {
        if (e.errorNum != 942) {
          console.error(e);
        }
      }
    }

    sql = `INSERT INTO no_example VALUES (:1, :2, :3)`;
    binds = [
      [101, 1.0e25, -1.0e25 ],
      [102, Number.MAX_VALUE, -Number.MAX_VALUE ],
      [103, -Number.MAX_VALUE, Number.MAX_VALUE ]
    ];

    for (const b of binds) {
      try {
        result = await connection.execute(sql, b, {autoCommit: true});
        console.log("binds:", b, " ,result:", result.rowsAffected);
      } catch (e) {
        console.log("binds:", b, " ,result:", e.toString());
      }
    }

    sql = `SELECT * FROM no_example`;
    result = await connection.execute(sql, {}, {});

    console.log("Query results: ");
    console.log(result.rows);

  } catch (err) {
    console.error(err);
  } finally {
    if (connection) {
      try {
        await connection.close();
      } catch (err) {
        console.error(err);
      }
    }
  }
}

run();

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions