From e2431b619da5c53d34df0b46105deb4450ed0c1f Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sun, 15 Sep 2019 19:49:32 +0200 Subject: QPSQL: Fix crash when a prepared statement is deleted after the db was removed When a prepared statement is still alive after the database was removed with QSqlDatabase::removeDatabase(), the cleanup routine is trying to access the driver which is no longer alive which results in a crash. Fix it by checking if the driver is still alive similar to 5f66486cc254e1483f776d3058f96db493fd26e5. Fixes: QTBUG-43889 Change-Id: Ib466a76d014e32c055d203bda15b075ad3dff3d9 Reviewed-by: Andy Shaw Reviewed-by: Jesus Fernandez --- src/plugins/sqldrivers/psql/qsql_psql.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/plugins/sqldrivers/psql') diff --git a/src/plugins/sqldrivers/psql/qsql_psql.cpp b/src/plugins/sqldrivers/psql/qsql_psql.cpp index 0bae45382d..28be7bdc38 100644 --- a/src/plugins/sqldrivers/psql/qsql_psql.cpp +++ b/src/plugins/sqldrivers/psql/qsql_psql.cpp @@ -428,12 +428,14 @@ static QVariant::Type qDecodePSQLType(int t) void QPSQLResultPrivate::deallocatePreparedStmt() { - const QString stmt = QStringLiteral("DEALLOCATE ") + preparedStmtId; - PGresult *result = drv_d_func()->exec(stmt); + if (drv_d_func()) { + const QString stmt = QStringLiteral("DEALLOCATE ") + preparedStmtId; + PGresult *result = drv_d_func()->exec(stmt); - if (PQresultStatus(result) != PGRES_COMMAND_OK) - qWarning("Unable to free statement: %s", PQerrorMessage(drv_d_func()->connection)); - PQclear(result); + if (PQresultStatus(result) != PGRES_COMMAND_OK) + qWarning("Unable to free statement: %s", PQerrorMessage(drv_d_func()->connection)); + PQclear(result); + } preparedStmtId.clear(); } -- cgit v1.2.3 From aa6d7dd7ee306c0adbcd42b013d1e749072205bb Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Wed, 18 Sep 2019 20:34:13 +0200 Subject: QSqlDriver: deprecate one-arg notification() signal QSqlDriver::notifcation() signal is available in two versions since Qt4 times. They are both emitted in the corresponding places which is useless. Therefore deprecate the one-arg version. [ChangeLog][QtSql][QSqlDriver] The one-arg version of QSqlDriver::notifcation() is now deprecated. Change-Id: Ie09aa0cc952f4d854c6fb617b37b9047a3194ee3 Reviewed-by: Andy Shaw --- src/plugins/sqldrivers/psql/qsql_psql.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/plugins/sqldrivers/psql') diff --git a/src/plugins/sqldrivers/psql/qsql_psql.cpp b/src/plugins/sqldrivers/psql/qsql_psql.cpp index 28be7bdc38..5f325db81e 100644 --- a/src/plugins/sqldrivers/psql/qsql_psql.cpp +++ b/src/plugins/sqldrivers/psql/qsql_psql.cpp @@ -1692,7 +1692,12 @@ void QPSQLDriver::_q_handleNotification(int) if (notify->extra) payload = d->isUtf8 ? QString::fromUtf8(notify->extra) : QString::fromLatin1(notify->extra); #endif +#if QT_DEPRECATED_SINCE(5, 15) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED emit notification(name); +QT_WARNING_POP +#endif QSqlDriver::NotificationSource source = (notify->be_pid == PQbackendPID(d->connection)) ? QSqlDriver::SelfSource : QSqlDriver::OtherSource; emit notification(name, source, payload); } -- cgit v1.2.3 From a978d21dac57697ae9557b99062bc804b005b9d4 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sun, 29 Sep 2019 21:28:52 +0200 Subject: PSQL: don't recreate QSqlField in loop in QPSQLResult::record() Move out the QSqlField variable out of the loop to avoid useless (de)allocations of QSqlField. Change-Id: I2c9e4c84f75e994d5eb1438839d502f6da531841 Reviewed-by: Robert Szefner Reviewed-by: Andy Shaw --- src/plugins/sqldrivers/psql/qsql_psql.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/plugins/sqldrivers/psql') diff --git a/src/plugins/sqldrivers/psql/qsql_psql.cpp b/src/plugins/sqldrivers/psql/qsql_psql.cpp index 28be7bdc38..3803f05b9f 100644 --- a/src/plugins/sqldrivers/psql/qsql_psql.cpp +++ b/src/plugins/sqldrivers/psql/qsql_psql.cpp @@ -812,8 +812,8 @@ QSqlRecord QPSQLResult::record() const return info; int count = PQnfields(d->result); + QSqlField f; for (int i = 0; i < count; ++i) { - QSqlField f; if (d->drv_d_func()->isUtf8) f.setName(QString::fromUtf8(PQfname(d->result, i))); else @@ -833,6 +833,8 @@ QSqlRecord QPSQLResult::record() const } } f.setTableName(tableName); + } else { + f.setTableName(QString()); } int ptype = PQftype(d->result, i); f.setType(qDecodePSQLType(ptype)); -- cgit v1.2.3