Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading null values with CsvDataFileLoader in dbunit

Tags:

dbunit

We are using the CsvDataFileLoader to load in our reference data like so:

new InsertIdentityOperation(DatabaseOperation.CLEAN_INSERT)
            .execute(connection,
                    new CsvDataFileLoader().load("/sql/ReferenceData/"));

Is there anyway to put null values into a csv that is loaded into our db.

I don't think there is, I would imagine that , null and NULL would all get interpreted as their string values.

Has anyone managed to do this or know of a work around for this problem?

like image 216
mark-cs Avatar asked Jan 01 '26 13:01

mark-cs


1 Answers

CsvDataFileLoader uses CsvURLProducer to load and parse the data.

In that class on Line 145 for dbunit 2.4.8 you see the following:

if (CsvDataSetWriter.NULL.equals(row[col])) {
    row[col] = null;
}

CsvDataSetWriter.NULL contains the string "null" therefore your assumption that null would get interpreted as a string value appears to be incorrect and you should use this in your CSV.

Of course this means that you can't have the string "null" in your fields but I'm sure this isn't often required.

like image 59
Dolbz Avatar answered Jan 06 '26 12:01

Dolbz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!