data/DatabaseSync.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <QSqlDatabase> | ||
| 4 | #include <QSqlError> | ||
| 5 | #include <QSqlQuery> | ||
| 6 | #include <QString> | ||
| 7 | #include <QStringList> | ||
| 8 | #include <QVariantList> | ||
| 9 | |||
| 10 | namespace DatabaseSync { | ||
| 11 | |||
| 12 | 25 | inline bool removeRowsMissingFromUidSet(QSqlDatabase &db, | |
| 13 | const QString &deleteSql, | ||
| 14 | const QVariantList &deleteBindings, | ||
| 15 | const QStringList &activeUids, | ||
| 16 | QString *error) { | ||
| 17 | 25 | constexpr auto savepoint = "mailjd_uid_reconcile"; | |
| 18 | 25 | constexpr auto tempTable = "mailjd_active_sync_uids"; | |
| 19 |
1/1✓ Branch 2 → 3 taken 25 times.
|
25 | QSqlQuery query(db); |
| 20 | |||
| 21 | 3 | auto fail = [&]() { | |
| 22 |
1/2✓ Branch 2 → 3 taken 3 times.
✗ Branch 2 → 9 not taken.
|
3 | if (error) |
| 23 |
2/2✓ Branch 3 → 4 taken 3 times.
✓ Branch 4 → 5 taken 3 times.
|
3 | *error = query.lastError().text(); |
| 24 |
1/1✓ Branch 9 → 10 taken 3 times.
|
3 | QSqlQuery cleanup(db); |
| 25 |
1/1✓ Branch 17 → 18 taken 3 times.
|
9 | cleanup.exec(QStringLiteral("ROLLBACK TO SAVEPOINT %1") |
| 26 |
2/2✓ Branch 15 → 16 taken 3 times.
✓ Branch 16 → 17 taken 3 times.
|
9 | .arg(QString::fromLatin1(savepoint))); |
| 27 |
1/1✓ Branch 29 → 30 taken 3 times.
|
9 | cleanup.exec(QStringLiteral("RELEASE SAVEPOINT %1") |
| 28 |
2/2✓ Branch 27 → 28 taken 3 times.
✓ Branch 28 → 29 taken 3 times.
|
6 | .arg(QString::fromLatin1(savepoint))); |
| 29 | 3 | return false; | |
| 30 | 28 | }; | |
| 31 | |||
| 32 |
1/1✓ Branch 10 → 11 taken 25 times.
|
75 | if (!query.exec(QStringLiteral("SAVEPOINT %1") |
| 33 |
3/4✓ Branch 8 → 9 taken 25 times.
✓ Branch 9 → 10 taken 25 times.
✗ Branch 15 → 16 not taken.
✓ Branch 15 → 18 taken 25 times.
|
75 | .arg(QString::fromLatin1(savepoint)))) |
| 34 | ✗ | return fail(); | |
| 35 |
1/1✓ Branch 25 → 26 taken 25 times.
|
75 | if (!query.exec(QStringLiteral( |
| 36 | "CREATE TEMP TABLE IF NOT EXISTS %1 " | ||
| 37 | "(uid TEXT PRIMARY KEY) WITHOUT ROWID") | ||
| 38 |
3/4✓ Branch 23 → 24 taken 25 times.
✓ Branch 24 → 25 taken 25 times.
✗ Branch 30 → 31 not taken.
✓ Branch 30 → 33 taken 25 times.
|
75 | .arg(QString::fromLatin1(tempTable)))) |
| 39 | ✗ | return fail(); | |
| 40 |
1/1✓ Branch 40 → 41 taken 25 times.
|
75 | if (!query.exec(QStringLiteral("DELETE FROM %1") |
| 41 |
3/4✓ Branch 38 → 39 taken 25 times.
✓ Branch 39 → 40 taken 25 times.
✗ Branch 45 → 46 not taken.
✓ Branch 45 → 48 taken 25 times.
|
75 | .arg(QString::fromLatin1(tempTable)))) |
| 42 | ✗ | return fail(); | |
| 43 | |||
| 44 |
1/1✓ Branch 55 → 56 taken 25 times.
|
75 | query.prepare(QStringLiteral("INSERT OR IGNORE INTO %1(uid) VALUES (?)") |
| 45 |
2/2✓ Branch 53 → 54 taken 25 times.
✓ Branch 54 → 55 taken 25 times.
|
50 | .arg(QString::fromLatin1(tempTable))); |
| 46 |
2/2✓ Branch 73 → 62 taken 99031 times.
✓ Branch 73 → 74 taken 25 times.
|
99056 | for (const QString &uid : activeUids) { |
| 47 |
1/1✓ Branch 65 → 66 taken 99031 times.
|
99031 | query.bindValue(0, uid); |
| 48 |
2/3✓ Branch 67 → 68 taken 99031 times.
✗ Branch 68 → 69 not taken.
✓ Branch 68 → 71 taken 99031 times.
|
99031 | if (!query.exec()) |
| 49 | ✗ | return fail(); | |
| 50 | } | ||
| 51 | |||
| 52 |
1/1✓ Branch 74 → 76 taken 25 times.
|
25 | query.prepare(deleteSql); |
| 53 |
2/2✓ Branch 83 → 78 taken 25 times.
✓ Branch 83 → 84 taken 25 times.
|
50 | for (const QVariant &binding : deleteBindings) |
| 54 |
1/1✓ Branch 80 → 81 taken 25 times.
|
25 | query.addBindValue(binding); |
| 55 |
3/3✓ Branch 84 → 85 taken 25 times.
✓ Branch 85 → 86 taken 3 times.
✓ Branch 85 → 88 taken 22 times.
|
25 | if (!query.exec()) |
| 56 |
1/1✓ Branch 86 → 87 taken 3 times.
|
3 | return fail(); |
| 57 | |||
| 58 |
1/1✓ Branch 95 → 96 taken 22 times.
|
66 | if (!query.exec(QStringLiteral("RELEASE SAVEPOINT %1") |
| 59 |
3/4✓ Branch 93 → 94 taken 22 times.
✓ Branch 94 → 95 taken 22 times.
✗ Branch 100 → 101 not taken.
✓ Branch 100 → 103 taken 22 times.
|
66 | .arg(QString::fromLatin1(savepoint)))) |
| 60 | ✗ | return fail(); | |
| 61 | 22 | return true; | |
| 62 | 25 | } | |
| 63 | |||
| 64 | } // namespace DatabaseSync | ||
| 65 |