3 * Copyright (C) 2012-2013 Team XBMC
6 * This Program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
11 * This Program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with XBMC; see the file COPYING. If not, see
18 * <http://www.gnu.org/licenses/>.
22 #include "dbwrappers/Database.h"
23 #include "XBDateTime.h"
31 /** The EPG database */
33 class CEpgDatabase : public CDatabase
37 * @brief Create a new instance of the EPG database.
39 CEpgDatabase(void) {};
42 * @brief Destroy this instance.
44 virtual ~CEpgDatabase(void) {};
47 * @brief Open the database.
48 * @return True if it was opened successfully, false otherwise.
50 virtual bool Open(void);
53 * @brief Get the minimal database version that is required to operate correctly.
54 * @return The minimal database version.
56 virtual int GetSchemaVersion(void) const { return 7; };
59 * @brief Get the default sqlite database filename.
60 * @return The default filename.
62 const char *GetBaseDBName(void) const { return "Epg"; };
64 /*! @name EPG methods */
68 * @brief Remove all EPG information from the database
69 * @return True if the EPG information was erased, false otherwise.
71 virtual bool DeleteEpg(void);
74 * @brief Delete an EPG table.
75 * @param table The table to remove.
76 * @return True if the table was removed successfully, false otherwise.
78 virtual bool Delete(const CEpg &table);
81 * @brief Erase all EPG entries older than 1 day.
82 * @return True if the entries were removed successfully, false otherwise.
84 virtual bool DeleteOldEpgEntries(void);
87 * @brief Remove a single EPG entry.
88 * @param tag The entry to remove.
89 * @return True if it was removed successfully, false otherwise.
91 virtual bool Delete(const CEpgInfoTag &tag);
94 * @brief Get all EPG tables from the database. Does not get the EPG tables' entries.
95 * @param container The container to fill.
96 * @return The amount of entries that was added.
98 virtual int Get(CEpgContainer &container);
101 * @brief Get all EPG entries for a table.
102 * @param epg The EPG table to get the entries for.
103 * @return The amount of entries that was added.
105 virtual int Get(CEpg &epg);
108 * @brief Get the last stored EPG scan time.
109 * @param iEpgId The table to update the time for. Use 0 for a global value.
110 * @param lastScan The last scan time or -1 if it wasn't found.
111 * @return True if the time was fetched successfully, false otherwise.
113 virtual bool GetLastEpgScanTime(int iEpgId, CDateTime *lastScan);
116 * @brief Update the last scan time.
117 * @param iEpgId The table to update the time for. Use 0 for a global value.
118 * @param bQueueWrite Don't execute the query immediately but queue it if true.
119 * @return True if it was updated successfully, false otherwise.
121 virtual bool PersistLastEpgScanTime(int iEpgId = 0, bool bQueueWrite = false);
123 bool Persist(const CEpgContainer &epg);
126 * @brief Persist an EPG table. It's entries are not persisted.
127 * @param epg The table to persist.
128 * @param bQueueWrite Don't execute the query immediately but queue it if true.
129 * @return The database ID of this entry or 0 if bSingleUpdate is false and the query was queued.
131 virtual int Persist(const CEpg &epg, bool bQueueWrite = false);
134 * @brief Persist an infotag.
135 * @param tag The tag to persist.
136 * @param bSingleUpdate If true, this is a single update and the query will be executed immediately.
137 * @return The database ID of this entry or 0 if bSingleUpdate is false and the query was queued.
139 virtual int Persist(const CEpgInfoTag &tag, bool bSingleUpdate = true);
142 * @return Last EPG id in the database
144 int GetLastEPGId(void);
150 * @brief Create the EPG database tables.
152 virtual void CreateTables();
155 * @brief Create the EPG database analytics.
157 virtual void CreateAnalytics();
160 * @brief Update an old version of the database.
161 * @param version The version to update the database from.
163 virtual void UpdateTables(int version);
164 virtual int GetMinSchemaVersion() const { return 4; }