Skip to content

Commit

Permalink
[CONJ-795] resultset.getRow() is now implemented for streaming result…
Browse files Browse the repository at this point in the history
…set with TYPE_FORWARD_ONLY type
  • Loading branch information
rusher committed Jun 22, 2020
1 parent 299dcac commit fbb4e9d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
Expand Up @@ -95,6 +95,7 @@ public class SelectResultSet implements ResultSet {
private int fetchSize;
private int resultSetScrollType;
private int rowPointer;
private int discardedRows = 0;
private ColumnLabelIndexer columnLabelIndexer;
private int lastRowPointer = -1;
private boolean isClosed;
Expand Down Expand Up @@ -344,6 +345,7 @@ private void nextStreamingValue() throws IOException, SQLException {

// if resultSet can be back to some previous value
if (resultSetScrollType == TYPE_FORWARD_ONLY) {
discardedRows += dataSize;
dataSize = 0;
}

Expand Down Expand Up @@ -773,7 +775,7 @@ public boolean last() throws SQLException {
public int getRow() throws SQLException {
checkClose();
if (streaming && resultSetScrollType == TYPE_FORWARD_ONLY) {
return 0;
return discardedRows + rowPointer + 1;
}
return rowPointer + 1;
}
Expand Down
23 changes: 20 additions & 3 deletions src/test/java/org/mariadb/jdbc/DriverTest.java
Expand Up @@ -882,12 +882,12 @@ public void testResultSetPositions() throws SQLException {

@Test
public void streamingResultSetPositions() throws SQLException {
sharedConnection
.createStatement()
.execute("INSERT INTO streamingressetpos VALUES (1), (2), (3), (4)");
Statement stmt =
sharedConnection.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
stmt.execute("TRUNCATE streamingressetpos");
stmt.execute("INSERT INTO streamingressetpos VALUES (1), (2), (3), (4)");

stmt.setFetchSize(Integer.MIN_VALUE);
ResultSet rs = stmt.executeQuery("SELECT * FROM streamingressetpos");
assertTrue(rs.absolute(2));
Expand All @@ -904,6 +904,23 @@ public void streamingResultSetPositions() throws SQLException {
assertEquals(2, rs.getRow());
}

@Test
public void streamingResultSetPositionsForward() throws SQLException {
Statement stmt =
sharedConnection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
stmt.execute("TRUNCATE streamingressetpos");
stmt.execute("INSERT INTO streamingressetpos VALUES (1), (2), (3), (4), (5), (6)");

stmt.setFetchSize(2);
ResultSet rs = stmt.executeQuery("SELECT * FROM streamingressetpos");
for (int i = 1; i <= 6; i++) {
assertTrue(rs.next());
assertEquals(i, rs.getRow());
}
assertFalse(rs.next());
assertEquals(7, rs.getRow());
}

@Test(expected = SQLException.class)
public void findColumnTest() throws SQLException {
ResultSet rs = sharedConnection.createStatement().executeQuery("select 1 as 'hej'");
Expand Down

0 comments on commit fbb4e9d

Please sign in to comment.