MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / migrateColumnsTable

Method migrateColumnsTable

app/src/Sessions/DatabaseManager.cpp:1401–1424  ·  view source on GitHub ↗

* @brief Adds source_id / source_title to legacy columns tables in older databases. */

Source from the content-addressed store, hash-verified

1399 * @brief Adds source_id / source_title to legacy columns tables in older databases.
1400 */
1401void Sessions::DatabaseManager::migrateColumnsTable(QSqlQuery& q)
1402{
1403 auto columnExists = [&q](const QString& column) {
1404 if (!q.exec(QStringLiteral("PRAGMA table_info(\"columns\")"))) {
1405 qWarning() << "[Sessions] PRAGMA table_info failed:" << q.lastError().text();
1406 return false;
1407 }
1408 while (q.next())
1409 if (q.value(1).toString().compare(column, Qt::CaseInsensitive) == 0)
1410 return true;
1411
1412 return false;
1413 };
1414
1415 if (!columnExists(QStringLiteral("source_id"))) {
1416 if (!q.exec("ALTER TABLE \"columns\" ADD COLUMN source_id INTEGER NOT NULL DEFAULT 0"))
1417 qWarning() << "[Sessions] ALTER add source_id failed:" << q.lastError().text();
1418 }
1419
1420 if (!columnExists(QStringLiteral("source_title"))) {
1421 if (!q.exec("ALTER TABLE \"columns\" ADD COLUMN source_title TEXT NOT NULL DEFAULT ''"))
1422 qWarning() << "[Sessions] ALTER add source_title failed:" << q.lastError().text();
1423 }
1424}
1425
1426/**
1427 * @brief Creates the per-sample tables (readings, raw_bytes, table_snapshots) and indexes.

Callers

nothing calls this directly

Calls 6

execMethod · 0.80
nextMethod · 0.80
textMethod · 0.45
lastErrorMethod · 0.45
compareMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected