Skip to content

Commit

Permalink
JDBC-304 Additional fix for PreparedStatement
Browse files Browse the repository at this point in the history
  • Loading branch information
mrotteveel committed Mar 30, 2013
1 parent 72ff1fd commit a7df803
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 8 deletions.
15 changes: 8 additions & 7 deletions src/main/org/firebirdsql/jdbc/AbstractPreparedStatement.java
Expand Up @@ -30,6 +30,7 @@

import org.firebirdsql.gds.*;
import org.firebirdsql.gds.impl.GDSHelper;
import org.firebirdsql.jdbc.AbstractStatement.CompletionReason;
import org.firebirdsql.jdbc.field.*;
import org.firebirdsql.jdbc.field.FBFlushableField.CachedObject;

Expand Down Expand Up @@ -141,15 +142,15 @@ protected AbstractPreparedStatement(GDSHelper c, String sql, int rsType,
}
}

public void completeStatement() throws SQLException {

if (!metaDataQuery)
closeResultSet(false);

if (!completed)
@Override
public void completeStatement(CompletionReason reason) throws SQLException {
if (!metaDataQuery) {
super.completeStatement(reason);
} else if (!completed) {
notifyStatementCompleted();
}
}

protected void notifyStatementCompleted(boolean success)
throws SQLException {
try {
Expand Down
43 changes: 42 additions & 1 deletion src/test/org/firebirdsql/jdbc/TestFBResultSet.java
Expand Up @@ -985,7 +985,7 @@ public void testGetExecutionPlan() throws Exception {
"", rs.getExecutionPlan());
}

public void testHoldability() throws Exception {
public void testHoldabilityStatement() throws Exception {
final int recordCount = 10;

PreparedStatement ps =
Expand Down Expand Up @@ -1025,6 +1025,47 @@ public void testHoldability() throws Exception {
closeQuietly(stmt2);
}
}

public void testHoldabilityPreparedStatement() throws Exception {
final int recordCount = 10;

PreparedStatement ps =
connection.prepareStatement(INSERT_INTO_TABLE_STATEMENT);

try {
for(int i = 0; i < recordCount; i++) {
ps.setInt(1, i);
ps.setInt(2, i);
ps.executeUpdate();
}
} finally {
ps.close();
}

PreparedStatement stmt = connection.prepareStatement(SELECT_TEST_TABLE, ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
Statement stmt2 = connection.createStatement();

try {
// execute first query
FirebirdResultSet rs = (FirebirdResultSet) stmt.executeQuery();

// now execute another query, causes commit in auto-commit mode
stmt2.executeQuery("SELECT * FROM rdb$database");

// now let's access the result set
int actualCount = 0;
assertEquals("Unexpected holdability", ResultSet.HOLD_CURSORS_OVER_COMMIT, rs.getHoldability());
while(rs.next()) {
rs.getString(1);
actualCount++;
}
assertEquals("Unexpected number of reads from holdable resultset", recordCount, actualCount);
} finally {
closeQuietly(stmt);
closeQuietly(stmt2);
}
}

public void testFetchSize() throws Exception {
final int FETCH_SIZE = 3;
Expand Down

0 comments on commit a7df803

Please sign in to comment.