* @brief Inserts a new session row. */
| 272 | * @brief Inserts a new session row. |
| 273 | */ |
| 274 | void Sessions::ExportWorker::insertSession(const DataModel::Frame& frame, const QDateTime& dt) |
| 275 | { |
| 276 | if (!m_db) [[unlikely]] |
| 277 | return; |
| 278 | |
| 279 | const auto projectJson = |
| 280 | QString::fromUtf8(QJsonDocument(buildReplayProjectJson(frame)).toJson(QJsonDocument::Compact)); |
| 281 | |
| 282 | QSqlQuery q(*m_db); |
| 283 | q.prepare("INSERT INTO sessions " |
| 284 | "(project_title, started_at, project_json) " |
| 285 | "VALUES (?, ?, ?)"); |
| 286 | q.bindValue(0, frame.title); |
| 287 | q.bindValue(1, dt.toString(Qt::ISODate)); |
| 288 | q.bindValue(2, projectJson); |
| 289 | |
| 290 | if (!q.exec()) { |
| 291 | qWarning() << "[SQLite] Insert session failed:" << q.lastError().text(); |
| 292 | return; |
| 293 | } |
| 294 | |
| 295 | m_sessionId = q.lastInsertId().toInt(); |
| 296 | Q_EMIT sessionIdAssigned(m_sessionId); |
| 297 | } |
| 298 | |
| 299 | /** |
| 300 | * @brief Writes column definitions for the new session from the export schema. |