if (eBuffer->subscriptionState == QIBaseEventBuffer::Subscribed) {
emit notification(i.key());
- emit notification(i.key(), QSqlDriver::UnknownSource);
+ emit notification(i.key(), QSqlDriver::UnknownSource, QVariant());
}
else if (eBuffer->subscriptionState == QIBaseEventBuffer::Starting)
eBuffer->subscriptionState = QIBaseEventBuffer::Subscribed;
while((notify = PQnotifies(d->connection)) != 0) {
QString name(QLatin1String(notify->relname));
if (d->seid.contains(name)) {
+ QString payload;
+#if defined PG_VERSION_NUM && PG_VERSION_NUM-0 >= 70400
+ if (notify->extra)
+ payload = d->isUtf8 ? QString::fromUtf8(notify->extra) : QString::fromAscii(notify->extra);
+#endif
emit notification(name);
QSqlDriver::NotificationSource source = (notify->be_pid == PQbackendPID(d->connection)) ? QSqlDriver::SelfSource : QSqlDriver::OtherSource;
- emit notification(name, source);
+ emit notification(name, source, payload);
}
else
qWarning("QPSQLDriver: received notification for '%s' which isn't subscribed to.",
/*!
\since 5.0
- \fn QSqlDriver::notification(const QString &name, NotificationSource source)
+ \fn QSqlDriver::notification(const QString &name, NotificationSource source, const QString & payload)
This signal is emitted when the database posts an event notification
- that the driver subscribes to. \a name identifies the event notification, \a source indicates the signal source.
+ that the driver subscribes to. \a name identifies the event notification, \a source indicates the signal source,
+ \a payload holds the extra data optionally delivered with the notification.
\sa subscribeToNotification()
*/
Q_SIGNALS:
void notification(const QString &name);
- void notification(const QString &name, QSqlDriver::NotificationSource source);
+ void notification(const QString &name, QSqlDriver::NotificationSource source, const QVariant &payload);
protected:
virtual void setOpen(bool o);
QSqlQuery query(db);
QString procedureName = qTableName("posteventProc", __FILE__);
+ QString payload = "payload";
QSqlDriver &driver=*(db.driver());
QVERIFY_SQL(driver, subscribeToNotification(procedureName));
- QSignalSpy spy(db.driver(), SIGNAL(notification(const QString&,QSqlDriver::NotificationSource)));
- query.exec(QString("NOTIFY \"%1\"").arg(procedureName));
+ QSignalSpy spy(db.driver(), SIGNAL(notification(const QString&,QSqlDriver::NotificationSource,const QVariant&)));
+ query.exec(QString("NOTIFY \"%1\", '%2'").arg(procedureName).arg(payload));
QCoreApplication::processEvents();
QCOMPARE(spy.count(), 1);
QList<QVariant> arguments = spy.takeFirst();
- QVERIFY(arguments.at(0).toString() == procedureName);
- QVERIFY(qVariantValue<QSqlDriver::NotificationSource>(arguments.at(1)) == QSqlDriver::SelfSource);
+ QCOMPARE(arguments.at(0).toString(), procedureName);
+ QCOMPARE(qVariantValue<QSqlDriver::NotificationSource>(arguments.at(1)), QSqlDriver::SelfSource);
+ QCOMPARE(qvariant_cast<QVariant>(arguments.at(2)).toString(), payload);
QVERIFY_SQL(driver, unsubscribeFromNotification(procedureName));
}