Skip to content

Commit 1208ba9

Browse files
committed
Add tests for new protocol version using PreparedStatement.execute()
1 parent 06c2843 commit 1208ba9

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightPreparedStatementTest.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,39 @@ public void testSimpleQueryNoParameterBindingWithExecute() throws SQLException {
9898
}
9999
}
100100

101+
@Test
102+
public void testSimpleQueryNoParameterBindingWithExecuteV2() throws SQLException {
103+
final String query = "SELECT * FROM TEST_V2";
104+
final Schema schema =
105+
new Schema(Collections.singletonList(Field.nullable("", Types.MinorType.INT.getType())));
106+
PRODUCER.addSelectQueryV2(
107+
query,
108+
schema,
109+
Collections.singletonList(
110+
listener -> {
111+
try (final BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE);
112+
final VectorSchemaRoot root = VectorSchemaRoot.create(schema, allocator)) {
113+
root.allocateNew();
114+
((IntVector) root.getVector(0)).setSafe(0, 123);
115+
root.setRowCount(1);
116+
listener.start(root);
117+
listener.putNext();
118+
} finally {
119+
listener.completed();
120+
}
121+
}));
122+
try (final PreparedStatement preparedStatement = connection.prepareStatement(query)) {
123+
boolean isResultSet = preparedStatement.execute();
124+
assertTrue(isResultSet);
125+
final ResultSet resultSet = preparedStatement.getResultSet();
126+
assertTrue(resultSet.next());
127+
assertEquals(123, resultSet.getInt(1));
128+
assertFalse(resultSet.next());
129+
assertFalse(preparedStatement.getMoreResults());
130+
assertEquals(-1, preparedStatement.getUpdateCount());
131+
}
132+
}
133+
101134
@Test
102135
public void testQueryWithParameterBinding() throws SQLException {
103136
final String query = "Fake query with parameters";
@@ -203,6 +236,20 @@ public void testUpdateQueryWithExecute() throws SQLException {
203236
}
204237
}
205238

239+
@Test
240+
public void testUpdateQueryWithExecuteV2() throws SQLException {
241+
String query = "Fake update with execute V2";
242+
PRODUCER.addUpdateQueryV2(query, /*updatedRows*/ 99);
243+
try (final PreparedStatement stmt = connection.prepareStatement(query)) {
244+
boolean isResultSet = stmt.execute();
245+
assertFalse(isResultSet);
246+
int updated = stmt.getUpdateCount();
247+
assertEquals(99, updated);
248+
assertFalse(stmt.getMoreResults());
249+
assertEquals(-1, stmt.getUpdateCount());
250+
}
251+
}
252+
206253
@Test
207254
public void testUpdateQueryWithParameters() throws SQLException {
208255
String query = "Fake update with parameters";

0 commit comments

Comments
 (0)