Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[CONJ-226] '00:00:00' value on TIME correction with prepareStatement
  • Loading branch information
rusher committed Nov 30, 2015
1 parent fce8e4c commit 528fa17
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
Expand Up @@ -824,9 +824,6 @@ private Date binaryDate(Calendar cal) throws ParseException {
}

private Time binaryTime(Calendar cal) throws ParseException {
if (rawBytes.length == 0) {
return null;
}
switch (dataType) {
case TIMESTAMP:
case DATETIME:
Expand All @@ -844,9 +841,14 @@ private Time binaryTime(Calendar cal) throws ParseException {
if (options.useLegacyDatetimeCode) {
calendar.setLenient(false);
}
int hour = rawBytes[5];
int minutes = rawBytes[6];
int seconds = rawBytes[7];
int hour = 0;
int minutes = 0;
int seconds = 0;
if (rawBytes.length > 7) {
hour = rawBytes[5];
minutes = rawBytes[6];
seconds = rawBytes[7];
}
calendar.set(1970, 0, 1, hour, minutes, seconds);

int nanoseconds = 0;
Expand Down
17 changes: 17 additions & 0 deletions src/test/java/org/mariadb/jdbc/DatatypeTest.java
Expand Up @@ -40,6 +40,8 @@ public static void initClass() throws SQLException {
createTable("test_setobjectconv", "id int not null primary key auto_increment, v1 varchar(40), v2 varchar(40)");
createTable("blabla", "valsue varchar(20)");
createTable("TestBigIntType", "t1 bigint(20), t2 bigint(20), t3 bigint(20), t4 bigint(20)");
createTable("time_period", "ID int unsigned NOT NULL, START time NOT NULL, END time NOT NULL, PRIMARY KEY (ID)");

}

@Before
Expand Down Expand Up @@ -775,4 +777,19 @@ private void testBitResult(ResultSet rs) throws SQLException {
}
}

@Test
public void testNullTimePreparedStatement() throws Exception {
sharedConnection.createStatement().execute("insert into time_period(id, start, end) values(1, '00:00:00', '08:00:00');");
final String sql = "SELECT id, start, end FROM time_period WHERE id=?";
PreparedStatement preparedStatement = sharedConnection.prepareStatement(sql);
preparedStatement.setInt(1, 1);
try (ResultSet resultSet = preparedStatement.executeQuery()) {
if (resultSet.next()) {
Time timeStart = resultSet.getTime(2);
Time timeEnd = resultSet.getTime(3);
assertEquals(timeStart, new Time(0, 0, 0));
assertEquals(timeEnd, new Time(8, 0, 0));
}
}
}
}

0 comments on commit 528fa17

Please sign in to comment.