data/MailSortSql.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "MailSortSql.h" | ||
| 2 | |||
| 3 | #include "MailSort.h" | ||
| 4 | #include <QSqlDriver> | ||
| 5 | #include <sqlite3.h> | ||
| 6 | |||
| 7 | namespace { | ||
| 8 | 133777 | void sortKeyFunction(sqlite3_context *context, int, sqlite3_value **values) { | |
| 9 |
1/1✓ Branch 2 → 3 taken 133777 times.
|
133777 | const auto *text = reinterpret_cast<const char *>(sqlite3_value_text(values[1])); |
| 10 |
4/4✓ Branch 3 → 4 taken 127897 times.
✓ Branch 3 → 6 taken 5880 times.
✓ Branch 4 → 5 taken 127897 times.
✓ Branch 5 → 7 taken 127897 times.
|
133777 | const QString value = text ? QString::fromUtf8(text, sqlite3_value_bytes(values[1])) : QString(); |
| 11 |
6/6✓ Branch 7 → 8 taken 133777 times.
✓ Branch 8 → 9 taken 48841 times.
✓ Branch 8 → 10 taken 84936 times.
✓ Branch 9 → 11 taken 48841 times.
✓ Branch 10 → 11 taken 84936 times.
✓ Branch 11 → 12 taken 133777 times.
|
133777 | const QByteArray folded = (sqlite3_value_int(values[0]) == 2 ? MailSort::subjectKey(value) : MailSort::personKey(value)).toUtf8(); |
| 12 |
1/1✓ Branch 15 → 16 taken 133777 times.
|
133777 | sqlite3_result_text(context, folded.constData(), int(folded.size()), SQLITE_TRANSIENT); |
| 13 | 133777 | } | |
| 14 | 6599 | void descendingKeyFunction(sqlite3_context *context, int, sqlite3_value **values) { | |
| 15 |
1/1✓ Branch 2 → 3 taken 6599 times.
|
6599 | const auto *text = static_cast<const char *>(sqlite3_value_blob(values[0])); |
| 16 |
4/5✓ Branch 3 → 4 taken 6599 times.
✓ Branch 4 → 5 taken 6599 times.
✗ Branch 4 → 6 not taken.
✓ Branch 7 → 8 taken 6599 times.
✓ Branch 8 → 9 taken 6599 times.
|
6599 | const QByteArray reversed = MailSort::descendingKey(QByteArray(text ? text : "", sqlite3_value_bytes(values[0]))); |
| 17 |
1/1✓ Branch 12 → 13 taken 6599 times.
|
6599 | sqlite3_result_blob(context, reversed.constData(), int(reversed.size()), SQLITE_TRANSIENT); |
| 18 | 6599 | } | |
| 19 | } // namespace | ||
| 20 | |||
| 21 | 5094 | void MailSort::registerSqlFunctions(QSqlDatabase &db) { | |
| 22 |
2/2✓ Branch 2 → 3 taken 5094 times.
✓ Branch 3 → 4 taken 5094 times.
|
5094 | const auto handle = db.driver()->handle(); |
| 23 |
9/21✓ Branch 4 → 5 taken 5094 times.
✓ Branch 5 → 6 taken 5094 times.
✗ Branch 5 → 12 not taken.
✓ Branch 8 → 9 taken 5094 times.
✓ Branch 9 → 10 taken 5094 times.
✗ Branch 11 → 12 not taken.
✓ Branch 11 → 13 taken 5094 times.
✓ Branch 14 → 15 taken 5094 times.
✗ Branch 14 → 16 not taken.
✓ Branch 16 → 17 taken 5094 times.
✗ Branch 16 → 18 not taken.
✓ Branch 18 → 19 taken 5094 times.
✗ Branch 18 → 20 not taken.
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 5094 times.
✗ Branch 34 → 35 not taken.
✗ Branch 34 → 36 not taken.
✗ Branch 38 → 39 not taken.
✗ Branch 38 → 40 not taken.
✗ Branch 42 → 43 not taken.
✗ Branch 42 → 44 not taken.
|
5094 | if (!handle.isValid() || QByteArray(handle.typeName()) != QByteArrayLiteral("sqlite3*")) return; |
| 24 | 5094 | auto *connection = *static_cast<sqlite3 **>(const_cast<void *>(handle.constData())); | |
| 25 |
1/2✗ Branch 23 → 24 not taken.
✓ Branch 23 → 25 taken 5094 times.
|
5094 | if (!connection) return; |
| 26 |
1/1✓ Branch 25 → 26 taken 5094 times.
|
5094 | sqlite3_create_function_v2(connection, "mailjd_sort_key", 2, SQLITE_UTF8 | SQLITE_DETERMINISTIC, |
| 27 | nullptr, sortKeyFunction, nullptr, nullptr, nullptr); | ||
| 28 |
1/1✓ Branch 26 → 27 taken 5094 times.
|
5094 | sqlite3_create_function_v2(connection, "mailjd_desc_key", 1, SQLITE_UTF8 | SQLITE_DETERMINISTIC, |
| 29 | nullptr, descendingKeyFunction, nullptr, nullptr, nullptr); | ||
| 30 | 5094 | } | |
| 31 |