bool CPVRDatabase::Persist(CPVRChannelGroup &group) { bool bReturn(false); if (group.GroupName().empty()) { CLog::LogF(LOGERROR, "Empty group name"); return bReturn; } std::string strQuery; bReturn = true; CSingleLock lock(m_critSection); { /* insert a new entry when this is a new group, or replace the existing one otherwise */ if (group.GroupID() <= 0) strQuery = PrepareSQL("INSERT INTO channelgroups (bIsRadio, iGroupType, sName, iLastWatched, bIsHidden, iPosition) VALUES (%i, %i, '%s', %u, %i, %i)", (group.IsRadio() ? 1 :0), group.GroupType(), group.GroupName().c_str(), static_cast<unsigned int>(group.LastWatched()), group.IsHidden(), group.GetPosition()); else strQuery = PrepareSQL("REPLACE INTO channelgroups (idGroup, bIsRadio, iGroupType, sName, iLastWatched, bIsHidden, iPosition) VALUES (%i, %i, %i, '%s', %u, %i, %i)", group.GroupID(), (group.IsRadio() ? 1 :0), group.GroupType(), group.GroupName().c_str(), static_cast<unsigned int>(group.LastWatched()), group.IsHidden(), group.GetPosition()); bReturn = ExecuteQuery(strQuery); /* set the group id if it was <= 0 */ if (bReturn && group.GroupID() <= 0) { CSingleLock lock(group.m_critSection); group.m_iGroupId = (int) m_pDS->lastinsertid(); } } /* only persist the channel data for the internal groups */ if (group.IsInternalGroup()) bReturn &= PersistChannels(group); /* persist the group member entries */ if (bReturn) bReturn = PersistGroupMembers(group); return bReturn; }
bool CPVRChannelGroups::Update(const CPVRChannelGroup &group, bool bUpdateFromClient /* = false */) { if (group.GroupName().empty() && group.GroupID() <= 0) return true; CPVRChannelGroupPtr updateGroup; { CSingleLock lock(m_critSection); // There can be only one internal group! Make sure we never push a new one! if (group.IsInternalGroup()) updateGroup = GetGroupAll(); // try to find the group by id if (!updateGroup && group.GroupID() > 0) updateGroup = GetById(group.GroupID()); // try to find the group by name if we didn't find it yet if (!updateGroup) updateGroup = GetByName(group.GroupName()); if (!updateGroup) { // create a new group if none was found. Copy the properties immediately // so the group doesn't get flagged as "changed" further down. updateGroup = CPVRChannelGroupPtr(new CPVRChannelGroup(group.IsRadio(), group.GroupID(), group.GroupName())); m_groups.push_back(updateGroup); } updateGroup->SetRadio(group.IsRadio()); updateGroup->SetGroupID(group.GroupID()); updateGroup->SetGroupName(group.GroupName()); updateGroup->SetGroupType(group.GroupType()); updateGroup->SetPosition(group.GetPosition()); // don't override properties we only store locally in our PVR database if (!bUpdateFromClient) { updateGroup->SetLastWatched(group.LastWatched()); updateGroup->SetHidden(group.IsHidden()); } } // sort groups SortGroups(); // persist changes if (bUpdateFromClient) return updateGroup->Persist(); return true; }
bool CPVRDatabase::Persist(CPVRChannelGroup &group) { bool bReturn(false); if (group.GroupName().IsEmpty()) { CLog::Log(LOGERROR, "%s - empty group name", __FUNCTION__); return bReturn; } CStdString strQuery; bReturn = true; { CSingleLock lock(group.m_critSection); /* insert a new entry when this is a new group, or replace the existing one otherwise */ if (group.GroupID() <= 0) strQuery = FormatSQL("INSERT INTO channelgroups (bIsRadio, iGroupType, sName) VALUES (%i, %i, '%s')", (group.IsRadio() ? 1 :0), group.GroupType(), group.GroupName().c_str()); else strQuery = FormatSQL("REPLACE INTO channelgroups (idGroup, bIsRadio, iGroupType, sName) VALUES (%i, %i, %i, '%s')", group.GroupID(), (group.IsRadio() ? 1 :0), group.GroupType(), group.GroupName().c_str()); bReturn = ExecuteQuery(strQuery); /* set the group id if it was <= 0 */ if (bReturn && group.GroupID() <= 0) group.m_iGroupId = (int) m_pDS->lastinsertid(); } /* only persist the channel data for the internal groups */ if (group.IsInternalGroup()) bReturn &= PersistChannels(group); /* persist the group member entries */ if (bReturn) bReturn = PersistGroupMembers(group); return bReturn; }
bool CPVRChannelGroups::Update(const CPVRChannelGroup &group, bool bSaveInDb) { if (group.GroupName().empty() && group.GroupID() <= 0) return true; CPVRChannelGroupPtr updateGroup; { CSingleLock lock(m_critSection); // try to find the group by id if (group.GroupID() > 0) updateGroup = GetById(group.GroupID()); // try to find the group by name if we didn't find it yet if (!updateGroup) updateGroup = GetByName(group.GroupName()); if (!updateGroup) { // create a new group if none was found updateGroup = CPVRChannelGroupPtr(new CPVRChannelGroup(m_bRadio, group.GroupID(), group.GroupName())); updateGroup->SetGroupType(group.GroupType()); updateGroup->SetLastWatched(group.LastWatched()); m_groups.push_back(updateGroup); } else { // update existing group updateGroup->SetGroupID(group.GroupID()); updateGroup->SetGroupName(group.GroupName()); updateGroup->SetGroupType(group.GroupType()); } } // persist changes if (bSaveInDb && updateGroup) return updateGroup->Persist(); return true; }