Ticket #2534: mythplugins-mythvideo-dbcheck_mysql3_compat-1.patch

File mythplugins-mythvideo-dbcheck_mysql3_compat-1.patch, 1.2 KB (added by sphery <mtdean@…>, 15 years ago)

Oops. This is the current patch (moves categoryIDs declaration to the appropriate block after adding the else)

  • mythvideo/mythvideo/dbcheck.cpp

     
    227227
    228228    if (dbver == "1008")
    229229    {
    230         const QString updates[] = {
    231 "UPDATE videometadata "
    232 "LEFT JOIN videocategory ON (videometadata.category = videocategory.intid) "
    233 "SET videometadata.category = 0 "
    234 "WHERE videocategory.intid IS NULL;",
    235 ""
    236 };
     230        QStringList updates;
    237231
     232        MSqlQuery query(MSqlQuery::InitCon());
     233        query.exec("SELECT intid FROM videocategory;");
     234
     235        if (query.isActive() && query.size())
     236        {
     237            QString categoryIDs = "'0',";
     238            while (query.next())
     239            {
     240              categoryIDs += "'" + query.value(0).toString() + "',";
     241            }
     242            categoryIDs = categoryIDs.left(categoryIDs.length() - 1);
     243            updates.append(QString(
     244"UPDATE videometadata SET category = 0 WHERE category NOT IN (%1);")
     245                           .arg(categoryIDs));
     246        }
     247        else
     248        {
     249          updates.append("SELECT 1;");
     250        }
     251
    238252        performActualUpdate(updates, "1009", dbver);
    239253    }
    240254