summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorKarim Pinter <karim.pinter@theqtcompany.com>2016-04-04 11:48:09 +0300
committerKarim Pinter <karim.pinter@theqtcompany.com>2016-04-21 10:56:24 +0000
commitb7ef2510d1f7b115937b39a1eb010a41add2c0b4 (patch)
treeb466ca0dc3b2fc73c9385af016968ee549db3a59 /tests
parent2be25273e1fc81c5a9e5124f1444100bdb3d458a (diff)
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 <andy.shaw@theqtcompany.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/sql/kernel/qsqldatabase/tst_qsqldatabase.cpp31
1 files changed, 31 insertions, 0 deletions
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<QVariant> 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);