From 334c4cf242b5c339c155739c7169483b1dbb5244 Mon Sep 17 00:00:00 2001 From: David Hampton Date: Wed, 3 Nov 2021 00:20:07 -0400 Subject: [PATCH] Replace MSqlQuery.bindValue(isNull()) with bindValueNoNull(). The latter also guarantees that a NULL isn't passed to SQL, is cleaner to read, and shares a single common call to QString::isNull(). --- mythtv/libs/libmyth/netutils.cpp | 16 ++++++-------- mythtv/libs/libmythmetadata/imagemanager.cpp | 4 ++-- mythtv/libs/libmythmetadata/videometadata.cpp | 22 +++++++++---------- mythtv/libs/libmythtv/cardutil.cpp | 2 +- mythtv/libs/libmythtv/metadataimagehelper.cpp | 6 ++--- mythtv/libs/libmythtv/mythvideoprofile.cpp | 6 ++--- 6 files changed, 27 insertions(+), 29 deletions(-) diff --git a/mythtv/libs/libmyth/netutils.cpp b/mythtv/libs/libmyth/netutils.cpp index 66f384b57bb..1445b6614b4 100644 --- a/mythtv/libs/libmyth/netutils.cpp +++ b/mythtv/libs/libmyth/netutils.cpp @@ -418,7 +418,7 @@ bool insertTreeArticleInDB(const QString &feedtitle, const QString &path, query.bindValue(":PATH", path); query.bindValue(":PATHTHUMB", paththumb); query.bindValue(":TITLE", item->GetTitle()); - query.bindValue(":SUBTITLE", item->GetSubtitle().isNull() ? "" : item->GetSubtitle()); + query.bindValueNoNull(":SUBTITLE", item->GetSubtitle()); query.bindValue(":DESCRIPTION", item->GetDescription()); query.bindValue(":URL", item->GetURL()); query.bindValue(":TYPE", type); @@ -434,16 +434,15 @@ bool insertTreeArticleInDB(const QString &feedtitle, const QString &path, query.bindValue(":TIME", time); query.bindValue(":RATING", item->GetRating()); query.bindValue(":FILESIZE", (qulonglong)item->GetFilesize()); - query.bindValue(":PLAYER", item->GetPlayer().isNull() ? "" : item->GetPlayer()); + query.bindValueNoNull(":PLAYER", item->GetPlayer()); query.bindValue(":PLAYERARGS", item->GetPlayerArguments().isEmpty() ? "" : item->GetPlayerArguments().join(" ")); - query.bindValue(":DOWNLOAD", item->GetDownloader().isNull() ? "" : - item->GetDownloader()); + query.bindValueNoNull(":DOWNLOAD", item->GetDownloader()); query.bindValue(":DOWNLOADARGS", item->GetDownloaderArguments().isEmpty() ? "" : item->GetDownloaderArguments().join(" ")); query.bindValue(":WIDTH", item->GetWidth()); query.bindValue(":HEIGHT", item->GetHeight()); - query.bindValue(":LANGUAGE", item->GetLanguage().isNull() ? "" : item->GetLanguage()); + query.bindValueNoNull(":LANGUAGE", item->GetLanguage()); query.bindValue(":PODCAST", false); query.bindValue(":DOWNLOADABLE", item->GetDownloadable()); query.bindValue(":CUSTOMHTML", item->GetCustomHTML()); @@ -773,16 +772,15 @@ bool insertRSSArticleInDB(const QString &feedtitle, ResultItem *item, query.bindValue(":TIME", time); query.bindValue(":RATING", item->GetRating()); query.bindValue(":FILESIZE", (qulonglong)item->GetFilesize()); - query.bindValue(":PLAYER", item->GetPlayer().isNull() ? "" : item->GetPlayer()); + query.bindValueNoNull(":PLAYER", item->GetPlayer()); query.bindValue(":PLAYERARGS", item->GetPlayerArguments().isEmpty() ? "" : item->GetPlayerArguments().join(" ")); - query.bindValue(":DOWNLOAD", item->GetDownloader().isNull() ? "" : - item->GetDownloader()); + query.bindValueNoNull(":DOWNLOAD", item->GetDownloader()); query.bindValue(":DOWNLOADARGS", item->GetDownloaderArguments().isEmpty() ? "" : item->GetDownloaderArguments().join(" ")); query.bindValue(":WIDTH", item->GetWidth()); query.bindValue(":HEIGHT", item->GetHeight()); - query.bindValue(":LANGUAGE", item->GetLanguage().isNull() ? "" : item->GetLanguage()); + query.bindValueNoNull(":LANGUAGE", item->GetLanguage()); query.bindValue(":DOWNLOADABLE", item->GetDownloadable()); query.bindValue(":COUNTRIES", item->GetCountries()); query.bindValue(":PODCAST", true); diff --git a/mythtv/libs/libmythmetadata/imagemanager.cpp b/mythtv/libs/libmythmetadata/imagemanager.cpp index a3998a59cbb..2690a16f01b 100644 --- a/mythtv/libs/libmythmetadata/imagemanager.cpp +++ b/mythtv/libs/libmythmetadata/imagemanager.cpp @@ -834,7 +834,7 @@ int ImageDb::InsertDbImage(ImageItemK &im, bool checkForDuplicate) const query.bindValue(":EXTENSION", im.m_extension); query.bindValue(":DATE", static_cast(im.m_date.count())); query.bindValue(":ORIENT", im.m_orientation); - query.bindValue(":COMMENT", im.m_comment.isNull() ? "" : im.m_comment); + query.bindValueNoNull(":COMMENT", im.m_comment); query.bindValue(":HIDDEN", im.m_isHidden); query.bindValue(":COVER", FS::DbId(im.m_userThumbnail)); @@ -878,7 +878,7 @@ bool ImageDb::UpdateDbImage(ImageItemK &im) const query.bindValue(":HIDDEN", im.m_isHidden); query.bindValue(":ORIENT", im.m_orientation); query.bindValue(":COVER", FS::DbId(im.m_userThumbnail)); - query.bindValue(":COMMENT", im.m_comment.isNull() ? "" : im.m_comment); + query.bindValueNoNull(":COMMENT", im.m_comment); if (query.exec()) return true; diff --git a/mythtv/libs/libmythmetadata/videometadata.cpp b/mythtv/libs/libmythmetadata/videometadata.cpp index ef6cc12604d..cc993333e91 100644 --- a/mythtv/libs/libmythmetadata/videometadata.cpp +++ b/mythtv/libs/libmythmetadata/videometadata.cpp @@ -698,13 +698,13 @@ void VideoMetadataImp::saveToDatabase() query.bindValue(":INTID", m_id); } - query.bindValue(":TITLE", m_title.isNull() ? "" : m_title); - query.bindValue(":SUBTITLE", m_subtitle.isNull() ? "" : m_subtitle); + query.bindValueNoNull(":TITLE", m_title); + query.bindValueNoNull(":SUBTITLE", m_subtitle); query.bindValue(":TAGLINE", m_tagline); - query.bindValue(":DIRECTOR", m_director.isNull() ? "" : m_director); + query.bindValueNoNull(":DIRECTOR", m_director); query.bindValue(":STUDIO", m_studio); query.bindValue(":PLOT", m_plot); - query.bindValue(":RATING", m_rating.isNull() ? "" : m_rating); + query.bindValueNoNull(":RATING", m_rating); query.bindValue(":YEAR", m_year); query.bindValue(":RELEASEDATE", m_releasedate); query.bindValue(":USERRATING", m_userrating); @@ -714,15 +714,15 @@ void VideoMetadataImp::saveToDatabase() query.bindValue(":EPISODE", m_episode); query.bindValue(":FILENAME", m_filename); query.bindValue(":HASH", m_hash); - query.bindValue(":TRAILER", m_trailer.isNull() ? "" : m_trailer); + query.bindValueNoNull(":TRAILER", m_trailer); query.bindValue(":SHOWLEVEL", m_showlevel); - query.bindValue(":COVERFILE", m_coverfile.isNull() ? "" : m_coverfile); - query.bindValue(":SCREENSHOT", m_screenshot.isNull() ? "" : m_screenshot); - query.bindValue(":BANNER", m_banner.isNull() ? "" : m_banner); - query.bindValue(":FANART", m_fanart.isNull() ? "" : m_fanart); - query.bindValue(":INETREF", m_inetref.isNull() ? "" : m_inetref); + query.bindValueNoNull(":COVERFILE", m_coverfile); + query.bindValueNoNull(":SCREENSHOT", m_screenshot); + query.bindValueNoNull(":BANNER", m_banner); + query.bindValueNoNull(":FANART", m_fanart); + query.bindValueNoNull(":INETREF", m_inetref); query.bindValue(":COLLECTION", m_collectionref); - query.bindValue(":HOMEPAGE", m_homepage.isNull() ? "" : m_homepage); + query.bindValueNoNull(":HOMEPAGE", m_homepage); query.bindValue(":BROWSE", m_browse); query.bindValue(":WATCHED", m_watched); query.bindValue(":HOST", m_host); diff --git a/mythtv/libs/libmythtv/cardutil.cpp b/mythtv/libs/libmythtv/cardutil.cpp index a44282d5e49..a5b4a68818e 100644 --- a/mythtv/libs/libmythtv/cardutil.cpp +++ b/mythtv/libs/libmythtv/cardutil.cpp @@ -1910,7 +1910,7 @@ int CardUtil::CreateCardInput(const uint inputid, query.bindValue(":CHANGERMODEL", changer_model); query.bindValue(":TUNECHAN", tunechan); query.bindValue(":STARTCHAN", startchan); - query.bindValue(":DISPLAYNAME", displayname.isNull() ? "" : displayname); + query.bindValueNoNull(":DISPLAYNAME", displayname); query.bindValue(":DISHNETEIT", dishnet_eit); query.bindValue(":RECPRIORITY", recpriority); query.bindValue(":QUICKTUNE", quicktune); diff --git a/mythtv/libs/libmythtv/metadataimagehelper.cpp b/mythtv/libs/libmythtv/metadataimagehelper.cpp index 9ac2ebe3158..5d72070232e 100644 --- a/mythtv/libs/libmythtv/metadataimagehelper.cpp +++ b/mythtv/libs/libmythtv/metadataimagehelper.cpp @@ -184,9 +184,9 @@ bool SetArtwork(const QString &inetref, query.bindValue(":INETREF", inetref); query.bindValue(":SEASON", season); query.bindValue(":HOST", host); - query.bindValue(":COVERART", coverart.isNull() ? "" : coverart); - query.bindValue(":FANART", fanart.isNull() ? "" : fanart); - query.bindValue(":BANNER", banner.isNull() ? "" : banner); + query.bindValueNoNull(":COVERART", coverart); + query.bindValueNoNull(":FANART", fanart); + query.bindValueNoNull(":BANNER", banner); if (!query.exec()) { diff --git a/mythtv/libs/libmythtv/mythvideoprofile.cpp b/mythtv/libs/libmythtv/mythvideoprofile.cpp index 75b3594dde9..a82a8110624 100644 --- a/mythtv/libs/libmythtv/mythvideoprofile.cpp +++ b/mythtv/libs/libmythtv/mythvideoprofile.cpp @@ -625,7 +625,7 @@ bool MythVideoProfile::SaveDB(uint GroupId, vector &Items) insert.bindValue(":GROUPID", GroupId); insert.bindValue(":PROFILEID", item.GetProfileID()); insert.bindValue(":VALUE", lit.key()); - insert.bindValue(":DATA", ((*lit).isNull()) ? "" : (*lit)); + insert.bindValueNoNull(":DATA", *lit); if (!insert.exec()) { MythDB::DBError("save_profile 2", insert); @@ -673,7 +673,7 @@ bool MythVideoProfile::SaveDB(uint GroupId, vector &Items) update.bindValue(":GROUPID", GroupId); update.bindValue(":PROFILEID", item.GetProfileID()); update.bindValue(":VALUE", lit.key()); - update.bindValue(":DATA", ((*lit).isNull()) ? "" : (*lit)); + update.bindValueNoNull(":DATA", *lit); if (!update.exec()) { MythDB::DBError("save_profile 5b", update); @@ -687,7 +687,7 @@ bool MythVideoProfile::SaveDB(uint GroupId, vector &Items) insert.bindValue(":GROUPID", GroupId); insert.bindValue(":PROFILEID", item.GetProfileID()); insert.bindValue(":VALUE", lit.key()); - insert.bindValue(":DATA", ((*lit).isNull()) ? "" : (*lit)); + insert.bindValueNoNull(":DATA", *lit); if (!insert.exec()) { MythDB::DBError("save_profile 4", insert);