Skip to content

Commit 194e80c

Browse files
committed
Indeterminate PreparedStatement error hidden when inside a transaction (eclipse-vertx#1558)
See eclipse-vertx#1557 When inside a transaction (autocommit=false), don't try to prepare a statement again, even if the error is due to indeterminate types. Indeed, the transaction is aborted and new commands are ignored until the transaction is rollbacked. Signed-off-by: Thomas Segismont <[email protected]>
1 parent d3814d8 commit 194e80c

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

vertx-pg-client/src/test/java/io/vertx/pgclient/PreparedStatementTestBase.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,14 @@ private <T> void testInferDataType42P18(TestContext ctx, Class<T> type, T value,
509509
ctx.assertEquals("HELLO " + suffix2, str);
510510
}));
511511
}));
512+
PgConnection.connect(vertx, options()).onComplete(ctx.asyncAssertSuccess(conn -> {
513+
conn.begin()
514+
.flatMap(tx -> conn.preparedQuery("SELECT CONCAT('HELLO ', $1)").execute(Tuple.of(value))
515+
.eventually(() -> conn.close())
516+
.onComplete(ctx.asyncAssertFailure(failure -> {
517+
ctx.assertTrue(hasSqlstateCode(failure, "42P18"));
518+
})));
519+
}));
512520
}
513521

514522
@Test

vertx-sql-client/src/main/java/io/vertx/sqlclient/impl/SocketConnectionBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ private PrepareStatementCommand prepareCommand(ExtendedQueryCommand<?> queryCmd,
303303
}
304304
} else {
305305
Throwable cause = ar.cause();
306-
if (isIndeterminatePreparedStatementError(cause) && !sendParameterTypes) {
306+
if (queryCmd.autoCommit() && isIndeterminatePreparedStatementError(cause) && !sendParameterTypes) {
307307
ChannelHandlerContext ctx = socket.channelHandlerContext();
308308
// We cannot cache this prepared statement because it might be executed with another type
309309
ctx.write(prepareCommand(queryCmd, false, true), ctx.voidPromise());

vertx-sql-client/src/main/java/io/vertx/sqlclient/impl/SqlConnectionBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public Future<PreparedStatement> prepare(String sql, PrepareOptions options) {
7676
.compose(
7777
cr -> Future.succeededFuture(PreparedStatementImpl.create(conn, context, cr, autoCommit())),
7878
err -> {
79-
if (conn.isIndeterminatePreparedStatementError(err)) {
79+
if (autoCommit() && conn.isIndeterminatePreparedStatementError(err)) {
8080
return Future.succeededFuture(PreparedStatementImpl.create(conn, context, options, sql, autoCommit()));
8181
} else {
8282
return Future.failedFuture(err);

0 commit comments

Comments
 (0)