Commit 0fb1f285 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Label: Split triggers creation in a specific method

parent 32d07824
......@@ -92,14 +92,19 @@ void Label::createTable( sqlite::Connection* dbConnection )
"PRIMARY KEY (label_id, media_id),"
"FOREIGN KEY(label_id) REFERENCES Label(id_label) ON DELETE CASCADE,"
"FOREIGN KEY(media_id) REFERENCES Media(id_media) ON DELETE CASCADE);";
sqlite::Tools::executeRequest( dbConnection, req );
sqlite::Tools::executeRequest( dbConnection, relReq );
}
void Label::createTriggers( sqlite::Connection* dbConnection )
{
const std::string ftsTrigger = "CREATE TRIGGER IF NOT EXISTS delete_label_fts "
"BEFORE DELETE ON " + policy::LabelTable::Name +
" BEGIN"
" UPDATE " + policy::MediaTable::Name + "Fts SET labels = TRIM(REPLACE(labels, old.name, ''))"
" WHERE labels MATCH old.name;"
" END";
sqlite::Tools::executeRequest( dbConnection, req );
sqlite::Tools::executeRequest( dbConnection, relReq );
sqlite::Tools::executeRequest( dbConnection, ftsTrigger );
}
......
......@@ -58,6 +58,7 @@ class Label : public ILabel, public DatabaseHelpers<Label, policy::LabelTable>
static LabelPtr create( MediaLibraryPtr ml, const std::string& name );
static void createTable( sqlite::Connection* dbConnection );
static void createTriggers( sqlite::Connection* dbConnection );
private:
MediaLibraryPtr m_ml;
......
......@@ -171,6 +171,7 @@ void MediaLibrary::createAllTriggers()
Genre::createTriggers( m_dbConnection.get() );
Playlist::createTriggers( m_dbConnection.get() );
History::createTriggers( m_dbConnection.get() );
Label::createTriggers( m_dbConnection.get() );
}
template <typename T>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment