Skip to content

Commit 6086105

Browse files
committed
bugfix: extrac columns only when SELECT/DELETE/INSERT/UPDATE statements (i.e., ignore CALL next value-like statements)
1 parent f86b228 commit 6086105

2 files changed

Lines changed: 33 additions & 9 deletions

File tree

client-java/sql/src/main/java/org/evomaster/client/java/sql/internal/SqlHandler.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,21 @@ public void handle(SqlExecutionLogDto sqlExecutionLogDto) {
150150

151151
private void mergeNewDataForCompleteSqlHeuristics(String sqlCommand) {
152152
Statement parsedSqlCommand = SqlParserUtils.parseSqlCommand(sqlCommand);
153-
Map<SqlTableId, Set<SqlColumnId>> columns = extractColumnsInvolvedInStatement(parsedSqlCommand);
154-
if (parsedSqlCommand instanceof Select) {
155-
mergeNewData(queriedData, columns);
156-
} else if (parsedSqlCommand instanceof Delete) {
157-
deletedData.addAll(columns.keySet());
158-
} else if (parsedSqlCommand instanceof Insert) {
159-
mergeNewData(insertedData, columns);
160-
} else if (parsedSqlCommand instanceof Update) {
161-
mergeNewData(updatedData, columns);
153+
if (parsedSqlCommand instanceof Select
154+
|| parsedSqlCommand instanceof Delete
155+
|| parsedSqlCommand instanceof Insert
156+
|| parsedSqlCommand instanceof Update) {
157+
158+
Map<SqlTableId, Set<SqlColumnId>> columns = extractColumnsInvolvedInStatement(parsedSqlCommand);
159+
if (parsedSqlCommand instanceof Select) {
160+
mergeNewData(queriedData, columns);
161+
} else if (parsedSqlCommand instanceof Delete) {
162+
deletedData.addAll(columns.keySet());
163+
} else if (parsedSqlCommand instanceof Insert) {
164+
mergeNewData(insertedData, columns);
165+
} else if (parsedSqlCommand instanceof Update) {
166+
mergeNewData(updatedData, columns);
167+
}
162168
}
163169
}
164170

client-java/sql/src/test/java/org/evomaster/client/java/sql/internal/SqlHandlerTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import org.evomaster.client.java.controller.api.dto.database.schema.TableDto;
99
import org.jetbrains.annotations.NotNull;
1010
import org.junit.jupiter.api.Test;
11+
import org.junit.jupiter.params.ParameterizedTest;
12+
import org.junit.jupiter.params.provider.ValueSource;
1113

1214
import java.sql.*;
1315
import java.util.Collections;
@@ -196,6 +198,22 @@ private static ColumnDto createColumnDto(String tableName, String columnName) {
196198
return schema;
197199
}
198200

201+
@ParameterizedTest
202+
@ValueSource(booleans = {false, true})
203+
public void testCallNextValue(boolean isCompleteSqlHeuristics) {
204+
205+
String sqlCommand = "CALL next value for hibernate_sequence";
206+
SqlHandler sqlHandler = new SqlHandler(null);
207+
sqlHandler.setCalculateHeuristics(true);
208+
sqlHandler.setCompleteSqlHeuristics(isCompleteSqlHeuristics);
209+
210+
SqlExecutionLogDto sqlExecutionLogDto = new SqlExecutionLogDto();
211+
sqlExecutionLogDto.sqlCommand = sqlCommand;
212+
sqlExecutionLogDto.threwSqlExeception = false;
213+
214+
sqlHandler.handle(sqlExecutionLogDto);
215+
}
216+
199217
private static @NotNull Connection createMockConnectionForSimpleSelect() throws SQLException {
200218
Connection mockConnection = mock(Connection.class);
201219
ResultSet mockEmployeeResultSet = mock(ResultSet.class);

0 commit comments

Comments
 (0)