MailJD nbsp;·nbsp; Test Dashboard nbsp;·nbsp; Coverage
LCOV - code coverage report
Current view: top level - data - DatabaseSync.h (source / functions) Coverage Total Hit
Test: MailJD Coverage (Unit + E2E) Lines: 87.2 % 39 34
Test Date: 2026-06-21 21:10:19 Functions: 100.0 % 2 2
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
Branches: 47.8 % 90 43

             Branch data     Line data    Source code
       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                 :          17 : inline bool removeRowsMissingFromUidSet(QSqlDatabase &db,
      13                 :             :                                         const QString &deleteSql,
      14                 :             :                                         const QVariantList &deleteBindings,
      15                 :             :                                         const QStringList &activeUids,
      16                 :             :                                         QString *error) {
      17                 :          17 :   constexpr auto savepoint = "mailjd_uid_reconcile";
      18                 :          17 :   constexpr auto tempTable = "mailjd_active_sync_uids";
      19         [ +  - ]:          17 :   QSqlQuery query(db);
      20                 :             : 
      21                 :           3 :   auto fail = [&]() {
      22         [ +  - ]:           3 :     if (error)
      23   [ +  -  +  - ]:           3 :       *error = query.lastError().text();
      24         [ +  - ]:           3 :     QSqlQuery cleanup(db);
      25         [ +  - ]:           9 :     cleanup.exec(QStringLiteral("ROLLBACK TO SAVEPOINT %1")
      26   [ +  -  +  - ]:           9 :                      .arg(QString::fromLatin1(savepoint)));
      27         [ +  - ]:           9 :     cleanup.exec(QStringLiteral("RELEASE SAVEPOINT %1")
      28   [ +  -  +  - ]:           6 :                      .arg(QString::fromLatin1(savepoint)));
      29                 :           3 :     return false;
      30                 :          20 :   };
      31                 :             : 
      32         [ +  - ]:          51 :   if (!query.exec(QStringLiteral("SAVEPOINT %1")
      33   [ +  -  +  -  :          51 :                       .arg(QString::fromLatin1(savepoint))))
                   -  + ]
      34         [ #  # ]:           0 :     return fail();
      35         [ +  - ]:          51 :   if (!query.exec(QStringLiteral(
      36                 :             :           "CREATE TEMP TABLE IF NOT EXISTS %1 "
      37                 :             :           "(uid TEXT PRIMARY KEY) WITHOUT ROWID")
      38   [ +  -  +  -  :          51 :                       .arg(QString::fromLatin1(tempTable))))
                   -  + ]
      39         [ #  # ]:           0 :     return fail();
      40         [ +  - ]:          51 :   if (!query.exec(QStringLiteral("DELETE FROM %1")
      41   [ +  -  +  -  :          51 :                       .arg(QString::fromLatin1(tempTable))))
                   -  + ]
      42         [ #  # ]:           0 :     return fail();
      43                 :             : 
      44         [ +  - ]:          51 :   query.prepare(QStringLiteral("INSERT OR IGNORE INTO %1(uid) VALUES (?)")
      45   [ +  -  +  - ]:          34 :                     .arg(QString::fromLatin1(tempTable)));
      46         [ +  + ]:       99032 :   for (const QString &uid : activeUids) {
      47         [ +  - ]:       99015 :     query.bindValue(0, uid);
      48   [ +  -  -  + ]:       99015 :     if (!query.exec())
      49         [ #  # ]:           0 :       return fail();
      50                 :             :   }
      51                 :             : 
      52         [ +  - ]:          17 :   query.prepare(deleteSql);
      53         [ +  + ]:          29 :   for (const QVariant &binding : deleteBindings)
      54         [ +  - ]:          12 :     query.addBindValue(binding);
      55   [ +  -  +  + ]:          17 :   if (!query.exec())
      56         [ +  - ]:           3 :     return fail();
      57                 :             : 
      58         [ +  - ]:          42 :   if (!query.exec(QStringLiteral("RELEASE SAVEPOINT %1")
      59   [ +  -  +  -  :          42 :                       .arg(QString::fromLatin1(savepoint))))
                   -  + ]
      60         [ #  # ]:           0 :     return fail();
      61                 :          14 :   return true;
      62                 :          17 : }
      63                 :             : 
      64                 :             : } // namespace DatabaseSync
        

Generated by: LCOV version 2.0-1