Skip to content

null check for all DB type in bindValuesInBulkInsert #16

@florianmski

Description

@florianmski

Hi,

First of all, thanks for this awesome tool ;)
I think we should do a null check in bindValuesInBulkInsert for every DB type, not only String.
Because as stated in the documentation for getAsLong for instance:

Returns
the Long value, or null if the value is missing or cannot be converted

In my case, I do not set a value in every column when inserting new rows using a bulkInsert and it yield a NPE.
I think there will be a special case for the _id column. If we haven't set a value for _id we shouldn't set a default one and instead let the system auto_increment this column.
Something like:

Long longValue = values.getAsLong(Columns.ID.getName());
if(longValue != null)
    stmt.bindLong(i++, longValue);
else
    i++;

Or, more compact

Long longValue = values.getAsLong(Columns.ID.getName());
if(longValue != null)
    stmt.bindLong(i, longValue);
i++;

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions