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