Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[CONJ-514] ResultSet method wasNull() always return true after a call…
… on a "null-date" field binary protocol handling
  • Loading branch information
rusher committed Aug 30, 2017
1 parent 0932c58 commit 4fbc42b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Expand Up @@ -1051,9 +1051,12 @@ private String getInternalString(ColumnInformation columnInfo, Calendar cal) thr
if (isBinaryEncoded) {
Date date = getInternalDate(columnInfo, cal);
if (date == null) {
//specific for "zero-date", getString will return "zero-date" value -> wasNull() must then return false
lastValueNull ^= BIT_LAST_ZERO_DATE;
return new String(row.buf, row.pos, row.length, StandardCharsets.UTF_8);
if (!isBinaryEncoded) {
//specific for "zero-date", getString will return "zero-date" value -> wasNull() must then return false
lastValueNull ^= BIT_LAST_ZERO_DATE;
return new String(row.buf, row.pos, row.length, StandardCharsets.UTF_8);
}
return null;
}
return date.toString();
}
Expand All @@ -1071,9 +1074,12 @@ private String getInternalString(ColumnInformation columnInfo, Calendar cal) thr
case DATETIME:
Timestamp timestamp = getInternalTimestamp(columnInfo, cal);
if (timestamp == null) {
//specific for "zero-date", getString will return "zero-date" value -> wasNull() must then return false
lastValueNull ^= BIT_LAST_ZERO_DATE;
return new String(row.buf, row.pos, row.length, StandardCharsets.UTF_8);
if (!isBinaryEncoded) {
//specific for "zero-date", getString will return "zero-date" value -> wasNull() must then return false
lastValueNull ^= BIT_LAST_ZERO_DATE;
return new String(row.buf, row.pos, row.length, StandardCharsets.UTF_8);
}
return null;
}
return timestamp.toString();
case DECIMAL:
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/org/mariadb/jdbc/DateTest.java
Expand Up @@ -583,10 +583,14 @@ public void nullDateString() throws Throwable {
assertTrue(rs.next());
if (sharedUsePrepare()) {
assertNull(rs.getString(1));
assertTrue(rs.wasNull());
assertNull(rs.getDate(1));
assertTrue(rs.wasNull());
} else {
assertEquals("0000-00-00", rs.getString(1));
assertFalse(rs.wasNull());
assertNull(rs.getDate(1));
assertTrue(rs.wasNull());
}
} catch (SQLDataException sqldataException) {
//'0000-00-00' doesn't work anymore on mysql 5.7.
Expand Down Expand Up @@ -646,8 +650,10 @@ public void getZeroDateString() throws SQLException {
assertEquals(null, resultSet.getDate(1));
if (sharedUsePrepare()) {
assertEquals(null, resultSet.getString(1));
assertTrue(resultSet.wasNull());
} else {
assertTrue(resultSet.getString(1).contains("0000-00-00 00:00:00"));
assertFalse(resultSet.wasNull());
}
}

Expand Down

0 comments on commit 4fbc42b

Please sign in to comment.