IBM / nodejs-idb-connector

A JavaScript (Node.js) library for communicating with Db2 for IBM i, with support for queries, procedures, and much more. Uses traditional callback-style syntax
MIT License
37 stars 23 forks source link

Unable to bind null values using statement.bindParam() #75

Closed abmusse closed 5 years ago

abmusse commented 5 years ago

First reported by @KerimG here

using node v10.15.3 and idb-connector v1.1.10 errors occur while preparing an insert statement and binding null value: SQLSTATE=HY009 SQLCODE=-99999

Here are some steps to recreate the issue

Create Table and Insert Data/NULL

CREATE TABLE MYSCHEMA.SCORES(team VARCHAR(100) ALLOCATE(20), score INTEGER)

INSERT INTO MYSCHEMA.SCORES VALUES('Lakers', NULL)
INSERT INTO MYSCHEMA.SCORES VALUES('Bulls', 100)
INSERT INTO MYSCHEMA.SCORES VALUES('Suns', NULL)
INSERT INTO MYSCHEMA.SCORES VALUES('Knicks', 95)
INSERT INTO MYSCHEMA.SCORES(team) VALUES('Raptors')

image

Test

    const {dbconn, dbstmt, IN, NULL, CHAR} = require('idb-connector');

    const sql = 'INSERT INTO MYSCHEMA.SCORES VALUES(?,?)';
    const connection = new dbconn();
    connection.debug(true);
    connection.conn('*LOCAL');
    const statement = new dbstmt(connection);

    statement.prepare(sql, (error) => {
      if (error) {
        throw error;
      }
      statement.bindParam([['Warriors', IN, CHAR], [null, IN, NULL]], (error) => {
        if (error) {
          throw error;
        }
        statement.execute((error) => {  
          if (error) {
             throw error;
          }
          statement.close();
          connection.disconn();
          connection.close();
        });
      });
    });
Error: SQLBindParmeter FAILED
SQLSTATE=HY009 SQLCODE=-99999 Error occurred in SQL Call Level Interface

Looking up HY009:

image