Skip to content

Commit

Permalink
Fix bug in date conversion, update select tests to verify fixes work,
Browse files Browse the repository at this point in the history
push version to 0.4 and update Readme with release info
  • Loading branch information
cvitter committed Jun 14, 2016
1 parent b3d9e3e commit 18da974
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
3 changes: 3 additions & 0 deletions riakts.jdbc.driver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ A copy of the current version of the compiled JAR file is located in https://git
**Important Note** remove **-DskipTests** if you want the JUnit tests to execute during the build.

# Release Notes
Version 0.4
- Corrected bug in dateStringToEpoch, changed method to dateStringMMddyyyyHHmmssSSToEpoch for clarity

Version 0.3:
- Fix riakts.jdbc.driver.Driver to register with DriverManager so that third party apps can use the driver
- Create an external test project (riakts.jdbc.driver.test) to test that the driver works with third party apps
Expand Down
2 changes: 1 addition & 1 deletion riakts.jdbc.driver/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.basho</groupId>
<artifactId>riakts.jdbc.driver</artifactId>
<version>0.3</version>
<version>0.4</version>
<name>Riak TS JDBC Driver</name>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ public static boolean validateRiakProperties(Properties info) {
* @return
* @throws ParseException
*/
public static long dateStringToEpoch(String dateString) throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss.SS");
public static long dateStringMMddyyyyHHmmssSSToEpoch(String dateString) throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss.SS");
Date date = sdf.parse(dateString);
return date.getTime();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public void testSqlInsertData() throws SQLException, ParseException {
String sqlStatement = "INSERT INTO jdbcDriverTest " +
"(name, age, joined, weight) " +
"VALUES " +
"('Craig', 92, " + Utility.dateStringToEpoch(timeStamp) + ", 202.5);";
"('Craig', 92, " + Utility.dateStringMMddyyyyHHmmssSSToEpoch(timeStamp) + ", 202.5);";

Statement statement = conn.createStatement();
int result = statement.executeUpdate(sqlStatement);
Expand All @@ -152,7 +152,7 @@ public void testSqlInsertMultipleRows() throws SQLException, ParseException {
String sqlStatement = "INSERT INTO jdbcDriverTest " +
"(name, age, joined, weight) " +
"VALUES " +
"('" + person[0] + "', " + person[1] + ", " + Utility.dateStringToEpoch(person[2]) +
"('" + person[0] + "', " + person[1] + ", " + Utility.dateStringMMddyyyyHHmmssSSToEpoch(person[2]) +
", " + person[3] + ");";
//System.out.println(sqlStatement);
Statement statement = conn.createStatement();
Expand All @@ -166,25 +166,25 @@ public void testSqlInsertMultipleRows() throws SQLException, ParseException {
@Test
public void testSqlSelect() throws SQLException, ParseException {
// Start and end date to search on
String startDateStr = "06/06/2016 0:00:00.00";
String endDateStr = "06/06/2016 23:59:59.59";
String startDateStr = "06/01/2016 0:00:00.00";
String endDateStr = "06/11/2016 23:59:59.59";

String sqlStatement = "SELECT * FROM jdbcDriverTest WHERE joined >= " +
Utility.dateStringToEpoch(startDateStr) +
" AND joined <= " + Utility.dateStringToEpoch(endDateStr) + ";";
//System.out.println(sqlStatement);
Utility.dateStringMMddyyyyHHmmssSSToEpoch(startDateStr) +
" AND joined <= " + Utility.dateStringMMddyyyyHHmmssSSToEpoch(endDateStr) + ";";
System.out.println(sqlStatement);

Statement statement = conn.createStatement();
ResultSet rs = statement.executeQuery(sqlStatement);
Assert.assertTrue(rs != null);

// Print out ResultSet for demonstraiton purposes only, commented out for normal test runs
// if (rs != null) {
// while (rs.next()) {
// System.out.println( rs.getString("name") + " | " + rs.getLong("age") +
// " | " + rs.getTimestamp("joined") + " | " + rs.getDouble("weight"));
// }
// }
// Print out ResultSet for demonstration purposes only, commented out for normal test runs
if (rs != null) {
while (rs.next()) {
System.out.println( rs.getString("name") + " | " + rs.getLong("age") +
" | " + rs.getTimestamp("joined") + " | " + rs.getDouble("weight"));
}
}
rs.close();
}

Expand All @@ -201,8 +201,8 @@ public void testRowPosition() throws ParseException, SQLException {
String endDateStr = "06/06/2016 23:59:59.59";

String sqlStatement = "SELECT * FROM jdbcDriverTest WHERE joined >= " +
Utility.dateStringToEpoch(startDateStr) +
" AND joined <= " + Utility.dateStringToEpoch(endDateStr) + ";";
Utility.dateStringMMddyyyyHHmmssSSToEpoch(startDateStr) +
" AND joined <= " + Utility.dateStringMMddyyyyHHmmssSSToEpoch(endDateStr) + ";";
//System.out.println(sqlStatement);

Statement statement = conn.createStatement();
Expand Down

0 comments on commit 18da974

Please sign in to comment.