Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,17 @@ static Signature newSignature(final String sql, Schema resultSetSchema, Schema p
parameterSchema == null
? new ArrayList<>()
: ConvertUtils.convertArrowFieldsToAvaticaParameters(parameterSchema.getFields());

StatementType statementType =
resultSetSchema == null || resultSetSchema.getFields().isEmpty()
? StatementType.IS_DML
: StatementType.SELECT;
return new Signature(
columnMetaData,
sql,
parameters,
Collections.emptyMap(),
null, // unnecessary, as SQL requests use ArrowFlightJdbcCursor
StatementType.SELECT);
statementType);
}

@Override
Expand Down Expand Up @@ -105,7 +108,8 @@ public ExecuteResult execute(
preparedStatement, ((ArrowFlightConnection) connection).getBufferAllocator())
.bind(typedValues);

if (statementHandle.signature == null) {
if (statementHandle.signature == null
|| statementHandle.signature.statementType == StatementType.IS_DML) {
// Update query
long updatedCount = preparedStatement.executeUpdate();
return new ExecuteResult(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.nio.charset.StandardCharsets;
import java.sql.Connection;
Expand Down Expand Up @@ -83,6 +85,19 @@ public void testSimpleQueryNoParameterBinding() throws SQLException {
}
}

@Test
public void testSimpleQueryNoParameterBindingWithExecute() throws SQLException {
final String query = CoreMockedSqlProducers.LEGACY_REGULAR_SQL_CMD;
try (final PreparedStatement preparedStatement = connection.prepareStatement(query)) {
boolean isResultSet = preparedStatement.execute();
assertTrue(isResultSet);
final ResultSet resultSet = preparedStatement.getResultSet();
CoreMockedSqlProducers.assertLegacyRegularSqlResultSet(resultSet);
assertFalse(preparedStatement.getMoreResults());
assertEquals(-1, preparedStatement.getUpdateCount());
}
}

@Test
public void testQueryWithParameterBinding() throws SQLException {
final String query = "Fake query with parameters";
Expand Down Expand Up @@ -174,6 +189,20 @@ public void testUpdateQuery() throws SQLException {
}
}

@Test
public void testUpdateQueryWithExecute() throws SQLException {
String query = "Fake update with execute";
PRODUCER.addUpdateQuery(query, /*updatedRows*/ 42);
try (final PreparedStatement stmt = connection.prepareStatement(query)) {
boolean isResultSet = stmt.execute();
assertFalse(isResultSet);
int updated = stmt.getUpdateCount();
assertEquals(42, updated);
assertFalse(stmt.getMoreResults());
assertEquals(-1, stmt.getUpdateCount());
}
}

@Test
public void testUpdateQueryWithParameters() throws SQLException {
String query = "Fake update with parameters";
Expand Down
Loading