Permalink
Browse files

Batch fix for unchecked instances of QSqlQuery::next(). Fixes multipl…

…e Coverity warnings.
  • Loading branch information...
1 parent b30825e commit 29ca55994609874f7645499cde1942095da0852b @stuartm stuartm committed May 24, 2012
View
3 mythplugins/mytharchive/mytharchive/logviewer.cpp
@@ -227,9 +227,8 @@ QString LogViewer::getSetting(const QString &key)
query.bindValue(":VALUE", key);
query.bindValue(":HOSTNAME", gCoreContext->GetHostName());
- if (query.exec() && query.isActive() && query.size() > 0)
+ if (query.exec() && query.next())
{
- query.next();
return query.value(0).toString();
}
}
View
3 mythplugins/mythmusic/mythmusic/metadata.cpp
@@ -194,9 +194,8 @@ bool Metadata::isInDatabase()
query.bindValue(":FILENAME", sqlfilename);
query.bindValue(":DIRECTORY", sqldir);
- if (query.exec() && query.isActive() && query.size() > 0)
+ if (query.exec() && query.next())
{
- query.next();
m_artist = query.value(0).toString();
m_compilation_artist = query.value(1).toString();
View
10 mythplugins/mythmusic/mythmusic/smartplaylist.cpp
@@ -896,7 +896,6 @@ void SmartPlaylistEditor::loadFromDatabase(QString category, QString name)
// load smartplaylist items
SmartPLCriteriaRow *row;
- uint rowCount;
query.prepare("SELECT field, operator, value1, value2 "
"FROM music_smartplaylist_items WHERE smartplaylistid = :ID "
@@ -905,12 +904,9 @@ void SmartPlaylistEditor::loadFromDatabase(QString category, QString name)
if (!query.exec())
MythDB::DBError("Load smartplaylist items", query);
- if (query.isActive() && query.size() > 0)
+ if (query.size() > 0)
{
- rowCount = query.size();
-
- query.first();
- for (uint x = 0; x < rowCount; x++)
+ while (query.next())
{
QString Field = query.value(0).toString();
QString Operator = query.value(1).toString();
@@ -920,8 +916,6 @@ void SmartPlaylistEditor::loadFromDatabase(QString category, QString name)
m_criteriaRows.append(row);
new MythUIButtonListItem(m_criteriaList, row->toString(), qVariantFromValue(row));
-
- query.next();
}
}
else
View
55 mythtv/libs/libmyth/netutils.cpp
@@ -347,20 +347,21 @@ bool needsUpdate(GrabberScript* script, uint updateFreq)
QDateTime lastUpdate(GrabberScript* script)
{
+ QDateTime updated;
MSqlQuery query(MSqlQuery::InitCon());
query.prepare("SELECT updated "
"FROM internetcontent "
"WHERE commandline = :COMMAND ORDER "
"BY updated DESC LIMIT 1;");
QFileInfo fi(script->GetCommandline());
query.bindValue(":COMMAND", fi.fileName());
- if (!query.exec() || !query.isActive()) {
+ if (!query.exec() || !query.isActive())
+ {
MythDB::DBError("Tree last update in db", query);
}
-
- query.next();
-
- QDateTime updated = query.value(0).toDateTime();
+ else if (query.next())
+ updated = query.value(0).toDateTime();
+
return updated;
}
@@ -374,7 +375,8 @@ bool clearTreeItems(const QString &feedcommand)
"WHERE feedtitle = :FEEDTITLE AND podcast = 0;");
query.bindValue(":FEEDTITLE", feedcommand);
- if (!query.exec() || !query.isActive()) {
+ if (!query.exec() || !query.isActive())
+ {
MythDB::DBError("netcontent: clearing DB", query);
return false;
}
@@ -393,7 +395,8 @@ bool isTreeInUse(const QString &feedcommand)
QFileInfo fi(feedcommand);
query.bindValue(":COMMAND", fi.fileName());
- if (!query.exec() || !query.isActive()) {
+ if (!query.exec() || !query.isActive())
+ {
MythDB::DBError("netcontent: isTreeInUse", query);
return false;
}
@@ -457,7 +460,8 @@ bool insertTreeArticleInDB(const QString &feedtitle, const QString &path,
query.bindValue(":SEASON", item->GetSeason());
query.bindValue(":EPISODE", item->GetEpisode());
- if (!query.exec() || !query.isActive()) {
+ if (!query.exec() || !query.isActive())
+ {
MythDB::DBError("netcontent: inserting article in DB", query);
return false;
}
@@ -481,7 +485,8 @@ QMultiMap<QPair<QString,QString>, ResultItem*> getTreeArticles(const QString &fe
"AND type = :TYPE ORDER BY title DESC;");
query.bindValue(":FEEDTITLE", feedtitle);
query.bindValue(":TYPE", type);
- if (!query.exec() || !query.isActive()) {
+ if (!query.exec() || !query.isActive())
+ {
MythDB::DBError("Tree find in db", query);
return ret;
}
@@ -544,33 +549,35 @@ bool findInDB(const QString& url, ArticleType type)
RSSSite* findByURL(const QString& url, ArticleType type)
{
+ RSSSite *tmp = NULL;
MSqlQuery query(MSqlQuery::InitCon());
query.prepare("SELECT name,thumbnail,author,description,"
"commandline,download,updated FROM internetcontent "
"WHERE commandline = :URL AND type = :TYPE "
"AND podcast = 1;");
query.bindValue(":URL", url);
query.bindValue(":TYPE", type);
- if (!query.exec() || !query.isActive()) {
+ if (!query.exec() || !query.next())
+ {
MythDB::DBError("RSS find in db", query);
- RSSSite *tmp = new RSSSite(QString(), QString(), (ArticleType)0, QString(),
- QString(), QString(), false,
- QDateTime());
- return tmp;
+ tmp = new RSSSite(QString(), QString(), (ArticleType)0, QString(),
+ QString(), QString(), false,
+ QDateTime());
}
else
- query.next();
+ {
+ QString title = query.value(0).toString();
+ QString image = query.value(1).toString();
+ QString author = query.value(2).toString();
+ QString description = query.value(3).toString();
+ QString outurl = query.value(4).toString();
+ bool download = query.value(5).toInt();
+ QDateTime updated; query.value(6).toDate();
- QString title = query.value(0).toString();
- QString image = query.value(1).toString();
- QString author = query.value(2).toString();
- QString description = query.value(3).toString();
- QString outurl = query.value(4).toString();
- bool download = query.value(5).toInt();
- QDateTime updated; query.value(6).toDate();
+ tmp = new RSSSite(title, image, type, description, outurl,
+ author, download, updated);
+ }
- RSSSite *tmp = new RSSSite(title, image, type, description, outurl,
- author, download, updated);
return tmp;
}
View
3 mythtv/libs/libmythprotoserver/requesthandler/fileserverhandler.cpp
@@ -74,9 +74,8 @@ QString FileServerHandler::LocalFilePath(const QUrl &url,
query.prepare("SELECT icon FROM channel WHERE icon LIKE :FILENAME ;");
query.bindValue(":FILENAME", QString("%/") + file);
- if (query.exec() && query.isActive() && query.size())
+ if (query.exec() && query.next())
{
- query.next();
lpath = query.value(0).toString();
}
else
View
6 mythtv/libs/libmythtv/channelbase.cpp
@@ -895,10 +895,9 @@ int ChannelBase::GetChanID() const
return -1;
}
- if (query.size() <= 0)
+ if (!query.next())
return -1;
- query.next();
return query.value(0).toInt();
}
@@ -1108,9 +1107,8 @@ bool ChannelBase::CheckChannel(const QString &channum,
{
MythDB::DBError("checkchannel", query);
}
- else if (query.size() > 0)
+ else if (query.next())
{
- query.next();
QString test = query.value(1).toString();
if (test != QString::null)
inputName = test;
View
14 mythtv/libs/libmythtv/channelgroupsettings.cpp
@@ -43,12 +43,12 @@ void ChannelGroupStorage::Load(void)
if (!query.exec() || !query.isActive())
MythDB::DBError("ChannelGroupStorage::Load", query);
- else
+ else if (query.next())
{
- query.next();
grpid = query.value(0).toUInt();
- qstr = "SELECT * FROM channelgroup WHERE grpid = :GRPID AND chanid = :CHANID";
+ qstr = "SELECT * FROM channelgroup WHERE grpid = :GRPID AND "
+ "chanid = :CHANID";
query.prepare(qstr);
query.bindValue(":GRPID", grpid);
query.bindValue(":CHANID", chanid);
@@ -188,8 +188,14 @@ void ChannelGroupEditor::doDelete(void)
query.prepare("SELECT grpid FROM channelgroupnames WHERE name = :NAME;");
query.bindValue(":NAME", name);
if (!query.exec())
+ {
MythDB::DBError("ChannelGroupEditor::doDelete", query);
- query.next();
+ return;
+ }
+
+ if (!query.next())
+ return;
+
uint grpid = query.value(0).toUInt();
// Delete channels from this group
View
27 mythtv/libs/libmythtv/channelutil.cpp
@@ -622,9 +622,8 @@ int ChannelUtil::GetBetterMplexID(int current_mplexid,
if (!query.exec() || !query.isActive())
MythDB::DBError("Getting mplexid global search", query);
- else if (query.size())
+ else if (query.next())
{
- query.next();
q_networkid = query.value(0).toInt();
q_transportid = query.value(1).toInt();
}
@@ -682,19 +681,17 @@ int ChannelUtil::GetBetterMplexID(int current_mplexid,
if (!query.exec() || !query.isActive())
MythDB::DBError("Finding matching mplexid", query);
- if (query.size() == 1)
+ if (query.size() == 1 && query.next())
{
LOG(VB_CHANSCAN, LOG_INFO,
QString("GetBetterMplexID(): query#%1 qsize(%2) "
"Returning %3")
.arg(i).arg(query.size()).arg(current_mplexid));
- query.next();
return query.value(0).toInt();
}
- if (query.size() > 1)
+ if (query.next())
{
- query.next();
int ret = (i==0) ? current_mplexid : query.value(0).toInt();
LOG(VB_CHANSCAN, LOG_INFO,
QString("GetBetterMplexID(): query#%1 qsize(%2) "
@@ -757,10 +754,10 @@ QString ChannelUtil::GetChannelStringField(int chan_id, const QString &field)
MythDB::DBError("Selecting channel/dtv_multiplex 1", query);
return QString::null;
}
- if (!query.size())
+
+ if (!query.next())
return QString::null;
-
- query.next();
+
return query.value(0).toString();
}
@@ -798,11 +795,9 @@ int ChannelUtil::GetSourceID(int db_mplexid)
return -1;
}
- if (query.size() > 0)
- {
- query.next();
+ if (query.next())
return query.value(0).toInt();
- }
+
return -1;
}
@@ -1798,11 +1793,9 @@ int ChannelUtil::GetServiceVersion(int mplexid)
return false;
}
- if (query.size() > 0)
- {
- query.next();
+ if (query.next())
return query.value(0).toInt();
- }
+
return -1;
}
View
3 mythtv/libs/libmythtv/dvbchannel.cpp
@@ -956,10 +956,9 @@ int DVBChannel::GetChanID() const
return -1;
}
- if (query.size() <= 0)
+ if (!query.next())
return -1;
- query.next();
return query.value(0).toInt();
}
View
5 mythtv/libs/libmythtv/recordingrule.cpp
@@ -726,7 +726,10 @@ unsigned RecordingRule::GetDefaultFilter(void)
MythDB::DBError("GetDefaultFilter", query);
return 0;
}
- query.next();
+
+ if (!query.next())
+ return 0;
+
return query.value(0).toUInt();
}
View
3 mythtv/libs/libmythtv/tv_rec.cpp
@@ -2085,13 +2085,12 @@ bool TVRec::ShouldSwitchToAnotherCard(QString chanid)
"FROM channel "
"WHERE channel.chanid = :CHANID");
query.bindValue(":CHANID", chanid);
- if (!query.exec() || !query.isActive() || query.size() == 0)
+ if (!query.exec() || !query.next())
{
MythDB::DBError("ShouldSwitchToAnotherCard", query);
return false;
}
- query.next();
QString channelname = query.value(0).toString();
QString callsign = query.value(1).toString();
View
3 mythtv/libs/libmythtv/videosource.cpp
@@ -675,9 +675,8 @@ bool VideoSourceEditor::cardTypesInclude(const int &sourceID,
query.bindValue(":SOURCEID", sourceID);
query.bindValue(":CARDTYPE", thecardtype);
- if (query.exec() && query.isActive() && query.size() > 0)
+ if (query.exec() && query.next())
{
- query.next();
int count = query.value(0).toInt();
if (count > 0)
View
14 mythtv/programs/mythfilldatabase/filldata.cpp
@@ -291,9 +291,8 @@ bool FillData::GrabDDData(Source source, int poffset,
#endif
query.prepare("SELECT count(*) from dd_v_program;");
- if (query.exec() && query.size() > 0)
+ if (query.exec() && query.next())
{
- query.next();
if (query.value(0).toInt() < 1)
{
LOG(VB_GENERAL, LOG_INFO, "Did not find any new program data.");
@@ -555,10 +554,8 @@ bool FillData::Run(SourceList &sourcelist)
"AND manualid = 0 AND c.xmltvid != '';");
query.bindValue(":SRCID", (*it).id);
- if (query.exec() && query.size() > 0)
+ if (query.exec() && query.next())
{
- query.next();
-
if (!query.isNull(0))
GuideDataBefore =
QDateTime::fromString(query.value(0).toString(),
@@ -604,9 +601,8 @@ bool FillData::Run(SourceList &sourcelist)
":SRCID AND xmltvid != ''");
query.bindValue(":SRCID", (*it).id);
- if (query.exec() && query.size() > 0)
+ if (query.exec() && query.next())
{
- query.next();
source_channels = query.value(0).toInt();
if (source_channels > 0)
{
@@ -966,10 +962,8 @@ bool FillData::Run(SourceList &sourcelist)
"AND manualid = 0 AND c.xmltvid != '';");
query.bindValue(":SRCID", (*it).id);
- if (query.exec() && query.size() > 0)
+ if (query.exec() && query.next())
{
- query.next();
-
if (!query.isNull(0))
GuideDataAfter = QDateTime::fromString(
query.value(0).toString(), Qt::ISODate);
View
3 mythtv/programs/mythtv-setup/checksetup.cpp
@@ -50,13 +50,12 @@ bool checkStoragePaths(QStringList &probs)
MSqlQuery query(MSqlQuery::InitCon());
query.prepare("SELECT count(groupname) FROM storagegroup;");
- if (!query.exec() || !query.isActive() || query.size() < 1)
+ if (!query.exec() || !query.next())
{
MythDB::DBError("checkStoragePaths", query);
return false;
}
- query.next();
if (query.value(0).toInt() == 0)
{
QString trMesg =

0 comments on commit 29ca559

Please sign in to comment.