27 LOG(VB_GENERAL, LOG_NOTICE,
28 "Inserting MythBrowser initial database information.");
32 "DROP TABLE IF EXISTS websites;",
33 "CREATE TABLE websites ("
34 "id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY, "
35 "category VARCHAR(100) NOT NULL, "
36 "name VARCHAR(100) NOT NULL, "
37 "url VARCHAR(255) NOT NULL);"
40 updates,
"1000", dbver))
48 "UPDATE settings SET data = 'Internal' WHERE data LIKE '%mythbrowser' AND value = 'WebBrowserCommand';"
51 updates,
"1001", dbver))
59 "DELETE FROM keybindings "
60 " WHERE action = 'DELETETAB' AND context = 'Browser';"
63 updates,
"1002", dbver))
71 "ALTER TABLE `websites` ADD `homepage` BOOL NOT NULL;"
74 updates,
"1003", dbver))
81bool FindInDB(
const QString &category,
const QString& name)
84 query.
prepare(
"SELECT name FROM websites "
85 "WHERE category = :CATEGORY AND name = :NAME ;");
94 return (query.
size() > 0);
100 query.
prepare(
"UPDATE `websites` SET `homepage` = '0' WHERE `homepage` = '1';");
108 query.
prepare(
"UPDATE `websites` SET `homepage` = '1' "
109 "WHERE `category` = :CATEGORY "
110 "AND `name` = :NAME;");
128 const bool isHomepage)
130 if (category.isEmpty() || name.isEmpty() || url.isEmpty())
136 QString _url = url.trimmed();
137 if (!_url.startsWith(
"http://") && !_url.startsWith(
"https://") &&
138 !_url.startsWith(
"file:/"))
139 _url.prepend(
"http://");
141 _url.replace(
"&",
"&");
144 query.
prepare(
"INSERT INTO websites (category, name, url, homepage) "
145 "VALUES(:CATEGORY, :NAME, :URL, :HOMEPAGE);");
149 query.
bindValue(
":HOMEPAGE", isHomepage);
170 query.
prepare(
"DELETE FROM websites "
171 "WHERE category = :CATEGORY AND name = :NAME;");
186 query.
prepare(
"SELECT DISTINCT category FROM websites "
187 "ORDER BY category;");
197 list << query.
value(0).toString();
205 while (!siteList.isEmpty())
206 delete siteList.takeFirst();
210 if (!query.
exec(
"SELECT category, name, url, homepage FROM websites "
211 "ORDER BY category, name"))
213 LOG(VB_GENERAL, LOG_ERR,
"BookmarkManager: Error in loading from DB");
221 site->m_category = query.
value(0).toString();
222 site->m_name = query.
value(1).toString();
223 site->m_sortName = sh->doTitle(site->m_name);
224 site->m_url = query.
value(2).toString();
225 site->m_isHomepage = query.
value(3).toBool();
226 site->m_selected =
false;
227 siteList.append(site);
232 return siteList.size();
const QString currentDatabaseVersion
bool UpgradeBrowserDatabaseSchema(void)
int GetSiteList(QList< Bookmark * > &siteList)
bool InsertInDB(Bookmark *site)
bool RemoveFromDB(Bookmark *site)
int GetCategoryList(QStringList &list)
bool FindInDB(const QString &category, const QString &name)
bool UpdateHomepageInDB(Bookmark *site)
const QString MythBrowserVersionName
bool ResetHomepageFromDB()
static bool sortByName(Bookmark *a, Bookmark *b)
QSqlQuery wrapper that fetches a DB connection from the connection pool.
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.
QVariant value(int i) const
int numRowsAffected() const
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
void bindValue(const QString &placeholder, const QVariant &val)
Add a single binding.
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
static MSqlQueryInfo InitCon(ConnectionReuse _reuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
QString GetSetting(const QString &key, const QString &defaultval="")
static void DBError(const QString &where, const MSqlQuery &query)
bool performActualUpdate(const QString &component, const QString &versionkey, const DBUpdates &updates, const QString &version, QString &dbver)
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
std::vector< std::string > DBUpdates
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
std::shared_ptr< MythSortHelper > getMythSortHelper(void)
Get a pointer to the MythSortHelper singleton.