Skip to content

Commit

Permalink
Fix sonar issue on MySQLComStmtPrepareExecutor
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed Sep 23, 2023
1 parent 4a4eeab commit 1b20e31
Showing 1 changed file with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CopyOnWriteArrayList;
Expand Down Expand Up @@ -99,7 +98,7 @@ private void failedIfContainsMultiStatements() {

private Collection<DatabasePacket> createPackets(final SQLStatementContext sqlStatementContext, final int statementId, final MySQLServerPreparedStatement serverPreparedStatement) {
Collection<DatabasePacket> result = new LinkedList<>();
List<Projection> projections = getProjections(sqlStatementContext);
Collection<Projection> projections = getProjections(sqlStatementContext);
int parameterCount = sqlStatementContext.getSqlStatement().getParameterCount();
result.add(new MySQLComStmtPrepareOKPacket(statementId, projections.size(), parameterCount, 0));
int characterSet = connectionSession.getAttributeMap().attr(MySQLConstants.MYSQL_CHARACTER_SET_ATTRIBUTE_KEY).get().getId();
Expand All @@ -108,14 +107,14 @@ private Collection<DatabasePacket> createPackets(final SQLStatementContext sqlSt
result.addAll(createParameterColumnDefinition41Packets(sqlStatementContext, characterSet, serverPreparedStatement));
result.add(new MySQLEofPacket(statusFlags));
}
if (!projections.isEmpty()) {
if (!projections.isEmpty() && sqlStatementContext instanceof SelectStatementContext) {
result.addAll(createProjectionColumnDefinition41Packets((SelectStatementContext) sqlStatementContext, characterSet));
result.add(new MySQLEofPacket(statusFlags));
}
return result;
}

private List<Projection> getProjections(final SQLStatementContext sqlStatementContext) {
private Collection<Projection> getProjections(final SQLStatementContext sqlStatementContext) {
return sqlStatementContext instanceof SelectStatementContext ? ((SelectStatementContext) sqlStatementContext).getProjectionsContext().getExpandProjections() : Collections.emptyList();
}

Expand Down

0 comments on commit 1b20e31

Please sign in to comment.