* @brief Opens a main-thread @c QSqlDatabase connection used for per-frame queries. */
| 453 | * @brief Opens a main-thread @c QSqlDatabase connection used for per-frame queries. |
| 454 | */ |
| 455 | bool Sessions::Player::openLocalDb(const QString& filePath) |
| 456 | { |
| 457 | m_connectionName = QStringLiteral("ss_sqlite_player_%1").arg(QDateTime::currentMSecsSinceEpoch()); |
| 458 | |
| 459 | m_db.emplace(QSqlDatabase::addDatabase("QSQLITE", m_connectionName)); |
| 460 | m_db->setDatabaseName(filePath); |
| 461 | if (!m_db->open()) { |
| 462 | Misc::Utilities::showMessageBox(tr("Cannot open session file"), |
| 463 | tr("Check file permissions and try again."), |
| 464 | QMessageBox::Critical); |
| 465 | const QString conn = m_connectionName; |
| 466 | m_db.reset(); |
| 467 | if (!conn.isEmpty()) |
| 468 | QSqlDatabase::removeDatabase(conn); |
| 469 | |
| 470 | m_connectionName.clear(); |
| 471 | return false; |
| 472 | } |
| 473 | |
| 474 | QSqlQuery pragma(*m_db); |
| 475 | pragma.exec("PRAGMA journal_mode=WAL"); |
| 476 | pragma.exec("PRAGMA busy_timeout=5000"); |
| 477 | |
| 478 | detectFinalValueColumns(); |
| 479 | return true; |
| 480 | } |
| 481 | |
| 482 | /** |
| 483 | * @brief Probes the readings schema for the final-value columns (absent in old session files). |