static const translateField fields[] = {
{ "none", TF_None, CDatabaseQueryRule::TEXT_FIELD },
- { "id", TF_Id, CDatabaseQueryRule::NUMERIC_FIELD },
+ { "textureid", TF_Id, CDatabaseQueryRule::NUMERIC_FIELD },
{ "url", TF_Url, CDatabaseQueryRule::TEXT_FIELD },
{ "cachedurl", TF_CachedUrl, CDatabaseQueryRule::TEXT_FIELD },
{ "lasthashcheck", TF_LastHashCheck, CDatabaseQueryRule::TEXT_FIELD },
return TEXT_FIELD;
}
+CStdString CTextureRule::FormatParameter(const CStdString &operatorString, const CStdString ¶m, const CDatabase &db, const CStdString &strType) const
+{
+ CStdString parameter(param);
+ if (m_field == TF_Url)
+ parameter = CTextureUtils::UnwrapImageURL(param);
+ return CDatabaseQueryRule::FormatParameter(operatorString, parameter, db, strType);
+}
+
void CTextureRule::GetAvailableFields(std::vector<std::string> &fieldList)
{
// start at 1 to skip TF_None
url.SetProtocol("image");
url.SetUserName(type);
url.SetHostName(image);
- if (!options.IsEmpty())
+ if (!options.empty())
{
url.SetFileName("transform");
url.SetOptions("?" + options);
if (StringUtils::StartsWith(image, "image://"))
{
CURL url(image);
- if (url.GetUserName().IsEmpty() && url.GetOptions().IsEmpty())
+ if (url.GetUserName().empty() && url.GetOptions().empty())
return url.GetHostName();
}
return image;
return CDatabase::Open();
}
-bool CTextureDatabase::CreateTables()
+void CTextureDatabase::CreateTables()
{
- try
- {
- CDatabase::CreateTables();
+ CLog::Log(LOGINFO, "create texture table");
+ m_pDS->exec("CREATE TABLE texture (id integer primary key, url text, cachedurl text, imagehash text, lasthashcheck text)");
- CLog::Log(LOGINFO, "create texture table");
- m_pDS->exec("CREATE TABLE texture (id integer primary key, url text, cachedurl text, imagehash text, lasthashcheck text)");
-
- CLog::Log(LOGINFO, "create textures index");
- m_pDS->exec("CREATE INDEX idxTexture ON texture(url)");
-
- CLog::Log(LOGINFO, "create sizes table, index, and trigger");
- m_pDS->exec("CREATE TABLE sizes (idtexture integer, size integer, width integer, height integer, usecount integer, lastusetime text)");
- m_pDS->exec("CREATE INDEX idxSize ON sizes(idtexture, size)");
- m_pDS->exec("CREATE INDEX idxSize2 ON sizes(idtexture, width, height)");
- m_pDS->exec("CREATE TRIGGER textureDelete AFTER delete ON texture FOR EACH ROW BEGIN delete from sizes where sizes.idtexture=old.id; END");
-
- CLog::Log(LOGINFO, "create path table");
- m_pDS->exec("CREATE TABLE path (id integer primary key, url text, type text, texture text)\n");
+ CLog::Log(LOGINFO, "create sizes table, index, and trigger");
+ m_pDS->exec("CREATE TABLE sizes (idtexture integer, size integer, width integer, height integer, usecount integer, lastusetime text)");
- // TODO: Should the path index be a covering index? (we need only retrieve texture)
- CLog::Log(LOGINFO, "create path index");
- m_pDS->exec("CREATE INDEX idxPath ON path(url, type)");
- }
- catch (...)
- {
- CLog::Log(LOGERROR, "%s unable to create tables", __FUNCTION__);
- return false;
- }
+ CLog::Log(LOGINFO, "create path table");
+ m_pDS->exec("CREATE TABLE path (id integer primary key, url text, type text, texture text)\n");
+}
- return true;
+void CTextureDatabase::CreateAnalytics()
+{
+ CLog::Log(LOGINFO, "%s creating indices", __FUNCTION__);
+ m_pDS->exec("CREATE INDEX idxTexture ON texture(url)");
+ m_pDS->exec("CREATE INDEX idxSize ON sizes(idtexture, size)");
+ m_pDS->exec("CREATE INDEX idxSize2 ON sizes(idtexture, width, height)");
+ // TODO: Should the path index be a covering index? (we need only retrieve texture)
+ m_pDS->exec("CREATE INDEX idxPath ON path(url, type)");
+
+ CLog::Log(LOGINFO, "%s creating triggers", __FUNCTION__);
+ m_pDS->exec("CREATE TRIGGER textureDelete AFTER delete ON texture FOR EACH ROW BEGIN delete from sizes where sizes.idtexture=old.id; END");
}
-bool CTextureDatabase::UpdateOldVersion(int version)
+void CTextureDatabase::UpdateTables(int version)
{
if (version < 7)
{ // update all old thumb://foo urls to image://foo?size=thumb
}
if (version < 9)
{ // get rid of the old path table and add the type column
- m_pDS->dropIndex("path", "idxPath");
- m_pDS->exec("DROP TABLE path");
+ m_pDS->exec("DROP TABLE IF EXISTS path");
m_pDS->exec("CREATE TABLE path (id integer primary key, urlhash integer, url text, type text, texture text)\n");
- m_pDS->exec("CREATE INDEX idxPath ON path(urlhash, type)");
}
if (version < 10)
{ // get rid of urlhash in both tables...
- m_pDS->dropIndex("path", "idxPath");
- m_pDS->exec("DROP TABLE path");
+ m_pDS->exec("DROP TABLE IF EXISTS path");
m_pDS->exec("CREATE TABLE path (id integer primary key, url text, type text, texture text)\n");
- m_pDS->exec("CREATE INDEX idxPath ON path(url, type)");
- m_pDS->dropIndex("texture", "idxTexture");
m_pDS->exec("CREATE TEMPORARY TABLE texture_backup(id,url,cachedurl,usecount,lastusetime,imagehash,lasthashcheck)");
m_pDS->exec("INSERT INTO texture_backup SELECT id,url,cachedurl,usecount,lastusetime,imagehash,lasthashcheck FROM texture");
m_pDS->exec("DROP TABLE texture");
m_pDS->exec("CREATE TABLE texture (id integer primary key, url text, cachedurl text, usecount integer, lastusetime text, imagehash text, lasthashcheck text)");
- m_pDS->exec("CREATE INDEX idxTexture ON texture(url)");
m_pDS->exec("INSERT INTO texture SELECT * FROM texture_backup");
m_pDS->exec("DROP TABLE texture_backup");
}
}
if (version < 12)
{ // create new sizes table and move usecount info to it.
- m_pDS->exec("DROP TABLE texture");
+ m_pDS->exec("DROP TABLE IF EXISTS texture");
m_pDS->exec("CREATE TABLE texture (id integer primary key, url text, cachedurl text, imagehash text, lasthashcheck text)");
- m_pDS->exec("CREATE INDEX idxTexture ON texture(url)");
m_pDS->exec("CREATE TABLE sizes (idtexture integer, size integer, width integer, height integer, usecount integer, lastusetime text)");
- m_pDS->exec("CREATE INDEX idxSize ON sizes(idtexture, size)");
- m_pDS->exec("CREATE TRIGGER textureDelete AFTER delete ON texture FOR EACH ROW BEGIN delete from sizes where sizes.idtexture=old.id; END");
}
- if (version < 13)
- { // index for updateusecount
- m_pDS->exec("CREATE INDEX idxSize2 ON sizes(idtexture, width, height)");
- }
- return true;
}
bool CTextureDatabase::IncrementUseCount(const CTextureDetails &details)
while (!m_pDS->eof())
{
CVariant texture;
- texture["id"] = m_pDS->fv(0).get_asInt();
+ texture["textureid"] = m_pDS->fv(0).get_asInt();
texture["url"] = m_pDS->fv(1).get_asString();
texture["cachedurl"] = m_pDS->fv(2).get_asString();
texture["imagehash"] = m_pDS->fv(3).get_asString();