* @brief Closes the database and finalizes the current session. */
| 77 | * @brief Closes the database and finalizes the current session. |
| 78 | */ |
| 79 | void Sessions::ExportWorker::closeResources() |
| 80 | { |
| 81 | if (!m_dbOpen) |
| 82 | return; |
| 83 | |
| 84 | finalizeSession(); |
| 85 | |
| 86 | TableSnapshotEntry staleSnapshot; |
| 87 | while (m_snapshotQueue->try_dequeue(staleSnapshot)) { |
| 88 | } |
| 89 | |
| 90 | m_readingQuery.reset(); |
| 91 | m_rawBytesQuery.reset(); |
| 92 | m_tableSnapshotQuery.reset(); |
| 93 | |
| 94 | QString connName; |
| 95 | if (m_db) { |
| 96 | connName = m_db->connectionName(); |
| 97 | QSqlQuery checkpoint(*m_db); |
| 98 | checkpoint.exec("PRAGMA wal_checkpoint(RESTART)"); |
| 99 | m_db->close(); |
| 100 | } |
| 101 | |
| 102 | m_db.reset(); |
| 103 | if (!connName.isEmpty()) |
| 104 | QSqlDatabase::removeDatabase(connName); |
| 105 | |
| 106 | m_dbOpen = false; |
| 107 | m_sessionId = -1; |
| 108 | m_lastRawBytesNs = -1; |
| 109 | m_schema = DataModel::ExportSchema{}; |
| 110 | resetMonotonicClock(); |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * @brief Returns whether the database file is open. |
nothing calls this directly
no test coverage detected