Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] callProcedure returns parameter values of incorrect datatype #378

Open
richardm90 opened this issue Apr 12, 2024 · 3 comments
Open

Comments

@richardm90
Copy link

  • odbc Package Version: 2.4.8
  • ODBC Driver: unixODBC 2.3.9
  • Database Name: DB2 for i
  • Database Version: V7R5
  • Database OS: IBM i
  • Node.js Version: v18.20.2
  • Node.js OS: IBM i

When using callProcedure I'm finding the returned results don't respect the datatype of the procedure parameters but instead appear to respect the datatype of the Node.js fields.

For example, if I create the following procedure.

DROP PROCEDURE RMTEMP.MY_PROC ;

CREATE PROCEDURE RMTEMP.MY_PROC (
  INOUT PARAM1 DECIMAL(11,2) ,
  INOUT PARAM2 DECIMAL(11,2) ,
  INOUT PARAM3 DECIMAL(11,2) ,
  INOUT PARAM4 DECIMAL(11,2)
)
BEGIN
  SET PARAM1 = 123.45;
  SET PARAM2 = 123.45;
  SET PARAM3 = 123.45;
  SET PARAM4 = 123.45;
END;

-- CALL RMTEMP.MY_PROC(99.99, 0, '99.99', null);

With the following Node.js code.

const odbc = require('odbc');

odbc.connect('DSN=MYIBMI', (error, connection) => {
  if (error) { throw error; }

  let param1=99.99;
  let param2=0;
  let param3='99.99';
  let param4=null;

  connection.callProcedure(null, 'RMTEMP', 'MY_PROC', [param1, param2, param3, param4], (error, result) => {
    if (error) { throw error; }

    connection.close();
    console.log(result);
  });
});

When I call this from Node I'm expecting all four parameters to have a return value of 123.45 (as numbers) but instead I get this. Of particular concern is the second parameter, which is returned as an integer, though I would expect all values to be returned as numbers rather than strings.

[
  statement: '{ CALL RMTEMP.MY_PROC (?,?,?,?) }',
  parameters: [ 123.45, 123, '123.45', '123.45' ],
  return: undefined,
  count: 0,
  columns: []
]

If I change the procedure to all OUT parameters I get a different result.

DROP PROCEDURE RMTEMP.MY_PROC ;

CREATE PROCEDURE RMTEMP.MY_PROC (
  OUT PARAM1 DECIMAL(11,2) ,
  OUT PARAM2 DECIMAL(11,2) ,
  OUT PARAM3 DECIMAL(11,2) ,
  OUT PARAM4 DECIMAL(11,2)
)
BEGIN
  SET PARAM1 = 123.45;
  SET PARAM2 = 123.45;
  SET PARAM3 = 123.45;
  SET PARAM4 = 123.45;
END;

Running the same Node.js code I get the following. At least I'm getting the correct values but all of the parameters are returned as strings rather than numbers.

[
  statement: '{ CALL RMTEMP.MY_PROC (?,?,?,?) }',
  parameters: [ '123.45', '123.45', '123.45', '123.45' ],
  return: undefined,
  count: 0,
  columns: []
]
Copy link

stale bot commented Jul 12, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale This issue hasn't seen any interaction in 30 days. label Jul 12, 2024
@kansasturnpike
Copy link

I'm seeing a similar issue when using stored procedures. However, have a StoredProceudre with a column of INOUT DECIMAL. The expected value is 2.50, but what I get back is 2.

@stale stale bot removed the stale This issue hasn't seen any interaction in 30 days. label Jul 25, 2024
@kansasturnpike
Copy link

@markdirish Any idea what's going on?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants