mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-20 21:33:27 -07:00
Correctly check for database needs to be updated
* Correctly check for database needs to be updated * Double check whether database needs to be updated PR #18638.
This commit is contained in:
parent
38c0864bf2
commit
cbe9a27a92
1 changed files with 19 additions and 9 deletions
|
@ -272,7 +272,7 @@ BitTorrent::DBResumeDataStorage::DBResumeDataStorage(const Path &dbPath, QObject
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const int dbVersion = (!db.record(DB_TABLE_TORRENTS).contains(DB_COLUMN_DOWNLOAD_PATH.name) ? 1 : currentDBVersion());
|
const int dbVersion = (!db.record(DB_TABLE_TORRENTS).contains(DB_COLUMN_DOWNLOAD_PATH.name) ? 1 : currentDBVersion());
|
||||||
if (dbVersion != DB_VERSION)
|
if (dbVersion < DB_VERSION)
|
||||||
updateDB(dbVersion);
|
updateDB(dbVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -530,20 +530,30 @@ void BitTorrent::DBResumeDataStorage::updateDB(const int fromVersion) const
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (fromVersion == 1)
|
if (fromVersion == 1)
|
||||||
|
{
|
||||||
|
const auto testQuery = u"SELECT COUNT(%1) FROM %2;"_qs
|
||||||
|
.arg(quoted(DB_COLUMN_DOWNLOAD_PATH.name), quoted(DB_TABLE_TORRENTS));
|
||||||
|
if (!query.exec(testQuery))
|
||||||
{
|
{
|
||||||
const auto alterTableTorrentsQuery = u"ALTER TABLE %1 ADD %2"_qs
|
const auto alterTableTorrentsQuery = u"ALTER TABLE %1 ADD %2"_qs
|
||||||
.arg(quoted(DB_TABLE_TORRENTS), makeColumnDefinition(DB_COLUMN_DOWNLOAD_PATH, "TEXT"));
|
.arg(quoted(DB_TABLE_TORRENTS), makeColumnDefinition(DB_COLUMN_DOWNLOAD_PATH, "TEXT"));
|
||||||
if (!query.exec(alterTableTorrentsQuery))
|
if (!query.exec(alterTableTorrentsQuery))
|
||||||
throw RuntimeError(query.lastError().text());
|
throw RuntimeError(query.lastError().text());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (fromVersion <= 2)
|
if (fromVersion <= 2)
|
||||||
|
{
|
||||||
|
const auto testQuery = u"SELECT COUNT(%1) FROM %2;"_qs
|
||||||
|
.arg(quoted(DB_COLUMN_STOP_CONDITION.name), quoted(DB_TABLE_TORRENTS));
|
||||||
|
if (!query.exec(testQuery))
|
||||||
{
|
{
|
||||||
const auto alterTableTorrentsQuery = u"ALTER TABLE %1 ADD %2"_qs
|
const auto alterTableTorrentsQuery = u"ALTER TABLE %1 ADD %2"_qs
|
||||||
.arg(quoted(DB_TABLE_TORRENTS), makeColumnDefinition(DB_COLUMN_STOP_CONDITION, "TEXT NOT NULL DEFAULT `None`"));
|
.arg(quoted(DB_TABLE_TORRENTS), makeColumnDefinition(DB_COLUMN_STOP_CONDITION, "TEXT NOT NULL DEFAULT `None`"));
|
||||||
if (!query.exec(alterTableTorrentsQuery))
|
if (!query.exec(alterTableTorrentsQuery))
|
||||||
throw RuntimeError(query.lastError().text());
|
throw RuntimeError(query.lastError().text());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const QString updateMetaVersionQuery = makeUpdateStatement(DB_TABLE_META, {DB_COLUMN_NAME, DB_COLUMN_VALUE});
|
const QString updateMetaVersionQuery = makeUpdateStatement(DB_TABLE_META, {DB_COLUMN_NAME, DB_COLUMN_VALUE});
|
||||||
if (!query.prepare(updateMetaVersionQuery))
|
if (!query.prepare(updateMetaVersionQuery))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue