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

How to insert a null value? #23

Closed
abmusse opened this issue Mar 8, 2018 · 2 comments
Closed

How to insert a null value? #23

abmusse opened this issue Mar 8, 2018 · 2 comments
Labels
bug Something isn't working major

Comments

@abmusse
Copy link
Member

abmusse commented Mar 8, 2018

Original report by Kerim Gueney (Bitbucket: KerimG, GitHub: KerimG).


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?

@abmusse
Copy link
Member Author

abmusse commented Mar 9, 2018

Original comment by Jesse G (Bitbucket: ThePrez, GitHub: ThePrez).


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.

@abmusse
Copy link
Member Author

abmusse commented May 2, 2018

Original comment by Xu Meng (Bitbucket: mengxumx, GitHub: dmabupt).


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

@abmusse abmusse closed this as completed Jun 21, 2018
@abmusse abmusse added major bug Something isn't working labels Jan 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working major
Projects
None yet
Development

No branches or pull requests

1 participant