diff options
| author | tony mancill <tmancill@debian.org> | 2019-11-30 16:20:58 -0800 |
|---|---|---|
| committer | tony mancill <tmancill@debian.org> | 2019-11-30 16:20:58 -0800 |
| commit | 08299e8b2bf50ba90daf570f57def529dd29d6e7 (patch) | |
| tree | 475e23eab7be9717383c3c2252cacd8f3c4570c9 /models/FoxLog.cpp | |
| parent | 3d67be3023bf34eac7f93fa422f5ef569abb92a9 (diff) | |
New upstream version 2.1.2+repackupstream/2.1.2+repack
Diffstat (limited to 'models/FoxLog.cpp')
| -rw-r--r-- | models/FoxLog.cpp | 56 |
1 files changed, 46 insertions, 10 deletions
diff --git a/models/FoxLog.cpp b/models/FoxLog.cpp index 954090bd..ad02cd2b 100644 --- a/models/FoxLog.cpp +++ b/models/FoxLog.cpp @@ -47,6 +47,21 @@ public: #include "FoxLog.moc" +namespace +{ + QString const fox_log_ddl { + "CREATE %1 TABLE fox_log%2 (" + " id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL," + " \"when\" DATETIME NOT NULL," + " call VARCHAR(20) NOT NULL," + " grid VARCHAR(4)," + " report_sent VARCHAR(3)," + " report_rcvd VARCHAR(3)," + " band VARCHAR(6) NOT NULL" + ")" + }; +} + FoxLog::impl::impl (Configuration const * configuration) : configuration_ {configuration} { @@ -54,16 +69,37 @@ FoxLog::impl::impl (Configuration const * configuration) { QSqlQuery query; SQL_error_check (query, static_cast<bool (QSqlQuery::*) (QString const&)> (&QSqlQuery::exec), - "CREATE TABLE fox_log (" - " id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL," - " \"when\" DATETIME NOT NULL," - " call VARCHAR(20) NOT NULL," - " grid VARCHAR(4)," - " report_sent VARCHAR(3)," - " report_rcvd VARCHAR(3)," - " band VARCHAR(6) NOT NULL," - " CONSTRAINT no_dupes UNIQUE (call, band)" - ")"); + fox_log_ddl.arg ("").arg ("")); + } + else + { + QSqlQuery query; + // query to check if table has a unique constraint + SQL_error_check (query, static_cast<bool (QSqlQuery::*) (QString const&)> (&QSqlQuery::exec), + "SELECT COUNT(*)" + " FROM sqlite_master" + " WHERE" + " type = 'index' AND tbl_name = 'fox_log'"); + query.next (); + if (query.value (0).toInt ()) + { + // update to new schema with no dupe disallowing unique + // constraint + database ().transaction (); + SQL_error_check (query, static_cast<bool (QSqlQuery::*) (QString const&)> (&QSqlQuery::exec), + fox_log_ddl.arg ("TEMPORARY").arg ("_backup")); + SQL_error_check (query, static_cast<bool (QSqlQuery::*) (QString const&)> (&QSqlQuery::exec), + "INSERT INTO fox_log_backup SELECT * from fox_log"); + SQL_error_check (query, static_cast<bool (QSqlQuery::*) (QString const&)> (&QSqlQuery::exec), + "DROP TABLE fox_log"); + SQL_error_check (query, static_cast<bool (QSqlQuery::*) (QString const&)> (&QSqlQuery::exec), + fox_log_ddl.arg ("").arg ("")); + SQL_error_check (query, static_cast<bool (QSqlQuery::*) (QString const&)> (&QSqlQuery::exec), + "INSERT INTO fox_log SELECT * from fox_log_backup"); + SQL_error_check (query, static_cast<bool (QSqlQuery::*) (QString const&)> (&QSqlQuery::exec), + "DROP TABLE fox_log_backup"); + database ().commit (); + } } SQL_error_check (dupe_query_, &QSqlQuery::prepare, |
