From bd6ac8b88a6e128ad8778aad89f5d8c3f31148de Mon Sep 17 00:00:00 2001 From: horchi Date: Tue, 2 Oct 2018 19:21:14 +0200 Subject: 2018-10-02: version 1.1.143 (horchi)\n change: Fixed compile problem of epglv \n \n --- channelmap.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 60 insertions(+), 5 deletions(-) (limited to 'channelmap.c') diff --git a/channelmap.c b/channelmap.c index 9629227..c8a52d6 100644 --- a/channelmap.c +++ b/channelmap.c @@ -223,10 +223,7 @@ int cEpgd::updateMapRow(char* extid, const char* source, const char* chan, if (changed || insert) { tell(1, "Channel '%s' %s, source '%s', extid %s, merge %d", - chan, insert ? "inserted" : "updated", - source, - extid, - merge); + chan, insert ? "inserted" : "updated", source, extid, merge); mapDb->setValue("MERGESP", 0L); // reset mergesp! mapDb->setValue("UPDFLG", insert ? "I" : "U"); @@ -241,7 +238,7 @@ int cEpgd::updateMapRow(char* extid, const char* source, const char* chan, } else { - mapDb->setValue("UPDFLG", "S"); + mapDb->setValue("UPDFLG", "S"); // 'S'tay - no change } mapDb->store(); @@ -258,6 +255,64 @@ int cEpgd::applyChannelmapChanges() { connection->startTransaction(); + mapDb->clear(); + mapDb->setValue("UPDFLG", "D"); + + // search matching 'I'nserted rows for all 'D'eleted rows to check if only the channelid has changed + + for (int f = selectMapByUpdFlg->find(); f; f = selectMapByUpdFlg->fetch()) + { + std::string oldChannelId = mapDb->getStrValue("CHANNELID"); + + mapDb->setValue("UPDFLG", "I"); + + if (selectMapByExt->find()) + { + std::string newChannelId = mapDb->getStrValue("CHANNELID"); + + tell(0, "channelid '%s' was changed to '%s'", oldChannelId.c_str(), newChannelId.c_str()); + + // change the 'I'nserted row and remove the 'D'eleted row -> no further action is necessary later on + + mapDb->find(); + mapDb->setValue("UPDFLG", "S"); + mapDb->update(); + mapDb->deleteWhere("channelid = '%s' and extid = '%s' and source = '%s'", + oldChannelId.c_str(), mapDb->getStrValue("EXTERNALID"), mapDb->getStrValue("SOURCE")); + + // now patch tables with channelid field + + std::map::iterator t; + + for (t = dbDict.getFirstTableIterator(); t != dbDict.getTableEndIterator(); t++) + { + cDbTableDef* td = t->second; + + if (td->hasName("CHANNELMAP")) + continue; + + if (td->getField("CHANNELID", yes)) + { + tell(3, "Table '%s' has a channelid field", td->getName()); + + cDbTable* table = new cDbTable(connection, t->first.c_str()); + char* stmt; + + asprintf(&stmt, "update %s set %s = '%s' where %s = '%s'", + td->getName(), + table->getField("CHANNELID")->getDbName(), newChannelId.c_str(), + table->getField("CHANNELID")->getDbName(), oldChannelId.c_str()); + + tell(0, "Executing '%s'", stmt); + connection->query("%s", stmt); + + free(stmt); + delete table; + } + } + } + } + mapDb->clear(); for (int f = selectAllMap->find(); f; f = selectAllMap->fetch()) -- cgit v1.2.3