Skip to content

Commit

Permalink
Replace MSqlQuery.bindValue(isNull()) with bindValueNoNull().
Browse files Browse the repository at this point in the history
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().
  • Loading branch information
linuxdude42 committed Nov 5, 2021
1 parent 8a6c077 commit 334c4cf
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 29 deletions.
16 changes: 7 additions & 9 deletions mythtv/libs/libmyth/netutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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());
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions mythtv/libs/libmythmetadata/imagemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ int ImageDb<FS>::InsertDbImage(ImageItemK &im, bool checkForDuplicate) const
query.bindValue(":EXTENSION", im.m_extension);
query.bindValue(":DATE", static_cast<qint64>(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));

Expand Down Expand Up @@ -878,7 +878,7 @@ bool ImageDb<FS>::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;
Expand Down
22 changes: 11 additions & 11 deletions mythtv/libs/libmythmetadata/videometadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/cardutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions mythtv/libs/libmythtv/metadataimagehelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand Down
6 changes: 3 additions & 3 deletions mythtv/libs/libmythtv/mythvideoprofile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ bool MythVideoProfile::SaveDB(uint GroupId, vector<MythVideoProfileItem> &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);
Expand Down Expand Up @@ -673,7 +673,7 @@ bool MythVideoProfile::SaveDB(uint GroupId, vector<MythVideoProfileItem> &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);
Expand All @@ -687,7 +687,7 @@ bool MythVideoProfile::SaveDB(uint GroupId, vector<MythVideoProfileItem> &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);
Expand Down

0 comments on commit 334c4cf

Please sign in to comment.