| | 611 | // Update starttime in table record for single recordings |
| | 612 | // when the starttime of a program is changed. |
| | 613 | // |
| | 614 | // Return the number of rows affected: |
| | 615 | // 0 if program is not found in table record |
| | 616 | // 1 if program is found and updated |
| | 617 | // |
| | 618 | static int change_record(MSqlQuery &query, uint chanid, |
| | 619 | const QDateTime &old_starttime, |
| | 620 | const QDateTime &new_starttime) |
| | 621 | { |
| | 622 | query.prepare("UPDATE record " |
| | 623 | "SET starttime = :NEWSTARTTIME, " |
| | 624 | " startdate = :NEWSTARTDATE " |
| | 625 | "WHERE chanid = :CHANID " |
| | 626 | "AND type = :TYPE " |
| | 627 | "AND search = :SEARCH " |
| | 628 | "AND starttime = :OLDSTARTTIME " |
| | 629 | "AND startdate = :OLDSTARTDATE "); |
| | 630 | query.bindValue(":CHANID", chanid); |
| | 631 | query.bindValue(":TYPE", kSingleRecord); |
| | 632 | query.bindValue(":SEARCH", kNoSearch); |
| | 633 | query.bindValue(":OLDSTARTTIME", old_starttime.time()); |
| | 634 | query.bindValue(":OLDSTARTDATE", old_starttime.date()); |
| | 635 | query.bindValue(":NEWSTARTTIME", new_starttime.time()); |
| | 636 | query.bindValue(":NEWSTARTDATE", new_starttime.date()); |
| | 637 | |
| | 638 | int rows = 0; |
| | 639 | if (!query.exec() || !query.isActive()) |
| | 640 | { |
| | 641 | MythDB::DBError("Updating record", query); |
| | 642 | } |
| | 643 | else |
| | 644 | { |
| | 645 | rows = query.numRowsAffected(); |
| | 646 | } |
| | 647 | if (rows > 0) |
| | 648 | { |
| | 649 | LOG(VB_EIT, LOG_DEBUG, |
| | 650 | QString("EIT: Updated record: chanid:%1 old:%3 new:%4 rows:%5") |
| | 651 | .arg(chanid) |
| | 652 | .arg(old_starttime.toString(Qt::ISODate)) |
| | 653 | .arg(new_starttime.toString(Qt::ISODate)) |
| | 654 | .arg(rows)); |
| | 655 | } |
| | 656 | return rows; |
| | 657 | } |
| | 658 | |
| | 674 | // Update starttime also in database table record so that |
| | 675 | // tables program and record remain consistent. |
| | 676 | if (m_starttime != match.m_starttime) |
| | 677 | { |
| | 678 | QDateTime const &old_starttime = match.m_starttime; |
| | 679 | QDateTime const &new_starttime = m_starttime; |
| | 680 | change_record(query, chanid, old_starttime, new_starttime); |
| | 681 | |
| | 682 | LOG(VB_EIT, LOG_DEBUG, |
| | 683 | QString("EIT: (U) change starttime from %1 to %2 for chanid:%3 program '%4' ") |
| | 684 | .arg(old_starttime.toString(Qt::ISODate)) |
| | 685 | .arg(new_starttime.toString(Qt::ISODate)) |
| | 686 | .arg(chanid) |
| | 687 | .arg(m_title.left(35))); |
| | 688 | } |
| | 689 | |