Skip to content

Commit

Permalink
JDBC-474 Fix ClassCastException on concurrency downgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
mrotteveel committed Jan 19, 2017
1 parent b6d4b0a commit 53a7783
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/org/firebirdsql/jdbc/AbstractResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public AbstractResultSet(FBConnection connection,
rowUpdater = new FBRowUpdater(connection, rowDescriptor, this, cached, listener);
} catch (FBResultSetNotUpdatableException ex) {
fbStatement.addWarning(FbExceptionBuilder
.forException(JaybirdErrorCodes.jb_concurrencyResetReadOnlyReasonNotUpdatable)
.forWarning(JaybirdErrorCodes.jb_concurrencyResetReadOnlyReasonNotUpdatable)
.toFlatSQLException(SQLWarning.class));
rsConcurrency = ResultSet.CONCUR_READ_ONLY;
}
Expand Down
21 changes: 21 additions & 0 deletions src/test/org/firebirdsql/jdbc/TestFBResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.firebirdsql.common.FBJUnit4TestBase;
import org.firebirdsql.gds.ISCConstants;
import org.firebirdsql.gds.JaybirdErrorCodes;
import org.junit.*;
import org.junit.rules.ExpectedException;

Expand All @@ -33,7 +34,10 @@
import static org.firebirdsql.common.DdlHelper.executeDDL;
import static org.firebirdsql.common.FBTestProperties.*;
import static org.firebirdsql.common.JdbcResourceHelper.closeQuietly;
import static org.firebirdsql.common.matchers.SQLExceptionMatchers.fbMessageStartsWith;
import static org.firebirdsql.common.matchers.SQLExceptionMatchers.sqlStateEquals;
import static org.hamcrest.CoreMatchers.allOf;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.*;

public class TestFBResultSet extends FBJUnit4TestBase {
Expand Down Expand Up @@ -788,6 +792,23 @@ public void testUpdatableResultSetNoPK() throws Exception {
}
}

@Test
public void testUpdatableStatementResultSetDowngradeToReadOnlyWhenQueryNotUpdatable() throws Exception {
executeCreateTable(connection, CREATE_TABLE_STATEMENT);
executeCreateTable(connection, CREATE_TABLE_STATEMENT2);

try (Statement stmt = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet rs = stmt.executeQuery("select * from test_table t1 left join test_table2 t2 on t1.id = t2.id")) {

SQLWarning warning = stmt.getWarnings();
assertThat(warning, allOf(
notNullValue(),
fbMessageStartsWith(JaybirdErrorCodes.jb_concurrencyResetReadOnlyReasonNotUpdatable)));

assertEquals("Expected downgrade to CONCUR_READ_ONLY", ResultSet.CONCUR_READ_ONLY, rs.getConcurrency());
}
}

@Test
public void testGetExecutionPlan() throws Exception {
executeCreateTable(connection, CREATE_TABLE_STATEMENT);
Expand Down

0 comments on commit 53a7783

Please sign in to comment.