|
1 | | -package com.softwareverde.database.row; |
| 1 | +package com.softwareverde.database.row.jdbc; |
2 | 2 |
|
3 | 3 | import com.softwareverde.database.DatabaseException; |
4 | 4 | import com.softwareverde.database.query.parameter.TypedParameter; |
| 5 | +import com.softwareverde.database.row.RowFactory; |
5 | 6 |
|
6 | 7 | import java.sql.ResultSet; |
7 | 8 | import java.sql.ResultSetMetaData; |
@@ -62,20 +63,22 @@ public JdbcRow fromResultSet(final ResultSet resultSet) throws DatabaseException |
62 | 63 | final TypedParameter typedValue; |
63 | 64 | { |
64 | 65 | if (JdbcRowFactory.isWholeNumberType(sqlDataType)) { |
65 | | - final Long longValue = resultSet.getLong(columnIndex); |
66 | | - typedValue = new TypedParameter(longValue); |
| 66 | + final long longValue = resultSet.getLong(columnIndex); // NOTE: ResultSet::getLong returns 0L if null. Must use ResultSet::wasNull. |
| 67 | + final boolean wasNull = resultSet.wasNull(); |
| 68 | + typedValue = (wasNull ? TypedParameter.NULL : new TypedParameter(longValue)); |
67 | 69 | } |
68 | 70 | else if (JdbcRowFactory.isBinaryType(sqlDataType)) { |
69 | 71 | final byte[] bytes = resultSet.getBytes(columnIndex); |
70 | | - typedValue = new TypedParameter(bytes); |
| 72 | + typedValue = ((bytes == null) ? TypedParameter.NULL : new TypedParameter(bytes)); |
71 | 73 | } |
72 | 74 | else if (JdbcRowFactory.isFloatingPointNumberType(sqlDataType)) { |
73 | | - final Double doubleValue = resultSet.getDouble(columnIndex); |
74 | | - typedValue = new TypedParameter(doubleValue); |
| 75 | + final double doubleValue = resultSet.getDouble(columnIndex); // NOTE: ResultSet::getDouble returns 0D if null. Must use ResultSet::wasNull. |
| 76 | + final boolean wasNull = resultSet.wasNull(); |
| 77 | + typedValue = (wasNull ? TypedParameter.NULL : new TypedParameter(doubleValue)); |
75 | 78 | } |
76 | 79 | else { |
77 | 80 | final String stringValue = resultSet.getString(columnIndex); |
78 | | - typedValue = new TypedParameter(stringValue); |
| 81 | + typedValue = ((stringValue == null) ? TypedParameter.NULL : new TypedParameter(stringValue)); |
79 | 82 | } |
80 | 83 | } |
81 | 84 |
|
|
0 commit comments