Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[CONJ-837] prepared statement cache leak on Resultset CONCUR_UPDATABL…
…E concurrency
  • Loading branch information
rusher committed Nov 6, 2020
1 parent 15af61a commit efb1940
Showing 1 changed file with 31 additions and 26 deletions.
Expand Up @@ -1119,39 +1119,39 @@ public void insertRow() throws SQLException {
insertSql.append(" RETURNING ").append(returningClause);
}

BasePrepareStatement insertPreparedStatement =
try (BasePrepareStatement insertPreparedStatement =
(row instanceof BinaryRowProtocol)
? connection.serverPrepareStatement(insertSql.toString())
: connection.clientPrepareStatement(insertSql.toString());
: connection.clientPrepareStatement(insertSql.toString())) {

for (Map.Entry<Integer, ParameterHolder> entry : paramMap.entrySet()) {
insertPreparedStatement.setParameter(entry.getKey(), entry.getValue());
}

ResultSet insertRs = insertPreparedStatement.executeQuery();
if (connection.isServerMariaDb() && connection.versionGreaterOrEqual(10, 5, 1)) {
if (insertRs.next()) {
byte[] rowByte = ((SelectResultSet) insertRs).getCurrentRowData();
addRowData(rowByte);
for (Map.Entry<Integer, ParameterHolder> entry : paramMap.entrySet()) {
insertPreparedStatement.setParameter(entry.getKey(), entry.getValue());
}
} else if (hasGeneratedPrimaryFields) {
// primary is auto_increment (only one field)
ResultSet rsKey = insertPreparedStatement.getGeneratedKeys();
if (rsKey.next()) {

prepareRefreshStmt();
refreshPreparedStatement.setObject(1, rsKey.getObject(1), generatedSqlType);
SelectResultSet rs = (SelectResultSet) refreshPreparedStatement.executeQuery();

// update row data only if not deleted externally
if (rs.next()) {
addRowData(rs.getCurrentRowData());

ResultSet insertRs = insertPreparedStatement.executeQuery();
if (connection.isServerMariaDb() && connection.versionGreaterOrEqual(10, 5, 1)) {
if (insertRs.next()) {
byte[] rowByte = ((SelectResultSet) insertRs).getCurrentRowData();
addRowData(rowByte);
}
} else if (hasGeneratedPrimaryFields) {
// primary is auto_increment (only one field)
ResultSet rsKey = insertPreparedStatement.getGeneratedKeys();
if (rsKey.next()) {

prepareRefreshStmt();
refreshPreparedStatement.setObject(1, rsKey.getObject(1), generatedSqlType);
SelectResultSet rs = (SelectResultSet) refreshPreparedStatement.executeQuery();

// update row data only if not deleted externally
if (rs.next()) {
addRowData(rs.getCurrentRowData());
}
}
} else {
addRowData(refreshRawData());
}
} else {
addRowData(refreshRawData());
}

Arrays.fill(parameterHolders, null);
}
}
Expand Down Expand Up @@ -1468,4 +1468,9 @@ public boolean previous() throws SQLException {
}
return super.previous();
}

public void close() throws SQLException {
refreshPreparedStatement.close();
super.close();
}
}

0 comments on commit efb1940

Please sign in to comment.