summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@qt.io>2020-07-27 12:27:44 +0200
committerAndy Shaw <andy.shaw@qt.io>2020-09-07 15:50:04 +0200
commitb1af52f2b2e1d318fc7a5481659e8101bf2e18dd (patch)
treebc4ad38288c2dc19264fde4a5a85ac676af00bf4 /src/plugins
parent483f7d8809731c1acefec41217f0402614025c09 (diff)
PostgreSQL: Attempt to subscribe even if it is already added
As the connection could be lost and then reconnected for the same driver instance then it should just do the LISTEN query as it will not do anything if it is already subscribed. Fixes: QTBUG-84356 Change-Id: I6179bca3991c3828ccee066fd96a6e5003c522be Pick-to: 5.15 Reviewed-by: Lisandro Damián Nicanor Pérez Meyer <perezmeyer@gmail.com> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/sqldrivers/psql/qsql_psql.cpp17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/plugins/sqldrivers/psql/qsql_psql.cpp b/src/plugins/sqldrivers/psql/qsql_psql.cpp
index 60729840e2..cdc4ce7c36 100644
--- a/src/plugins/sqldrivers/psql/qsql_psql.cpp
+++ b/src/plugins/sqldrivers/psql/qsql_psql.cpp
@@ -1580,21 +1580,20 @@ bool QPSQLDriver::subscribeToNotification(const QString &name)
return false;
}
- if (d->seid.contains(name)) {
- qWarning("QPSQLDriver::subscribeToNotificationImplementation: already subscribing to '%s'.",
- qPrintable(name));
- return false;
- }
-
+ const bool alreadyContained = d->seid.contains(name);
int socket = PQsocket(d->connection);
if (socket) {
// Add the name to the list of subscriptions here so that QSQLDriverPrivate::exec knows
- // to check for notifications immediately after executing the LISTEN
- d->seid << name;
+ // to check for notifications immediately after executing the LISTEN. If it has already
+ // been subscribed then LISTEN Will do nothing. But we do the call anyway in case the
+ // connection was lost and this is a re-subscription.
+ if (!alreadyContained)
+ d->seid << name;
QString query = QStringLiteral("LISTEN ") + escapeIdentifier(name, QSqlDriver::TableName);
PGresult *result = d->exec(query);
if (PQresultStatus(result) != PGRES_COMMAND_OK) {
- d->seid.removeLast();
+ if (!alreadyContained)
+ d->seid.removeLast();
setLastError(qMakeError(tr("Unable to subscribe"), QSqlError::StatementError, d, result));
PQclear(result);
return false;