Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[CONJ-271] correction of resultset return value of first/last when re…
…sultset has no result.
  • Loading branch information
rusher committed Mar 30, 2016
1 parent f9a06a3 commit 318ca24
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Expand Up @@ -637,7 +637,7 @@ public boolean first() throws SQLException {
throw new SQLException("Invalid operation for result set type TYPE_FORWARD_ONLY");
} else {
rowPointer = 0;
return true;
return resultSet.size() > 0;
}
}

Expand All @@ -648,7 +648,7 @@ public boolean last() throws SQLException {
throw new SQLException("Invalid operation for result set type TYPE_FORWARD_ONLY");
} else {
rowPointer = resultSet.size() - 1;
return true;
return rowPointer > 0;
}
}

Expand Down
14 changes: 14 additions & 0 deletions src/test/java/org/mariadb/jdbc/ResultSetTest.java
Expand Up @@ -58,6 +58,7 @@ public void isFirstZeroRowsTest() throws SQLException {
assertFalse(resultSet.isFirst());
assertFalse(resultSet.next()); //No more rows after this
assertFalse(resultSet.isFirst()); // connectorj compatibility
assertFalse(resultSet.first());
resultSet.close();
try {
resultSet.isFirst();
Expand All @@ -79,6 +80,8 @@ public void isFirstTwoRowsTest() throws SQLException {
assertFalse(resultSet.isFirst());
resultSet.next(); //No more rows after this
assertFalse(resultSet.isFirst());
assertTrue(resultSet.first());
assertEquals(1, resultSet.getInt(1));
resultSet.close();
try {
resultSet.isFirst();
Expand All @@ -96,6 +99,7 @@ public void isLastZeroRowsTest() throws SQLException {
assertFalse(resultSet.isLast()); // connectorj compatibility
resultSet.next(); //No more rows after this
assertFalse(resultSet.isLast());
assertFalse(resultSet.last());
resultSet.close();
try {
resultSet.isLast();
Expand All @@ -118,6 +122,8 @@ public void isLastTwoRowsTest() throws SQLException {
assertTrue(resultSet.isLast());
resultSet.next(); //No more rows after this
assertFalse(resultSet.isLast());
assertTrue(resultSet.last());
assertEquals(2, resultSet.getInt(1));
resultSet.close();
try {
resultSet.isLast();
Expand Down Expand Up @@ -156,6 +162,8 @@ public void isAfterLastTwoRowsTest() throws SQLException {
assertFalse(resultSet.isAfterLast());
resultSet.next(); //No more rows after this
assertTrue(resultSet.isAfterLast());
assertTrue(resultSet.last());
assertEquals(2, resultSet.getInt(1));
resultSet.close();
try {
resultSet.isAfterLast();
Expand All @@ -172,10 +180,16 @@ public void previousTest() throws SQLException {
ResultSet rs = sharedConnection.createStatement().executeQuery("SELECT * FROM result_set_test");
assertFalse(rs.previous());
assertTrue(rs.next());
assertEquals(1, rs.getInt(1));
assertFalse(rs.previous());
assertTrue(rs.next());
assertEquals(1, rs.getInt(1));
assertTrue(rs.next());
assertEquals(2, rs.getInt(1));
assertTrue(rs.previous());
assertEquals(1, rs.getInt(1));
assertTrue(rs.last());
assertEquals(2, rs.getInt(1));
rs.close();
}

Expand Down

0 comments on commit 318ca24

Please sign in to comment.