Skip to content

Commit 71a647e

Browse files
authored
Fix transactional insert throwing No Value Present in server (#3476)
This changes the transactional logic to correctly handle mutations Fixes: #3475
1 parent 98d988c commit 71a647e

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

fdb-relational-jdbc/src/test/java/com/apple/foundationdb/relational/jdbc/JDBCAutoCommitTest.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ void autoCommitOn() throws SQLException, IOException {
8484
* Run a test with commit and then read.
8585
*/
8686
@Test
87-
void commitThenRead() throws SQLException, IOException {
87+
void directInsertCommitThenRead() throws SQLException, IOException {
8888
try (RelationalConnection connection = DriverManager.getConnection(getTestDbUri()).unwrap(RelationalConnection.class)) {
8989
connection.setAutoCommit(false);
9090

@@ -100,6 +100,27 @@ void commitThenRead() throws SQLException, IOException {
100100
}
101101
}
102102

103+
/**
104+
* Run a test with commit and then read.
105+
*/
106+
@Test
107+
void queryInsertCommitThenRead() throws SQLException, IOException {
108+
try (RelationalConnection connection = DriverManager.getConnection(getTestDbUri()).unwrap(RelationalConnection.class)) {
109+
connection.setAutoCommit(false);
110+
111+
try (RelationalStatement statement = connection.createStatement()) {
112+
Assertions.assertFalse(statement.execute("INSERT INTO test_table VALUES (100, 'one hundred')"));
113+
Assertions.assertEquals(1, statement.getUpdateCount());
114+
connection.commit();
115+
116+
RelationalResultSet resultSet = statement.executeQuery("SELECT * FROM test_table");
117+
assertNextResult(resultSet, 100, "one hundred");
118+
assertNoNextResult(resultSet);
119+
connection.commit();
120+
}
121+
}
122+
}
123+
103124
@Test
104125
void insertMultiCommitRead() throws SQLException, IOException {
105126
try (RelationalConnection connection = DriverManager.getConnection(getTestDbUri()).unwrap(RelationalConnection.class)) {

fdb-relational-server/src/main/java/com/apple/foundationdb/relational/server/jdbc/v1/TransactionRequestHandler.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,13 @@ public void onNext(final TransactionalRequest transactionRequest) {
8282
final FRL.Response response = frl.transactionalExecute(transactionalToken, request.getSql(),
8383
request.getParameters().getParameterList(), fromProto(request.getOptions()));
8484

85-
StatementResponse.Builder statementResponseBuilder = StatementResponse.newBuilder()
86-
.setResultSet(response.getResultSet())
87-
.setRowCount(response.getRowCount());
85+
StatementResponse.Builder statementResponseBuilder = StatementResponse.newBuilder();
86+
if (response.isQuery()) {
87+
statementResponseBuilder.setResultSet(response.getResultSet());
88+
}
89+
if (response.isMutation()) {
90+
statementResponseBuilder.setRowCount(response.getRowCount());
91+
}
8892

8993
responseBuilder.setExecuteResponse(statementResponseBuilder);
9094
} else if (transactionRequest.hasInsertRequest()) {

0 commit comments

Comments
 (0)