Ticket #12016: positionmap.patch

File positionmap.patch, 4.5 KB (added by Jonatan Lindblad, 10 years ago)
  • mythtv/libs/libmyth/programinfo.cpp

    diff --git a/mythtv/libs/libmyth/programinfo.cpp b/mythtv/libs/libmyth/programinfo.cpp
    index 71277ea..57b87c5 100644
    a b void ProgramInfo::SavePositionMap( 
    35943594    if (!query.exec())
    35953595        MythDB::DBError("position map clear", query);
    35963596
     3597    // Use the multi-value insert syntax to reduce database I/O
     3598    QStringList q("INSERT INTO ");
     3599    QString qfields;
    35973600    if (IsVideo())
    35983601    {
    3599         query.prepare(
    3600             "INSERT INTO "
    3601             "filemarkup (filename, mark, type, offset) "
    3602             "VALUES ( :PATH , :MARK , :TYPE , :OFFSET )");
    3603         query.bindValue(":PATH", videoPath);
     3602        q << "filemarkup (filename, type, mark, offset)";
     3603        qfields = QString("('%1',%2,") .
     3604            // ideally, this should be escaped
     3605            arg(videoPath) .
     3606            arg(type);
    36043607    }
    36053608    else // if (IsRecording())
    36063609    {
    3607         query.prepare(
    3608             "INSERT INTO "
    3609             "recordedseek (chanid, starttime, mark, type, offset) "
    3610             " VALUES ( :CHANID , :STARTTIME , :MARK , :TYPE , :OFFSET )");
    3611         query.bindValue(":CHANID",    chanid);
    3612         query.bindValue(":STARTTIME", recstartts);
     3610        q << "recordedseek (chanid, starttime, type, mark, offset)";
     3611        qfields = QString("(%1,'%2',%3,") .
     3612            arg(chanid) .
     3613            arg(recstartts.toString(Qt::ISODate)) .
     3614            arg(type);
    36133615    }
    3614     query.bindValue(":TYPE", type);
     3616    q << " VALUES ";
    36153617
     3618    bool add_comma = false;
    36163619    frm_pos_map_t::iterator it;
    36173620    for (it = posMap.begin(); it != posMap.end(); ++it)
    36183621    {
    void ProgramInfo::SavePositionMap( 
    36263629
    36273630        uint64_t offset = *it;
    36283631
    3629         query.bindValue(":MARK",   (quint64)frame);
    3630         query.bindValue(":OFFSET", (quint64)offset);
    3631 
    3632         if (!query.exec())
     3632        if (add_comma)
    36333633        {
    3634             MythDB::DBError("position map insert", query);
    3635             break;
     3634            q << ",";
    36363635        }
     3636        else
     3637        {
     3638            add_comma = true;
     3639        }
     3640        q << qfields << QString("%1,%2)").arg(frame).arg(offset);
     3641    }
     3642    query.prepare(q.join(""));
     3643    if (!query.exec())
     3644    {
     3645        MythDB::DBError("position map insert", query);
    36373646    }
    36383647}
    36393648
    void ProgramInfo::SavePositionMapDelta( 
    36523661        return;
    36533662    }
    36543663
    3655     MSqlQuery query(MSqlQuery::InitCon());
    3656 
     3664    // Use the multi-value insert syntax to reduce database I/O
     3665    QStringList q("INSERT INTO ");
     3666    QString qfields;
    36573667    if (IsVideo())
    36583668    {
    3659         query.prepare(
    3660             "INSERT INTO "
    3661             "filemarkup (filename, mark, type, offset) "
    3662             "VALUES ( :PATH , :MARK , :TYPE , :OFFSET )");
    3663         query.bindValue(":PATH", StorageGroup::GetRelativePathname(pathname));
     3669        q << "filemarkup (filename, type, mark, offset)";
     3670        qfields = QString("('%1',%2,") .
     3671            // ideally, this should be escaped
     3672            arg(StorageGroup::GetRelativePathname(pathname)) .
     3673            arg(type);
    36643674    }
    36653675    else if (IsRecording())
    36663676    {
    3667         query.prepare(
    3668             "INSERT INTO "
    3669             "recordedseek (chanid, starttime, mark, type, offset) "
    3670             " VALUES ( :CHANID , :STARTTIME , :MARK , :TYPE , :OFFSET )");
    3671         query.bindValue(":CHANID",    chanid);
    3672         query.bindValue(":STARTTIME", recstartts);
     3677        q << "recordedseek (chanid, starttime, type, mark, offset)";
     3678        qfields = QString("(%1,'%2',%3,") .
     3679            arg(chanid) .
     3680            arg(recstartts.toString(Qt::ISODate)) .
     3681            arg(type);
    36733682    }
    36743683    else
    36753684    {
    36763685        return;
    36773686    }
    3678     query.bindValue(":TYPE", type);
     3687    q << " VALUES ";
    36793688
     3689    bool add_comma = false;
    36803690    frm_pos_map_t::iterator it;
    36813691    for (it = posMap.begin(); it != posMap.end(); ++it)
    36823692    {
    36833693        uint64_t frame  = it.key();
    36843694        uint64_t offset = *it;
    36853695
    3686         query.bindValue(":MARK",   (quint64)frame);
    3687         query.bindValue(":OFFSET", (quint64)offset);
    3688 
    3689         if (!query.exec())
     3696        if (add_comma)
    36903697        {
    3691             MythDB::DBError("delta position map insert", query);
    3692             break;
     3698            q << ",";
    36933699        }
     3700        else
     3701        {
     3702            add_comma = true;
     3703        }
     3704        q << qfields << QString("%1,%2)").arg(frame).arg(offset);
     3705    }
     3706
     3707    MSqlQuery query(MSqlQuery::InitCon());
     3708    query.prepare(q.join(""));
     3709    if (!query.exec())
     3710    {
     3711        MythDB::DBError("delta position map insert", query);
    36943712    }
    36953713}
    36963714