Skip to content

Commit

Permalink
ChannelUtil function GetChannelNumber
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kmdewaal committed Dec 1, 2024
1 parent 80f447c commit 772b317
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
23 changes: 23 additions & 0 deletions mythtv/libs/libmythtv/channelutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions mythtv/libs/libmythtv/channelutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 772b317

Please sign in to comment.