oracle / node-oracledb

Oracle Database driver for Node.js maintained by Oracle Corp.
http://oracle.github.io/node-oracledb/
Other
2.25k stars 1.07k forks source link

The Return query of a sum () function, after being performed via node, displays a different value. #1161

Closed VinnyLima closed 4 years ago

VinnyLima commented 4 years ago

I am developing an APIrest, but when node executes a query through oracledb.execute () the function returns me a different value than when I run in SQLdeveloper. follow examples

This is my Model

const oracledb = require('oracledb');
const dbConfig = require('../config/database.js');

async function initialize() {
  const pool = await oracledb.createPool(dbConfig.hrPool);
}
module.exports.initialize = initialize;

async function close() {
    await oracledb.getPool().close();
  }   
module.exports.close = close;

 const baseQuery3 = 'select
sum(vlrnota) as valor_notas
--dtfatur as  datafaturajmento
from tgfcab
where  dtfatur >= to_date('01/09/2019', 'DD/MM/YYYY')
and codtipoper  in (1100, 1109, 1102, 1103, 1105) ;

async function find(context) {
    let query = baseQuery3;
    const binds = {};

    if (context.codparc) {
        binds.codparc_id = context.codparc;

        query += '\nand codparc  = :codparc_id ';
    }

    const result = await database.simpleExecute(query, binds);

    return result.rows;
}

module.exports.find = find;

This is my Controller

async function get(req, res, next) {
    try {
        const context = {};

        //context.id = parseInt(req.params.id, 10);

        const rows = await validadorFatu.find(context);

        if (req.params.id) {
            if (rows.length === 1) {
                res.status(200).json(rows[0]);
            } else {
                res.status(404).end();
            }
        } else {
            res.status(200).json(rows);
        }
    } catch (err) {
        next(err);
    }
}

module.exports.get = get;

results in api Node.js image

Results in consulting SQLdeveloper image

Thanks for help me!

dmcghan commented 4 years ago

At first glance, the queries look the same. This leads me to believe you're hitting on two different databases. Please look very closely at the connection information for both SQL Developer and Node.js.

VinnyLima commented 4 years ago

@dmcghan Many thanks for the light that! You were correct. with Node was searching the test base and Sqldeveloper in production.

Thanks!!!!