Skip to content

Commit 1baee2b

Browse files
committed
Indeterminate PreparedStatement error hidden when inside a transaction
See #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 4ab36b8 commit 1baee2b

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,14 @@ private <T> void testInferDataType42P18(TestContext ctx, Class<T> type, T value,
547547
ctx.assertEquals("HELLO " + suffix2, str);
548548
}));
549549
}));
550+
PgConnection.connect(vertx, options()).onComplete(ctx.asyncAssertSuccess(conn -> {
551+
conn.begin()
552+
.flatMap(tx -> conn.preparedQuery("SELECT CONCAT('HELLO ', $1)").execute(Tuple.of(value))
553+
.eventually(() -> conn.close())
554+
.onComplete(ctx.asyncAssertFailure(failure -> {
555+
ctx.assertTrue(hasSqlstateCode(failure, "42P18"));
556+
})));
557+
}));
550558
}
551559

552560
@Test

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ private void fireCommandMessage(ChannelHandlerContext chctx, CommandMessage<?, ?
334334
ctx.flush();
335335
}
336336
} else {
337-
if (isIndeterminatePreparedStatementError(cause) && !sendParameterTypes) {
337+
if (queryCmd.autoCommit() && isIndeterminatePreparedStatementError(cause) && !sendParameterTypes) {
338338
ChannelHandlerContext ctx = socket.channelHandlerContext();
339339
// We cannot cache this prepared statement because it might be executed with another type
340340
fireCommandMessage(ctx, prepareCommand(queryCmd, handler, false, true));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public Future<PreparedStatement> prepare(String sql, PrepareOptions options) {
8282
.compose(
8383
cr -> Future.succeededFuture(PreparedStatementBase.create(conn, context, cr, autoCommit())),
8484
err -> {
85-
if (conn.isIndeterminatePreparedStatementError(err)) {
85+
if (autoCommit() && conn.isIndeterminatePreparedStatementError(err)) {
8686
return Future.succeededFuture(PreparedStatementBase.create(conn, context, options, sql, autoCommit()));
8787
} else {
8888
return Future.failedFuture(err);

0 commit comments

Comments
 (0)