Skip to content

Commit

Permalink
[CONJ-282] Handling YEARs with binary prepareStatement
Browse files Browse the repository at this point in the history
  • Loading branch information
rusher committed Apr 19, 2016
1 parent d46dedc commit 2dca31e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -39,7 +39,7 @@ Development snapshot are available on sonatype nexus repository
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>1.5.0-SNAPSHOT</version>
<version>1.4.3-SNAPSHOT</version>
</dependency>
</dependencies>
```
Expand Down
6 changes: 6 additions & 0 deletions documentation/Changelog.md
@@ -1,10 +1,16 @@
# Changelog

* [1.4.3](#1.4.3)
* [1.4.2](#1.4.2)
* [1.4.1](#1.4.1)
* [1.4.0](#1.4.0)

---
## 1.4.3
Not released
* [CONJ-282] Handling YEARs with binary prepareStatement
* [CONJ-278] Improve prepared statement on failover

## 1.4.2
Released on 08 april 2016
* [CONJ-275] Streaming result without result throw "Current position is before the first row"
Expand Down
Expand Up @@ -3261,18 +3261,27 @@ private Date binaryDate(byte[] rawBytes, ColumnInformation columnInfo, Calendar
if (rawBytes.length == 0) {
return null;
}
int year;
int month;
int day;

year = ((rawBytes[0] & 0xff) | (rawBytes[1] & 0xff) << 8);
month = rawBytes[2];
day = rawBytes[3];
int year = ((rawBytes[0] & 0xff) | (rawBytes[1] & 0xff) << 8);

if (rawBytes.length == 2 && columnInfo.getLength() == 2) {
//YEAR(2) - deprecated
if (year <= 69) {
year += 2000;
} else {
year += 1900;
}
}

int month = 1;
int day = 1;

if (rawBytes.length >= 4) {
month = rawBytes[2];
day = rawBytes[3];
}

Calendar calendar = Calendar.getInstance();
/*if (!options.useLegacyDatetimeCode) {
c = cal;
}*/

Date dt;
synchronized (calendar) {
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/org/mariadb/jdbc/DateTest.java
Expand Up @@ -149,10 +149,21 @@ public void yearTest() throws SQLException {
Date.valueOf("2155-01-01")};
Date[] data2 = new Date[]{null, Date.valueOf("1970-01-01"), Date.valueOf("2000-01-01"),
Date.valueOf("2069-01-01")};
checkDateResult(data1, data2, rs);

//CONJ-282
PreparedStatement preparedStatement = sharedConnection.prepareStatement("SELECT * FROM yeartest");
rs = preparedStatement.executeQuery();
checkDateResult(data1, data2, rs);
}

private void checkDateResult(Date[] data1, Date[] data2, ResultSet rs) throws SQLException {
int count = 0;
while (rs.next()) {
assertEquals(data1[count], rs.getObject(1));
assertEquals(data2[count], rs.getObject(2));
assertEquals(data1[count], rs.getDate(1));
assertEquals(data2[count], rs.getDate(2));
count++;
}
}
Expand Down

0 comments on commit 2dca31e

Please sign in to comment.