MythTV master
eitutils.cpp
Go to the documentation of this file.
1// libmyth* headers
5
6// local headers
7#include "eitutils.h"
8
10{
11 int result = GENERIC_EXIT_OK;
12 int sourceid = -1;
13
14 if (cmdline.toBool("sourceid"))
15 {
16 sourceid = cmdline.toInt("sourceid");
17 }
18
20 if (query.isConnected())
21 {
22 // truncate EIT cache
23 QString sql = "TRUNCATE eit_cache;";
24 query.prepare(sql);
25 LOG(VB_GENERAL, LOG_DEBUG,
26 QString("Truncating EIT cache"));
27 if (!query.exec())
28 {
29 MythDB::DBError("Truncate eit_cache table", query);
30 result = GENERIC_EXIT_NOT_OK;
31 }
32
33 // delete program for all channels that use EIT on sources that use EIT
34 sql = "DELETE FROM program WHERE chanid IN ("
35 "SELECT chanid FROM channel "
36 "WHERE deleted IS NULL AND "
37 " useonairguide = 1 AND "
38 " sourceid IN ("
39 "SELECT sourceid FROM videosource WHERE useeit=1";
40 if (-1 != sourceid)
41 {
42 sql += " AND sourceid = :SOURCEID";
43 }
44 sql += "));";
45 query.prepare(sql);
46 if (-1 != sourceid)
47 {
48 query.bindValue(":SOURCEID", sourceid);
49 }
50 LOG(VB_GENERAL, LOG_DEBUG,
51 QString("Deleting program entries from EIT."));
52 if (!query.exec())
53 {
54 MythDB::DBError("Delete program entries from EIT", query);
55 result = GENERIC_EXIT_NOT_OK;
56 }
57
58 // delete programrating for all channels that use EIT on sources that use EIT
59 sql = "DELETE FROM programrating WHERE chanid IN ("
60 "SELECT chanid FROM channel "
61 "WHERE deleted IS NULL AND "
62 " useonairguide = 1 AND "
63 " sourceid IN ("
64 "SELECT sourceid FROM videosource WHERE useeit=1";
65 if (-1 != sourceid)
66 {
67 sql += " AND sourceid = :SOURCEID";
68 }
69 sql += "));";
70 query.prepare(sql);
71 if (-1 != sourceid)
72 {
73 query.bindValue(":SOURCEID", sourceid);
74 }
75 LOG(VB_GENERAL, LOG_DEBUG,
76 QString("Deleting program rating entries from EIT."));
77 if (!query.exec())
78 {
79 MythDB::DBError("Delete program rating entries from EIT", query);
80 result = GENERIC_EXIT_NOT_OK;
81 }
82
83 // delete credits for all channels that use EIT on sources that use EIT
84 sql = "DELETE FROM credits WHERE chanid IN ("
85 "SELECT chanid FROM channel "
86 "WHERE deleted IS NULL AND "
87 " useonairguide = 1 AND "
88 " sourceid IN ("
89 "SELECT sourceid FROM videosource WHERE useeit=1";
90 if (-1 != sourceid)
91 {
92 sql += " AND sourceid = :SOURCEID";
93 }
94 sql += "));";
95 query.prepare(sql);
96 if (-1 != sourceid)
97 {
98 query.bindValue(":SOURCEID", sourceid);
99 }
100 LOG(VB_GENERAL, LOG_DEBUG,
101 QString("Deleting credits from EIT."));
102 if (!query.exec())
103 {
104 MythDB::DBError("Delete credits from EIT", query);
105 result = GENERIC_EXIT_NOT_OK;
106 }
107
108 // delete program genres for all channels that use EIT on sources that use EIT
109 sql = "DELETE FROM programgenres WHERE chanid IN ("
110 "SELECT chanid FROM channel "
111 "WHERE deleted IS NULL AND "
112 " useonairguide = 1 AND "
113 " sourceid IN ("
114 "SELECT sourceid FROM videosource WHERE useeit=1";
115 if (-1 != sourceid)
116 {
117 sql += " AND sourceid = :SOURCEID";
118 }
119 sql += "));";
120 query.prepare(sql);
121 if (-1 != sourceid)
122 {
123 query.bindValue(":SOURCEID", sourceid);
124 }
125 LOG(VB_GENERAL, LOG_DEBUG,
126 QString("Deleting program genre entries from EIT."));
127 if (!query.exec())
128 {
129 MythDB::DBError("Delete program genre entries from EIT", query);
130 result = GENERIC_EXIT_NOT_OK;
131 }
132 }
133
134 return result;
135}
136
138{
139 utilMap["cleareit"] = &ClearEIT;
140}
141
142/* vim: set expandtab tabstop=4 shiftwidth=4: */
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:128
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.
Definition: mythdbcon.cpp:837
bool isConnected(void) const
Only updated once during object creation.
Definition: mythdbcon.h:137
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
Definition: mythdbcon.cpp:618
void bindValue(const QString &placeholder, const QVariant &val)
Add a single binding.
Definition: mythdbcon.cpp:888
static MSqlQueryInfo InitCon(ConnectionReuse _reuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition: mythdbcon.cpp:550
bool toBool(const QString &key) const
Returns stored QVariant as a boolean.
int toInt(const QString &key) const
Returns stored QVariant as an integer, falling to default if not provided.
static void DBError(const QString &where, const MSqlQuery &query)
Definition: mythdb.cpp:226
static int ClearEIT(const MythUtilCommandLineParser &cmdline)
Definition: eitutils.cpp:9
void registerEITUtils(UtilMap &utilMap)
Definition: eitutils.cpp:137
@ GENERIC_EXIT_OK
Exited with no error.
Definition: exitcodes.h:13
@ GENERIC_EXIT_NOT_OK
Exited with error.
Definition: exitcodes.h:14
MythCommFlagCommandLineParser cmdline
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
QMap< QString, UtilFunc > UtilMap
Definition: mythutil.h:15