static bool delete_program(MSqlQuery &query, uint chanid, const QDateTime &st) { query.prepare( "DELETE from program " "WHERE chanid = :CHANID AND " " starttime = :STARTTIME"); query.bindValue(":CHANID", chanid); query.bindValue(":STARTTIME", st); if (!query.exec()) { MythDB::DBError("delete_program", query); return false; } query.prepare( "DELETE from credits " "WHERE chanid = :CHANID AND " " starttime = :STARTTIME"); query.bindValue(":CHANID", chanid); query.bindValue(":STARTTIME", st); if (!query.exec()) { MythDB::DBError("delete_credits", query); return false; } return true; }
void DatabaseLogger::prepare(MSqlQuery &query) { query.prepare(m_query); query.bindValue(":HOST", gCoreContext->GetHostName()); query.bindValue(":APP", QCoreApplication::applicationName()); query.bindValue(":PID", getpid()); }
void DBUtil::UnlockSchema(MSqlQuery &query) { query.prepare("SELECT RELEASE_LOCK('schemaLock')"); if (!query.exec()) { MythDB::DBError("DBUtil UnlockSchema", query); } }
void UPnpCDSMusic::BuildItemQuery( MSqlQuery &query, const QStringMap &mapParams ) { int nId = mapParams[ "Id" ].toInt(); QString sSQL = QString( "%1 WHERE song.song_id=:ID " ) .arg( GetItemListSQL() ); query.prepare( sSQL ); query.bindValue( ":ID", (int)nId ); }
uint DBPerson::InsertPersonDB(MSqlQuery &query) const { query.prepare( "INSERT IGNORE INTO people (name) " "VALUES (:NAME);"); query.bindValue(":NAME", name); if (query.exec()) return 1; MythDB::DBError("insert_person", query); return 0; }
void UPnpCDSTv::BuildItemQuery( MSqlQuery &query, const QStringMap &mapParams ) { int nChanId = mapParams[ "ChanId" ].toInt(); QString sStartTime = mapParams[ "StartTime" ]; QString sSQL = QString( "%1 WHERE chanid=:CHANID and starttime=:STARTTIME " ) .arg( GetItemListSQL() ); query.prepare( sSQL ); query.bindValue(":CHANID" , (int)nChanId ); query.bindValue(":STARTTIME", sStartTime ); }
static bool change_program(MSqlQuery &query, uint chanid, const QDateTime &st, const QDateTime &new_st, const QDateTime &new_end) { query.prepare( "UPDATE program " "SET starttime = :NEWSTART, " " endtime = :NEWEND " "WHERE chanid = :CHANID AND " " starttime = :OLDSTART"); query.bindValue(":CHANID", chanid); query.bindValue(":OLDSTART", st); query.bindValue(":NEWSTART", new_st); query.bindValue(":NEWEND", new_end); if (!query.exec()) { MythDB::DBError("change_program", query); return false; } query.prepare( "UPDATE credits " "SET starttime = :NEWSTART " "WHERE chanid = :CHANID AND " " starttime = :OLDSTART"); query.bindValue(":CHANID", chanid); query.bindValue(":OLDSTART", st); query.bindValue(":NEWSTART", new_st); if (!query.exec()) { MythDB::DBError("change_credits", query); return false; } return true; }
bool updateLastRunStatus(MSqlQuery &query, QString &status) { query.prepare("UPDATE settings SET data = :STATUS " "WHERE value='mythfilldatabaseLastRunStatus'"); query.bindValue(":STATUS", status); if (!query.exec()) { MythDB::DBError("updateLastRunStatus", query); return false; } return true; }
uint DBPerson::GetPersonDB(MSqlQuery &query) const { query.prepare( "SELECT person " "FROM people " "WHERE name = :NAME"); query.bindValue(":NAME", name); if (!query.exec()) MythDB::DBError("get_person", query); else if (query.next()) return query.value(0).toUInt(); return 0; }
bool updateLastRunStart(MSqlQuery &query) { QDateTime qdtNow = QDateTime::currentDateTime(); query.prepare("UPDATE settings SET data = :STARTTIME " "WHERE value='mythfilldatabaseLastRunStart'"); query.bindValue(":STARTTIME", qdtNow); if (!query.exec()) { MythDB::DBError("updateLastRunStart", query); return false; } return true; }
bool ProgramData::DeleteOverlaps( MSqlQuery &query, uint chanid, const ProgInfo &pi) { if (VERBOSE_LEVEL_CHECK(VB_XMLTV, LOG_INFO)) { // Get overlaps.. query.prepare( "SELECT title,starttime,endtime " "FROM program " "WHERE chanid = :CHANID AND " " starttime >= :START AND " " starttime < :END;"); query.bindValue(":CHANID", chanid); query.bindValue(":START", pi.starttime); query.bindValue(":END", pi.endtime); if (!query.exec()) return false; if (!query.next()) return true; do { LOG(VB_XMLTV, LOG_INFO, QString("Removing existing program: %1 - %2 %3 %4") .arg(query.value(1).toDateTime().toString(Qt::ISODate)) .arg(query.value(2).toDateTime().toString(Qt::ISODate)) .arg(pi.channel) .arg(query.value(0).toString())); } while (query.next()); } if (!ClearDataByChannel(chanid, pi.starttime, pi.endtime, false)) { LOG(VB_XMLTV, LOG_ERR, QString("Program delete failed : %1 - %2 %3 %4") .arg(pi.starttime.toString(Qt::ISODate)) .arg(pi.endtime.toString(Qt::ISODate)) .arg(pi.channel) .arg(pi.title)); return false; } return true; }
static bool program_exists(MSqlQuery &query, uint chanid, const QDateTime &st) { query.prepare( "SELECT title FROM program " "WHERE chanid = :CHANID AND " " starttime = :OLDSTART"); query.bindValue(":CHANID", chanid); query.bindValue(":OLDSTART", st); if (!query.exec()) { MythDB::DBError("program_exists", query); } if (query.next()) { return true; } return false; }
uint DBPerson::InsertCreditsDB(MSqlQuery &query, uint personid, uint chanid, const QDateTime &starttime) const { if (!personid) return 0; query.prepare( "REPLACE INTO credits " " ( person, chanid, starttime, role) " "VALUES (:PERSON, :CHANID, :STARTTIME, :ROLE) "); query.bindValue(":PERSON", personid); query.bindValue(":CHANID", chanid); query.bindValue(":STARTTIME", starttime); query.bindValue(":ROLE", GetRole()); if (query.exec()) return 1; MythDB::DBError("insert_credits", query); return 0; }
// Update matched item with current data. // uint DBEvent::UpdateDB( MSqlQuery &query, uint chanid, const DBEvent &match) const { QString ltitle = title; QString lsubtitle = subtitle; QString ldesc = description; QString lcategory = category; uint16_t lairdate = airdate; QString lprogramId = programId; QString lseriesId = seriesId; QString linetref = inetref; QDate loriginalairdate = originalairdate; if (match.title.length() >= ltitle.length()) ltitle = match.title; if (match.subtitle.length() >= lsubtitle.length()) lsubtitle = match.subtitle; if (match.description.length() >= ldesc.length()) ldesc = match.description; if (lcategory.isEmpty() && !match.category.isEmpty()) lcategory = match.category; if (!lairdate && !match.airdate) lairdate = match.airdate; if (!loriginalairdate.isValid() && match.originalairdate.isValid()) loriginalairdate = match.originalairdate; if (lprogramId.isEmpty() && !match.programId.isEmpty()) lprogramId = match.programId; if (lseriesId.isEmpty() && !match.seriesId.isEmpty()) lseriesId = match.seriesId; if (linetref.isEmpty() && !match.inetref.isEmpty()) linetref= match.inetref; ProgramInfo::CategoryType tmp = categoryType; if (!categoryType && match.categoryType) tmp = match.categoryType; QString lcattype = myth_category_type_to_string(tmp); unsigned char lsubtype = subtitleType | match.subtitleType; unsigned char laudio = audioProps | match.audioProps; unsigned char lvideo = videoProps | match.videoProps; uint lseason = match.season; uint lepisode = match.episode; uint lepisodeTotal = match.totalepisodes; if (season || episode || totalepisodes) { lseason = season; lepisode = episode; lepisodeTotal = totalepisodes; } uint lpartnumber = match.partnumber; uint lparttotal = match.parttotal; if (partnumber || parttotal) { lpartnumber = partnumber; lparttotal = parttotal; } bool lpreviouslyshown = previouslyshown | match.previouslyshown; uint32_t llistingsource = listingsource | match.listingsource; QString lsyndicatedepisodenumber = syndicatedepisodenumber; if (lsyndicatedepisodenumber.isEmpty() && !match.syndicatedepisodenumber.isEmpty()) lsyndicatedepisodenumber = match.syndicatedepisodenumber; query.prepare( "UPDATE program " "SET title = :TITLE, subtitle = :SUBTITLE, " " description = :DESC, " " category = :CATEGORY, category_type = :CATTYPE, " " starttime = :STARTTIME, endtime = :ENDTIME, " " closecaptioned = :CC, subtitled = :HASSUBTITLES, " " stereo = :STEREO, hdtv = :HDTV, " " subtitletypes = :SUBTYPE, " " audioprop = :AUDIOPROP, videoprop = :VIDEOPROP, " " season = :SEASON, " " episode = :EPISODE, totalepisodes = :TOTALEPS, " " partnumber = :PARTNO, parttotal = :PARTTOTAL, " " syndicatedepisodenumber = :SYNDICATENO, " " airdate = :AIRDATE, originalairdate=:ORIGAIRDATE, " " listingsource = :LSOURCE, " " seriesid = :SERIESID, programid = :PROGRAMID, " " previouslyshown = :PREVSHOWN, inetref = :INETREF " "WHERE chanid = :CHANID AND " " starttime = :OLDSTART "); query.bindValue(":CHANID", chanid); query.bindValue(":OLDSTART", match.starttime); query.bindValue(":TITLE", denullify(ltitle)); query.bindValue(":SUBTITLE", denullify(lsubtitle)); query.bindValue(":DESC", denullify(ldesc)); query.bindValue(":CATEGORY", denullify(lcategory)); query.bindValue(":CATTYPE", lcattype); query.bindValue(":STARTTIME", starttime); query.bindValue(":ENDTIME", endtime); query.bindValue(":CC", (lsubtype & SUB_HARDHEAR) ? true : false); query.bindValue(":HASSUBTITLES",(lsubtype & SUB_NORMAL) ? true : false); query.bindValue(":STEREO", (laudio & AUD_STEREO) ? true : false); query.bindValue(":HDTV", (lvideo & VID_HDTV) ? true : false); query.bindValue(":SUBTYPE", lsubtype); query.bindValue(":AUDIOPROP", laudio); query.bindValue(":VIDEOPROP", lvideo); query.bindValue(":SEASON", lseason); query.bindValue(":EPISODE", lepisode); query.bindValue(":TOTALEPS", lepisodeTotal); query.bindValue(":PARTNO", lpartnumber); query.bindValue(":PARTTOTAL", lparttotal); query.bindValue(":SYNDICATENO", denullify(lsyndicatedepisodenumber)); query.bindValue(":AIRDATE", lairdate ? QString::number(lairdate) : "0000"); query.bindValue(":ORIGAIRDATE", loriginalairdate); query.bindValue(":LSOURCE", llistingsource); query.bindValue(":SERIESID", denullify(lseriesId)); query.bindValue(":PROGRAMID", denullify(lprogramId)); query.bindValue(":PREVSHOWN", lpreviouslyshown); query.bindValue(":INETREF", linetref); if (!query.exec()) { MythDB::DBError("InsertDB", query); return 0; } if (credits) { for (uint i = 0; i < credits->size(); i++) (*credits)[i].InsertDB(query, chanid, starttime); } QList<EventRating>::const_iterator j = ratings.begin(); for (; j != ratings.end(); ++j) { query.prepare( "INSERT INTO programrating " " ( chanid, starttime, system, rating) " "VALUES (:CHANID, :START, :SYS, :RATING)"); query.bindValue(":CHANID", chanid); query.bindValue(":START", starttime); query.bindValue(":SYS", (*j).system); query.bindValue(":RATING", (*j).rating); if (!query.exec()) MythDB::DBError("programrating insert", query); } return 1; }
/// \brief Prepare the database query for use, and bind constant values to it. /// \param query The database query to prepare void DatabaseLogger::prepare(MSqlQuery &query) { query.prepare(m_query); query.bindValue(":HOST", gCoreContext->GetHostName()); }
int UPnpMedia::buildFileList(QString directory, int rootID, int itemID, MSqlQuery &query) { int parentid; QDir vidDir(directory); //VERBOSE(VB_UPNP, QString("buildFileList = %1, rootID = %2, itemID = //%3").arg(directory).arg(rootID).arg(itemID)); if (rootID > 0) parentid = rootID; else parentid = itemID; vidDir.setSorting( QDir::DirsFirst | QDir::Name ); QFileInfoList List = vidDir.entryInfoList(); // If we can't read it's contents move on if (List.isEmpty()) return itemID; for (QFileInfoList::iterator it = List.begin(); it != List.end(); ++it) { QFileInfo Info(*it); QString fName = Info.fileName(); QString fPath = Info.filePath(); // We don't want . or .. or something that specifically globs to // either. The "??" and "?" cases can happen when the backend is // running in a non-UTF-8 locale and comes across a UTF-8 filename if (fName == "." || fName == ".." || fName == "?" || fName == "??" || fName == ".?" || fName == "?.") continue; if (Info.isDir()) { // If we are about to recurse into the current directory (which // will cause an infinite recursive loop!), skip this entry. QDir subDir(fPath); if( subDir.canonicalPath() == vidDir.canonicalPath() ) continue; itemID++; query.prepare("INSERT INTO upnpmedia " "(intid, class, itemtype, parentid, itemproperties, " "filepath, filename, title, coverart) " "VALUES (:ITEMID, :ITEMCLASS, 'FOLDER', :PARENTID, '', " ":FILEPATH, :FILENAME, :TITLE, :COVERART)"); query.bindValue(":ITEMCLASS", sMediaType); query.bindValue(":ITEMID", itemID); query.bindValue(":PARENTID", parentid); query.bindValue(":FILEPATH", fPath); query.bindValue(":FILENAME", fName); query.bindValue(":TITLE", GetTitleName(fPath,fName)); query.bindValue(":COVERART", GetCoverArt(fPath)); if (!query.exec()) MythDB::DBError("UPnpMedia::buildFileList", query); itemID = buildFileList(fPath, 0, itemID, query); continue; } else { /* if (handler->validextensions.count() > 0) { QRegExp r; r.setPattern("^" + Info.suffix() + "$"); r.setCaseSensitive(false); QStringList result = handler->validextensions.grep(r); if (result.isEmpty()) { continue; } } */ itemID++; // VERBOSE(VB_UPNP, QString("UPnpMedia Video File : (%1) (%2)") // .arg(itemID) // .arg(fName)); query.prepare("INSERT INTO upnpmedia " "(intid, class, itemtype, parentid, itemproperties, " "filepath, filename, title, coverart) " "VALUES (:ITEMID, :ITEMCLASS, 'FILE', :PARENTID, '', " ":FILEPATH, :FILENAME, :TITLE, :COVERART)"); query.bindValue(":ITEMCLASS", sMediaType); query.bindValue(":ITEMID", itemID); query.bindValue(":PARENTID", parentid); query.bindValue(":FILEPATH", fPath); query.bindValue(":FILENAME", fName); query.bindValue(":TITLE", GetTitleName(fPath,fName)); query.bindValue(":COVERART", GetCoverArt(fPath)); if (!query.exec()) MythDB::DBError("UPnpMedia::buildFileList", query); } } return itemID; }
/** \brief Try to get a lock on the table schemalock. * Prevents multiple upgrades by different programs of the same schema. */ bool DBUtil::TryLockSchema(MSqlQuery &query, uint timeout_secs) { query.prepare("SELECT GET_LOCK('schemaLock', :TIMEOUT)"); query.bindValue(":TIMEOUT", timeout_secs); return query.exec() && query.first() && query.value(0).toBool(); }
bool ProgramData::IsUnchanged( MSqlQuery &query, uint chanid, const ProgInfo &pi) { query.prepare( "SELECT count(*) " "FROM program " "WHERE chanid = :CHANID AND " " starttime = :START AND " " endtime = :END AND " " title = :TITLE AND " " subtitle = :SUBTITLE AND " " description = :DESC AND " " category = :CATEGORY AND " " category_type = :CATEGORY_TYPE AND " " airdate = :AIRDATE AND " " stars >= (:STARS1 - 0.001) AND " " stars <= (:STARS2 + 0.001) AND " " previouslyshown = :PREVIOUSLYSHOWN AND " " title_pronounce = :TITLE_PRONOUNCE AND " " audioprop = :AUDIOPROP AND " " videoprop = :VIDEOPROP AND " " subtitletypes = :SUBTYPES AND " " partnumber = :PARTNUMBER AND " " parttotal = :PARTTOTAL AND " " seriesid = :SERIESID AND " " showtype = :SHOWTYPE AND " " colorcode = :COLORCODE AND " " syndicatedepisodenumber = :SYNDICATEDEPISODENUMBER AND " " programid = :PROGRAMID"); QString cattype = myth_category_type_to_string(pi.categoryType); query.bindValue(":CHANID", chanid); query.bindValue(":START", pi.starttime); query.bindValue(":END", pi.endtime); query.bindValue(":TITLE", pi.title); query.bindValue(":SUBTITLE", pi.subtitle); query.bindValue(":DESC", pi.description); query.bindValue(":CATEGORY", pi.category); query.bindValue(":CATEGORY_TYPE", cattype); query.bindValue(":AIRDATE", pi.airdate); query.bindValue(":STARS1", pi.stars); query.bindValue(":STARS2", pi.stars); query.bindValue(":PREVIOUSLYSHOWN", pi.previouslyshown); query.bindValue(":TITLE_PRONOUNCE", pi.title_pronounce); query.bindValue(":AUDIOPROP", pi.audioProps); query.bindValue(":VIDEOPROP", pi.videoProps); query.bindValue(":SUBTYPES", pi.subtitleType); query.bindValue(":PARTNUMBER", pi.partnumber); query.bindValue(":PARTTOTAL", pi.parttotal); query.bindValue(":SERIESID", pi.seriesId); query.bindValue(":SHOWTYPE", pi.showtype); query.bindValue(":COLORCODE", pi.colorcode); query.bindValue(":SYNDICATEDEPISODENUMBER", pi.syndicatedepisodenumber); query.bindValue(":PROGRAMID", pi.programId); if (query.exec() && query.next()) return query.value(0).toUInt() > 0; return false; }
uint ProgInfo::InsertDB(MSqlQuery &query, uint chanid) const { LOG(VB_XMLTV, LOG_INFO, QString("Inserting new program : %1 - %2 %3 %4") .arg(starttime.toString(Qt::ISODate)) .arg(endtime.toString(Qt::ISODate)) .arg(channel) .arg(title)); query.prepare( "REPLACE INTO program (" " chanid, title, subtitle, description, " " category, category_type, " " starttime, endtime, " " closecaptioned, stereo, hdtv, subtitled, " " subtitletypes, audioprop, videoprop, " " partnumber, parttotal, " " syndicatedepisodenumber, " " airdate, originalairdate,listingsource, " " seriesid, programid, previouslyshown, " " stars, showtype, title_pronounce, colorcode ) " "VALUES(" " :CHANID, :TITLE, :SUBTITLE, :DESCRIPTION, " " :CATEGORY, :CATTYPE, " " :STARTTIME, :ENDTIME, " " :CC, :STEREO, :HDTV, :HASSUBTITLES, " " :SUBTYPES, :AUDIOPROP, :VIDEOPROP, " " :PARTNUMBER, :PARTTOTAL, " " :SYNDICATENO, " " :AIRDATE, :ORIGAIRDATE, :LSOURCE, " " :SERIESID, :PROGRAMID, :PREVSHOWN, " " :STARS, :SHOWTYPE, :TITLEPRON, :COLORCODE)"); QString cattype = myth_category_type_to_string(categoryType); query.bindValue(":CHANID", chanid); query.bindValue(":TITLE", title); query.bindValue(":SUBTITLE", subtitle); query.bindValue(":DESCRIPTION", description); query.bindValue(":CATEGORY", category); query.bindValue(":CATTYPE", cattype); query.bindValue(":STARTTIME", starttime); query.bindValue(":ENDTIME", endtime); query.bindValue(":CC", subtitleType & SUB_HARDHEAR ? true : false); query.bindValue(":STEREO", audioProps & AUD_STEREO ? true : false); query.bindValue(":HDTV", videoProps & VID_HDTV ? true : false); query.bindValue(":HASSUBTITLES", subtitleType & SUB_NORMAL ? true : false); query.bindValue(":SUBTYPES", subtitleType); query.bindValue(":AUDIOPROP", audioProps); query.bindValue(":VIDEOPROP", videoProps); query.bindValue(":PARTNUMBER", partnumber); query.bindValue(":PARTTOTAL", parttotal); query.bindValue(":SYNDICATENO", syndicatedepisodenumber); query.bindValue(":AIRDATE", airdate ? QString::number(airdate):"0000"); query.bindValue(":ORIGAIRDATE", originalairdate); query.bindValue(":LSOURCE", listingsource); query.bindValue(":SERIESID", seriesId); query.bindValue(":PROGRAMID", programId); query.bindValue(":PREVSHOWN", previouslyshown); query.bindValue(":STARS", stars); query.bindValue(":SHOWTYPE", showtype); query.bindValue(":TITLEPRON", title_pronounce); query.bindValue(":COLORCODE", colorcode); if (!query.exec()) { MythDB::DBError("program insert", query); return 0; } QList<EventRating>::const_iterator j = ratings.begin(); for (; j != ratings.end(); ++j) { query.prepare( "INSERT INTO programrating " " ( chanid, starttime, system, rating) " "VALUES (:CHANID, :START, :SYS, :RATING)"); query.bindValue(":CHANID", chanid); query.bindValue(":START", starttime); query.bindValue(":SYS", (*j).system); query.bindValue(":RATING", (*j).rating); if (!query.exec()) MythDB::DBError("programrating insert", query); } if (credits) { for (uint i = 0; i < credits->size(); ++i) (*credits)[i].InsertDB(query, chanid, starttime); } return 1; }
uint DBEvent::InsertDB(MSqlQuery &query, uint chanid) const { query.prepare( "REPLACE INTO program (" " chanid, title, subtitle, description, " " category, category_type, " " starttime, endtime, " " closecaptioned, stereo, hdtv, subtitled, " " subtitletypes, audioprop, videoprop, " " stars, partnumber, parttotal, " " syndicatedepisodenumber, " " airdate, originalairdate,listingsource, " " seriesid, programid, previouslyshown ) " "VALUES (" " :CHANID, :TITLE, :SUBTITLE, :DESCRIPTION, " " :CATEGORY, :CATTYPE, " " :STARTTIME, :ENDTIME, " " :CC, :STEREO, :HDTV, :HASSUBTITLES, " " :SUBTYPES, :AUDIOPROP, :VIDEOPROP, " " :STARS, :PARTNUMBER, :PARTTOTAL, " " :SYNDICATENO, " " :AIRDATE, :ORIGAIRDATE, :LSOURCE, " " :SERIESID, :PROGRAMID, :PREVSHOWN) "); QString cattype = myth_category_type_to_string(categoryType); query.bindValue(":CHANID", chanid); query.bindValue(":TITLE", title); query.bindValue(":SUBTITLE", subtitle); query.bindValue(":DESCRIPTION", description); query.bindValue(":CATEGORY", category); query.bindValue(":CATTYPE", cattype); query.bindValue(":STARTTIME", starttime); query.bindValue(":ENDTIME", endtime); query.bindValue(":CC", subtitleType & SUB_HARDHEAR ? true : false); query.bindValue(":STEREO", audioProps & AUD_STEREO ? true : false); query.bindValue(":HDTV", videoProps & VID_HDTV ? true : false); query.bindValue(":HASSUBTITLES",subtitleType & SUB_NORMAL ? true : false); query.bindValue(":SUBTYPES", subtitleType); query.bindValue(":AUDIOPROP", audioProps); query.bindValue(":VIDEOPROP", videoProps); query.bindValue(":STARS", stars); query.bindValue(":PARTNUMBER", partnumber); query.bindValue(":PARTTOTAL", parttotal); query.bindValue(":SYNDICATENO", syndicatedepisodenumber); query.bindValue(":AIRDATE", airdate ? QString::number(airdate):"0000"); query.bindValue(":ORIGAIRDATE", originalairdate); query.bindValue(":LSOURCE", listingsource); query.bindValue(":SERIESID", seriesId); query.bindValue(":PROGRAMID", programId); query.bindValue(":PREVSHOWN", previouslyshown); if (!query.exec()) { MythDB::DBError("InsertDB", query); return 0; } if (credits) { for (uint i = 0; i < credits->size(); i++) (*credits)[i].InsertDB(query, chanid, starttime); } return 1; }
uint DBEvent::UpdateDB( MSqlQuery &query, uint chanid, const DBEvent &match) const { QString ltitle = title; QString lsubtitle = subtitle; QString ldesc = description; QString lcategory = category; uint16_t lairdate = airdate; QString lprogramId = programId; QString lseriesId = seriesId; QDate loriginalairdate = originalairdate; if (match.title.length() >= ltitle.length()) ltitle = match.title; if (match.subtitle.length() >= lsubtitle.length()) lsubtitle = match.subtitle; if (match.description.length() >= ldesc.length()) ldesc = match.description; if (lcategory.isEmpty() && !match.category.isEmpty()) lcategory = match.category; if (!lairdate && !match.airdate) lairdate = match.airdate; if (!loriginalairdate.isValid() && match.originalairdate.isValid()) loriginalairdate = match.originalairdate; if (lprogramId.isEmpty() && !match.programId.isEmpty()) lprogramId = match.programId; if (lseriesId.isEmpty() && !match.seriesId.isEmpty()) lseriesId = match.seriesId; uint tmp = categoryType; if (!categoryType && match.categoryType) tmp = match.categoryType; QString lcattype = myth_category_type_to_string(tmp); unsigned char lsubtype = subtitleType | match.subtitleType; unsigned char laudio = audioProps | match.audioProps; unsigned char lvideo = videoProps | match.videoProps; uint lpartnumber = (!partnumber && match.partnumber) ? match.partnumber : partnumber; uint lparttotal = (!parttotal && match.parttotal ) ? match.parttotal : parttotal; bool lpreviouslyshown = previouslyshown | match.previouslyshown; uint32_t llistingsource = listingsource | match.listingsource; QString lsyndicatedepisodenumber = syndicatedepisodenumber; if (lsyndicatedepisodenumber.isEmpty() && !match.syndicatedepisodenumber.isEmpty()) lsyndicatedepisodenumber = match.syndicatedepisodenumber; query.prepare( "UPDATE program " "SET title = :TITLE, subtitle = :SUBTITLE, " " description = :DESC, " " category = :CATEGORY, category_type = :CATTYPE, " " starttime = :STARTTIME, endtime = :ENDTIME, " " closecaptioned = :CC, subtitled = :HASSUBTITLES, " " stereo = :STEREO, hdtv = :HDTV, " " subtitletypes = :SUBTYPE, " " audioprop = :AUDIOPROP, videoprop = :VIDEOPROP, " " partnumber = :PARTNO, parttotal = :PARTTOTAL, " " syndicatedepisodenumber = :SYNDICATENO, " " airdate = :AIRDATE, originalairdate=:ORIGAIRDATE, " " listingsource = :LSOURCE, " " seriesid = :SERIESID, programid = :PROGRAMID, " " previouslyshown = :PREVSHOWN " "WHERE chanid = :CHANID AND " " starttime = :OLDSTART "); query.bindValue(":CHANID", chanid); query.bindValue(":OLDSTART", match.starttime); query.bindValue(":TITLE", ltitle); query.bindValue(":SUBTITLE", lsubtitle); query.bindValue(":DESC", ldesc); query.bindValue(":CATEGORY", lcategory); query.bindValue(":CATTYPE", lcattype); query.bindValue(":STARTTIME", starttime); query.bindValue(":ENDTIME", endtime); query.bindValue(":CC", lsubtype & SUB_HARDHEAR ? true : false); query.bindValue(":HASSUBTITLES",lsubtype & SUB_NORMAL ? true : false); query.bindValue(":STEREO", laudio & AUD_STEREO ? true : false); query.bindValue(":HDTV", lvideo & VID_HDTV ? true : false); query.bindValue(":SUBTYPE", lsubtype); query.bindValue(":AUDIOPROP", laudio); query.bindValue(":VIDEOPROP", lvideo); query.bindValue(":PARTNO", lpartnumber); query.bindValue(":PARTTOTAL", lparttotal); query.bindValue(":SYNDICATENO", lsyndicatedepisodenumber); query.bindValue(":AIRDATE", lairdate?QString::number(lairdate):"0000"); query.bindValue(":ORIGAIRDATE", loriginalairdate); query.bindValue(":LSOURCE", llistingsource); query.bindValue(":SERIESID", lseriesId); query.bindValue(":PROGRAMID", lprogramId); query.bindValue(":PREVSHOWN", lpreviouslyshown); if (!query.exec()) { MythDB::DBError("InsertDB", query); return 0; } if (credits) { for (uint i = 0; i < credits->size(); i++) (*credits)[i].InsertDB(query, chanid, starttime); } return 1; }
uint DBEvent::GetOverlappingPrograms( MSqlQuery &query, uint chanid, vector<DBEvent> &programs) const { uint count = 0; query.prepare( "SELECT title, subtitle, description, " " category, category_type, " " starttime, endtime, " " subtitletypes+0,audioprop+0, videoprop+0, " " seriesid, programid, " " partnumber, parttotal, " " syndicatedepisodenumber, " " airdate, originalairdate, " " previouslyshown,listingsource, " " stars+0 " "FROM program " "WHERE chanid = :CHANID AND " " manualid = 0 AND " " ( ( starttime >= :STIME1 AND starttime < :ETIME1 ) OR " " ( endtime > :STIME2 AND endtime <= :ETIME2 ) )"); query.bindValue(":CHANID", chanid); query.bindValue(":STIME1", starttime); query.bindValue(":ETIME1", endtime); query.bindValue(":STIME2", starttime); query.bindValue(":ETIME2", endtime); if (!query.exec()) { MythDB::DBError("GetOverlappingPrograms 1", query); return 0; } while (query.next()) { MythCategoryType category_type = string_to_myth_category_type(query.value(4).toString()); DBEvent prog( query.value(0).toString(), query.value(1).toString(), query.value(2).toString(), query.value(3).toString(), category_type, query.value(5).toDateTime(), query.value(6).toDateTime(), query.value(7).toUInt(), query.value(8).toUInt(), query.value(9).toUInt(), query.value(19).toDouble(), query.value(10).toString(), query.value(11).toString(), query.value(18).toUInt()); prog.partnumber = query.value(12).toUInt(); prog.parttotal = query.value(13).toUInt(); prog.syndicatedepisodenumber = query.value(14).toString(); prog.airdate = query.value(15).toUInt(); prog.originalairdate = query.value(16).toDate(); prog.previouslyshown = query.value(17).toBool(); ; programs.push_back(prog); count++; } return count; }