Skip to content

Commit b08cb01

Browse files
committed
Indeterminate PreparedStatement error hidden when inside a transaction (#1558)
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 659fa14 commit b08cb01

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/src/main/java/io/vertx/sqlclient/impl/SocketConnectionBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ private PrepareStatementCommand prepareCommand(ExtendedQueryCommand<?> queryCmd,
295295
ctx.flush();
296296
}
297297
} else {
298-
if (isIndeterminatePreparedStatementError(cause) && !sendParameterTypes) {
298+
if (queryCmd.autoCommit() && isIndeterminatePreparedStatementError(cause) && !sendParameterTypes) {
299299
ChannelHandlerContext ctx = socket.channelHandlerContext();
300300
// We cannot cache this prepared statement because it might be executed with another type
301301
ctx.write(prepareCommand(queryCmd, false, true), ctx.voidPromise());

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
@@ -80,7 +80,7 @@ public Future<PreparedStatement> prepare(String sql, PrepareOptions options) {
8080
.compose(
8181
cr -> Future.succeededFuture(PreparedStatementBase.create(conn, context, cr, autoCommit())),
8282
err -> {
83-
if (conn.isIndeterminatePreparedStatementError(err)) {
83+
if (autoCommit() && conn.isIndeterminatePreparedStatementError(err)) {
8484
return Future.succeededFuture(PreparedStatementBase.create(conn, context, options, sql, autoCommit()));
8585
} else {
8686
return Future.failedFuture(err);

0 commit comments

Comments
 (0)