Skip to content

Commit

Permalink
MythMusic: Fix coverity ID 703848 Structurally dead code
Browse files Browse the repository at this point in the history
In FileScanner::GetDirectoryId(): Code block is unreachable because of the
syntactic structure of the code. Re-factor the code to keep coverity happy
and add some comments to clarify what the code is doing.
  • Loading branch information
Paul Harrison committed Jun 9, 2013
1 parent f974b5d commit 974d7f6
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions mythplugins/mythmusic/mythmusic/filescanner.cpp
Expand Up @@ -167,28 +167,31 @@ int FileScanner::GetDirectoryId(const QString &directory, const int &parentid)
"WHERE path = :DIRECTORY ;");
query.bindValue(":DIRECTORY", directory);

if (query.exec() && query.next())
if (!query.exec())
{
return query.value(0).toInt();
MythDB::DBError("music select directory id", query);
return -1;
}
else

if (query.next())
{
query.prepare("INSERT INTO music_directories (path, parent_id) "
"VALUES (:DIRECTORY, :PARENTID);");
query.bindValue(":DIRECTORY", directory);
query.bindValue(":PARENTID", parentid);
// we have found the directory already in the DB
return query.value(0).toInt();
}

if (!query.exec() || !query.isActive()
|| query.numRowsAffected() <= 0)
{
MythDB::DBError("music insert directory", query);
return -1;
}
return query.lastInsertId().toInt();
// directory is not in the DB so insert it
query.prepare("INSERT INTO music_directories (path, parent_id) "
"VALUES (:DIRECTORY, :PARENTID);");
query.bindValue(":DIRECTORY", directory);
query.bindValue(":PARENTID", parentid);

if (!query.exec() || !query.isActive() || query.numRowsAffected() <= 0)
{
MythDB::DBError("music insert directory", query);
return -1;
}

MythDB::DBError("music select directory id", query);
return -1;
return query.lastInsertId().toInt();
}

/*!
Expand Down

0 comments on commit 974d7f6

Please sign in to comment.