Skip to content

Commit

Permalink
return a real row number from a result set in case of streaming excep…
Browse files Browse the repository at this point in the history
…t result sets of scrolling type TYPE_FORWARD_ONLY
  • Loading branch information
dmitriy.tseyler committed Feb 16, 2018
1 parent 3868199 commit 37de02c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Expand Up @@ -764,7 +764,7 @@ public boolean last() throws SQLException {
@Override
public int getRow() throws SQLException {
checkClose();
if (streaming) {
if (streaming && resultSetScrollType == TYPE_FORWARD_ONLY) {
return 0;
}
return rowPointer + 1;
Expand Down
21 changes: 21 additions & 0 deletions src/test/java/org/mariadb/jdbc/DriverTest.java
Expand Up @@ -96,6 +96,7 @@ public static void initClass() throws SQLException {
createTable("quotesPreparedStatements", "id int not null primary key auto_increment, a varchar(10) , "
+ "b varchar(10)");
createTable("ressetpos", "i int not null primary key", "engine=innodb");
createTable("streamingressetpos", "i int not null primary key", "engine=innodb");
createTable("streamingtest", "val varchar(20)");
createTable("testBlob2", "a blob");
createTable("testString2", "a varchar(10)");
Expand Down Expand Up @@ -692,6 +693,26 @@ public void testResultSetPositions() throws SQLException {
assertEquals(4, rs.getInt(1));
}

@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.setFetchSize(Integer.MIN_VALUE);
ResultSet rs = stmt.executeQuery("SELECT * FROM streamingressetpos");
assertTrue(rs.absolute(2));
assertEquals(2, rs.getRow());
assertTrue(rs.relative(-1));
assertEquals(1, rs.getRow());
rs.afterLast();
assertEquals(5, rs.getRow());
rs.beforeFirst();
assertEquals(0, rs.getRow());
assertTrue(rs.next());
assertEquals(1, rs.getRow());
assertTrue(rs.next());
assertEquals(2, 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 37de02c

Please sign in to comment.