int CEpgDatabase::Persist(const CEpg &epg, bool bQueueWrite /* = false */) { int iReturn = -1; CStdString strQuery; if (epg.EpgID() > 0) { strQuery = FormatSQL("REPLACE INTO epg (idEpg, sName, sScraperName) " "VALUES (%u, '%s', '%s');", epg.EpgID(), epg.Name().c_str(), epg.ScraperName().c_str()); } else { strQuery = FormatSQL("REPLACE INTO epg (sName, sScraperName) " "VALUES ('%s', '%s');", epg.Name().c_str(), epg.ScraperName().c_str()); } if (bQueueWrite) { if (QueueInsertQuery(strQuery)) iReturn = epg.EpgID() <= 0 ? 0 : epg.EpgID(); } else { if (ExecuteQuery(strQuery)) iReturn = epg.EpgID() <= 0 ? (int) m_pDS->lastinsertid() : epg.EpgID(); } return iReturn; }
void CEpgContainer::InsertFromDatabase(int iEpgID, const CStdString &strName, const CStdString &strScraperName) { // table might already have been created when pvr channels were loaded CEpg* epg = GetById(iEpgID); if (epg) { if (!epg->Name().Equals(strName) || !epg->ScraperName().Equals(strScraperName)) { // current table data differs from the info in the db epg->SetChanged(); SetChanged(); } } else { // create a new epg table epg = new CEpg(iEpgID, strName, strScraperName, true); if (epg) { m_epgs.insert(make_pair(iEpgID, epg)); SetChanged(); epg->RegisterObserver(this); } } }