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

Label: Split triggers creation in a specific method

parent 32d07824
...@@ -92,14 +92,19 @@ void Label::createTable( sqlite::Connection* dbConnection ) ...@@ -92,14 +92,19 @@ void Label::createTable( sqlite::Connection* dbConnection )
"PRIMARY KEY (label_id, media_id)," "PRIMARY KEY (label_id, media_id),"
"FOREIGN KEY(label_id) REFERENCES Label(id_label) ON DELETE CASCADE," "FOREIGN KEY(label_id) REFERENCES Label(id_label) ON DELETE CASCADE,"
"FOREIGN KEY(media_id) REFERENCES Media(id_media) 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 " const std::string ftsTrigger = "CREATE TRIGGER IF NOT EXISTS delete_label_fts "
"BEFORE DELETE ON " + policy::LabelTable::Name + "BEFORE DELETE ON " + policy::LabelTable::Name +
" BEGIN" " BEGIN"
" UPDATE " + policy::MediaTable::Name + "Fts SET labels = TRIM(REPLACE(labels, old.name, ''))" " UPDATE " + policy::MediaTable::Name + "Fts SET labels = TRIM(REPLACE(labels, old.name, ''))"
" WHERE labels MATCH old.name;" " WHERE labels MATCH old.name;"
" END"; " END";
sqlite::Tools::executeRequest( dbConnection, req );
sqlite::Tools::executeRequest( dbConnection, relReq );
sqlite::Tools::executeRequest( dbConnection, ftsTrigger ); sqlite::Tools::executeRequest( dbConnection, ftsTrigger );
} }
......
...@@ -58,6 +58,7 @@ class Label : public ILabel, public DatabaseHelpers<Label, policy::LabelTable> ...@@ -58,6 +58,7 @@ class Label : public ILabel, public DatabaseHelpers<Label, policy::LabelTable>
static LabelPtr create( MediaLibraryPtr ml, const std::string& name ); static LabelPtr create( MediaLibraryPtr ml, const std::string& name );
static void createTable( sqlite::Connection* dbConnection ); static void createTable( sqlite::Connection* dbConnection );
static void createTriggers( sqlite::Connection* dbConnection );
private: private:
MediaLibraryPtr m_ml; MediaLibraryPtr m_ml;
......
...@@ -171,6 +171,7 @@ void MediaLibrary::createAllTriggers() ...@@ -171,6 +171,7 @@ void MediaLibrary::createAllTriggers()
Genre::createTriggers( m_dbConnection.get() ); Genre::createTriggers( m_dbConnection.get() );
Playlist::createTriggers( m_dbConnection.get() ); Playlist::createTriggers( m_dbConnection.get() );
History::createTriggers( m_dbConnection.get() ); History::createTriggers( m_dbConnection.get() );
Label::createTriggers( m_dbConnection.get() );
} }
template <typename T> 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