Skip to content

Commit

Permalink
JDBC-288 Backport basic fix (disallow use of execute methods acceptin…
Browse files Browse the repository at this point in the history
…g query string on PreparedStatement and PreparedStatement)
  • Loading branch information
mrotteveel committed Dec 8, 2012
1 parent 7ebe3e5 commit 2152962
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 28 deletions.
24 changes: 0 additions & 24 deletions src/main/org/firebirdsql/jdbc/AbstractCallableStatement.java
Expand Up @@ -1264,30 +1264,6 @@ public ResultSet getGeneratedKeys() throws SQLException {
throw new FBDriverNotCapableException();
}

public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
throw new FBDriverNotCapableException();
}

public int executeUpdate(String sql, int[] columnIndexes) throws SQLException {
throw new FBDriverNotCapableException();
}

public int executeUpdate(String sql, String[] columnNames) throws SQLException {
throw new FBDriverNotCapableException();
}

public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
throw new FBDriverNotCapableException();
}

public boolean execute(String sql, int[] columnIndexes) throws SQLException {
throw new FBDriverNotCapableException();
}

public boolean execute(String sql, String[] columnNames) throws SQLException {
throw new FBDriverNotCapableException();
}

/**
* Asserts if the current statement has data to return. It checks if the
* result set has a row with data.
Expand Down
54 changes: 54 additions & 0 deletions src/main/org/firebirdsql/jdbc/AbstractPreparedStatement.java
Expand Up @@ -43,6 +43,8 @@
*/
public abstract class AbstractPreparedStatement extends AbstractStatement implements
FirebirdPreparedStatement {

static final String METHOD_NOT_SUPPORTED = "This method is only supported on Statement and not supported on PreparedStatement and CallableStatement";

private boolean metaDataQuery;

Expand Down Expand Up @@ -1339,4 +1341,56 @@ public int getStatementType() throws FBSQLException {
public ParameterMetaData getParameterMetaData() throws SQLException {
return new FBParameterMetaData(fixedStmt.getInSqlda().sqlvar, gdsHelper);
}

// Methods not allowed to be used on PreparedStatement and CallableStatement

@Override
public ResultSet executeQuery(String sql) throws SQLException {
throw new FBSQLException(METHOD_NOT_SUPPORTED);
}

@Override
public int executeUpdate(String sql) throws SQLException {
throw new FBSQLException(METHOD_NOT_SUPPORTED);
}

@Override
public boolean execute(String sql) throws SQLException {
throw new FBSQLException(METHOD_NOT_SUPPORTED);
}

@Override
public void addBatch(String sql) throws SQLException {
throw new FBSQLException(METHOD_NOT_SUPPORTED);
}

@Override
public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
throw new FBSQLException(METHOD_NOT_SUPPORTED);
}

@Override
public int executeUpdate(String sql, int[] columnIndex) throws SQLException {
throw new FBSQLException(METHOD_NOT_SUPPORTED);
}

@Override
public int executeUpdate(String sql, String[] columnNames) throws SQLException {
throw new FBSQLException(METHOD_NOT_SUPPORTED);
}

@Override
public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
throw new FBSQLException(METHOD_NOT_SUPPORTED);
}

@Override
public boolean execute(String sql, int[] columnIndexes) throws SQLException {
throw new FBSQLException(METHOD_NOT_SUPPORTED);
}

@Override
public boolean execute(String sql, String[] columnNames) throws SQLException {
throw new FBSQLException(METHOD_NOT_SUPPORTED);
}
}
10 changes: 6 additions & 4 deletions src/test/org/firebirdsql/jdbc/TestFBPreparedStatement.java
Expand Up @@ -175,10 +175,12 @@ public void testMixedExecution() throws Throwable {
try {
ps.setInt(1, 100);
ps.execute();

ResultSet rs = ps.executeQuery("SELECT * FROM test_blob");
while (rs.next()) {
// nothing

try {
ps.executeQuery("SELECT * FROM test_blob");
fail("Calling executeQuery(String) on PreparedStatement should fail");
} catch (SQLException ex) {
// expected
}
} finally {
closeQuietly(ps);
Expand Down

0 comments on commit 2152962

Please sign in to comment.