From 9094ad18b0d909f7490dec3451ec7ef9c312f42a Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sun, 19 Jan 2025 17:35:21 +0100 Subject: [PATCH] SQL/PSQL: call deallocatePreparedStmt() unconditionally deallocatePreparedStmt() knows by itself when to call the psql cleanup routines or not. No need to have this logic outside this function. Pick-to: 6.9 Task-number: QTBUG-132303 Change-Id: Ib1a5ba7b53c156f6a6b93f23a3ec8c851d7398fc Reviewed-by: Thiago Macieira Reviewed-by: Thierry Bastian --- src/plugins/sqldrivers/psql/qsql_psql.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/plugins/sqldrivers/psql/qsql_psql.cpp b/src/plugins/sqldrivers/psql/qsql_psql.cpp index 3d6027048e7..dc7ea70a468 100644 --- a/src/plugins/sqldrivers/psql/qsql_psql.cpp +++ b/src/plugins/sqldrivers/psql/qsql_psql.cpp @@ -387,7 +387,7 @@ static QMetaType qDecodePSQLType(int t) void QPSQLResultPrivate::deallocatePreparedStmt() { - if (drv_d_func()) { + if (drv_d_func() && !preparedStmtId.isEmpty()) { #if defined(LIBPQ_HAS_CLOSE_PREPARED) PGresult *result = PQclosePrepared(drv_d_func()->connection, preparedStmtId.toUtf8()); #else @@ -416,8 +416,7 @@ QPSQLResult::~QPSQLResult() Q_D(QPSQLResult); cleanup(); - if (d->preparedQueriesEnabled && !d->preparedStmtId.isNull()) - d->deallocatePreparedStmt(); + d->deallocatePreparedStmt(); } QVariant QPSQLResult::handle() const @@ -862,8 +861,7 @@ bool QPSQLResult::prepare(const QString &query) cleanup(); - if (!d->preparedStmtId.isEmpty()) - d->deallocatePreparedStmt(); + d->deallocatePreparedStmt(); const QString stmtId = qMakePreparedStmtId(); PGresult *result = PQprepare(d->drv_d_func()->connection, stmtId.toUtf8(),