rodhoward / node-sybase

23 stars 55 forks source link

Column excluded from the result if the value is `null` #25

Closed gkarthiks closed 3 years ago

gkarthiks commented 6 years ago

The column:value pair is ignored in the resulting JSON when any column of any row is null.

This makes inconsistency in the resulting JSON data. I would expect to return back null or empty value with the key as corresponding column_name.

liamray commented 4 years ago

Why rodhoward skips null values at all ?

BTW my forked version provides a columns parameter in the callback function. Also I've added a query2Csv() function => sybase-plus

rodhoward commented 3 years ago

So yep I'm not bothering to put null values into the row object. I think this fine though it doesn't lose you any information and this way you don't need to deal with "null" in javascript just undefined. which is nice..

for (int c = 1; c< colCount+1; c++)
{
    Object val = rs.getObject(c);
    if (val == null) continue;

    int dataType = meta.getColumnType(c);
    switch (dataType)
    {
        case SybaseDB.TYPE_TIME_STAMP:
        case SybaseDB.TYPE_DATE:
            String my8601formattedDate = df.format(new Date(rs.getTimestamp(c).getTime()));
            row.put(columns[c], my8601formattedDate);
            break;
        default:
            row.put(columns[c], rs.getObject(c));
    }
}
}