From 772b317648e206af6b057abd5b1e6e7f10e2dee4 Mon Sep 17 00:00:00 2001 From: Klaas de Waal Date: Sun, 1 Dec 2024 16:20:39 +0100 Subject: [PATCH] ChannelUtil function GetChannelNumber Add function GetChannelNumber to retrieve the channel number for a given video source ID and the channel name. The channel name is truncated to the first 64 characters because that is the length of the name field in table channel. --- mythtv/libs/libmythtv/channelutil.cpp | 23 +++++++++++++++++++++++ mythtv/libs/libmythtv/channelutil.h | 3 +++ 2 files changed, 26 insertions(+) diff --git a/mythtv/libs/libmythtv/channelutil.cpp b/mythtv/libs/libmythtv/channelutil.cpp index 06024846b20..d5a6d9aad8c 100644 --- a/mythtv/libs/libmythtv/channelutil.cpp +++ b/mythtv/libs/libmythtv/channelutil.cpp @@ -988,6 +988,29 @@ int ChannelUtil::GetChannelValueInt(const QString &channel_field, return (retval) ? retval : -1; } +QString ChannelUtil::GetChannelNumber(uint sourceid, const QString &channel_name) +{ + if (channel_name.isEmpty()) + return {}; + + MSqlQuery query(MSqlQuery::InitCon()); + query.prepare("SELECT channum FROM channel WHERE sourceid = :SOURCEID " + "AND name = :NAME " + "AND deleted IS NULL;" ); + query.bindValue(":SOURCEID", sourceid); + query.bindValue(":NAME", channel_name.left(64)); // Field channel.name is 64 characters + if (!query.exec()) + { + MythDB::DBError("GetChannelNumber", query); + return {}; + } + + if (!query.next()) + return {}; + + return query.value(0).toString(); +} + bool ChannelUtil::IsOnSameMultiplex(uint srcid, const QString &new_channum, const QString &old_channum) diff --git a/mythtv/libs/libmythtv/channelutil.h b/mythtv/libs/libmythtv/channelutil.h index 95b11725112..066e380eef4 100644 --- a/mythtv/libs/libmythtv/channelutil.h +++ b/mythtv/libs/libmythtv/channelutil.h @@ -289,6 +289,9 @@ class MTV_PUBLIC ChannelUtil uint sourceid, const QString &channum); + static QString GetChannelNumber(uint sourceid, + const QString &channel_name); + static bool IsOnSameMultiplex(uint srcid, const QString &new_channum, const QString &old_channum);