Commit 32d07824 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen
Browse files

History: Split trigger creation in a separate method

parent 30dc1916
......@@ -58,6 +58,12 @@ void History::createTable( sqlite::Connection* dbConnection )
"FOREIGN KEY (id_media) REFERENCES " + policy::MediaTable::Name +
"(id_media) ON DELETE CASCADE"
")";
// Don't index the id_media field, we don't want to select history records using the media_id
sqlite::Tools::executeRequest( dbConnection, req );
}
void History::createTriggers(sqlite::Connection* dbConnection)
{
const std::string triggerReq = "CREATE TRIGGER IF NOT EXISTS limit_nb_records AFTER INSERT ON "
+ policy::HistoryTable::Name +
" BEGIN "
......@@ -65,8 +71,6 @@ void History::createTable( sqlite::Connection* dbConnection )
"(SELECT id_media FROM " + policy::HistoryTable::Name +
" ORDER BY insertion_date DESC LIMIT -1 OFFSET " + std::to_string( MaxEntries ) + ");"
" END";
// Don't index the id_media field, we don't want to select history records using the media_id
sqlite::Tools::executeRequest( dbConnection, req );
sqlite::Tools::executeRequest( dbConnection, triggerReq );
}
......
......@@ -50,6 +50,7 @@ class History : public IHistoryEntry, public DatabaseHelpers<History, policy::Hi
public:
History( MediaLibraryPtr ml, sqlite::Row& row );
static void createTable( sqlite::Connection* dbConnection );
static void createTriggers( sqlite::Connection* dbConnection );
static bool insert( sqlite::Connection* dbConn, int64_t mediaId );
static std::vector<HistoryPtr> fetch( MediaLibraryPtr ml );
static void clearStreams( MediaLibraryPtr ml );
......
......@@ -170,6 +170,7 @@ void MediaLibrary::createAllTriggers()
File::createTriggers( m_dbConnection.get() );
Genre::createTriggers( m_dbConnection.get() );
Playlist::createTriggers( m_dbConnection.get() );
History::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