From b7ef2510d1f7b115937b39a1eb010a41add2c0b4 Mon Sep 17 00:00:00 2001 From: Karim Pinter Date: Mon, 4 Apr 2016 11:48:09 +0300 Subject: Adding notification feature to SQLite driver This modification enables to use notification feature of SQLite with Qt SQL driver, enables to subscribe for notifications and also to remove notifications. close() is added to destructor to unregister notifications in case it is used in multiple threads. [ChangeLog][QtSql][SQLite] Adding notification feature to SQLite driver Change-Id: I8b98787f5214a406357646a98711a8ff6045a0dd Reviewed-by: Andy Shaw --- .../sql/kernel/qsqldatabase/tst_qsqldatabase.cpp | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'tests') diff --git a/tests/auto/sql/kernel/qsqldatabase/tst_qsqldatabase.cpp b/tests/auto/sql/kernel/qsqldatabase/tst_qsqldatabase.cpp index bd8fbcca0e..8126e72ad2 100644 --- a/tests/auto/sql/kernel/qsqldatabase/tst_qsqldatabase.cpp +++ b/tests/auto/sql/kernel/qsqldatabase/tst_qsqldatabase.cpp @@ -100,6 +100,8 @@ private slots: void eventNotificationIBase(); void eventNotificationPSQL_data() { generic_data("QPSQL"); } void eventNotificationPSQL(); + void eventNotificationSQLite_data() { generic_data("QSQLITE"); } + void eventNotificationSQLite(); //database specific 64 bit integer test void bigIntField_data() { generic_data(); } @@ -2109,6 +2111,35 @@ void tst_QSqlDatabase::eventNotificationPSQL() QVERIFY_SQL(driver, unsubscribeFromNotification(procedureName)); } +void tst_QSqlDatabase::eventNotificationSQLite() +{ + QFETCH(QString, dbName); + QSqlDatabase db = QSqlDatabase::database(dbName); + CHECK_DATABASE(db); + if (db.driverName().compare(QLatin1String("QSQLITE"), Qt::CaseInsensitive)) { + QSKIP("QSQLITE specific test"); + } + const QString tableName(qTableName("sqlitnotifytest", __FILE__, db)); + tst_Databases::safeDropTable(db, tableName); + + QSignalSpy notificationSpy(db.driver(), SIGNAL(notification(QString))); + QSignalSpy notificationSpyExt(db.driver(), SIGNAL(notification(QString,QSqlDriver::NotificationSource,QVariant))); + QSqlQuery q(db); + QVERIFY_SQL(q, exec("CREATE TABLE " + tableName + " (id INTEGER, realVal REAL)")); + db.driver()->subscribeToNotification(tableName); + QVERIFY_SQL(q, exec("INSERT INTO " + tableName + " (id, realVal) VALUES (1, 2.3)")); + QTRY_COMPARE(notificationSpy.count(), 1); + QTRY_COMPARE(notificationSpyExt.count(), 1); + QList arguments = notificationSpy.takeFirst(); + QCOMPARE(arguments.at(0).toString(), tableName); + arguments = notificationSpyExt.takeFirst(); + QCOMPARE(arguments.at(0).toString(), tableName); + db.driver()->unsubscribeFromNotification(tableName); + QVERIFY_SQL(q, exec("INSERT INTO " + tableName + " (id, realVal) VALUES (1, 2.3)")); + QTRY_COMPARE(notificationSpy.count(), 0); + QTRY_COMPARE(notificationSpyExt.count(), 0); +} + void tst_QSqlDatabase::sqlite_bindAndFetchUInt() { QFETCH(QString, dbName); -- cgit v1.2.3