How to insert a null value?

Issue #22 resolved
Kerim Gueney created an issue

I have a database table that has nullable columns and I want to multiple rows in one go. The data contains null values in various places. As in, I cannot just leave out an entire column in my insert statement but rather need an explicit way to insert null.

Is that currently possible? If yes, how would I do that?

Comments (5)

  1. Jesse G

    Looking at dbstmt.cc, I see:

        else if(bindIndicator == 3) { //Parameter is NULL
          SQLINTEGER nullLen = SQL_NULL_DATA;
          DEBUG("SQLBindParameter [%d] = NULL \n", i + 1)
          rc = SQLBindParameter(obj->stmth, i + 1, SQL_PARAM_INPUT, SQL_C_DEFAULT, dataType, paramSize, decDigits, buf, 0, &nullLen);
        }
    

    So, I'd expect passing a '3' in as the bind indicator (instead of a 1 for character, 2 for numeric) would do the trick. @KerimG, can you verify?

    If so, we should define and document const values for the possible bind indicators or 0, 1, 2, and 3.

  2. mengxumx Account Deactivated

    Yes, indicator 3 tells idb-connector the parameter is null -->

    [null, db.SQL_PARAM_INPUT, 3]

    This is the old way to set the data type, but from v1.0.9, it can automatically detect the data types. Considering compatibility, I still keep the indicator 0(CLOB), 1(null-terminated-string), 2(integer), 3(null) and added two new types 4(decimal), 5(boolean) --

    https://bitbucket.org/litmis/nodejs-idb-connector/src/318f12eecda1120839054d76b805a927cd172c20/src/db2ia/dbstmt.cc#lines-707

  3. Log in to comment