Commit 9424f441 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Playlist: Detect duplicated insertions

parent 069b7f55
......@@ -102,7 +102,15 @@ bool Playlist::add( int64_t mediaId, unsigned int position )
static const std::string req = "INSERT INTO PlaylistMediaRelation(media_id, playlist_id, position) VALUES(?, ?, ?)";
// position isn't a foreign key, but we want it to be passed as NULL if it equals to 0
// When the position is NULL, the insertion triggers takes care of counting the number of records to auto append.
return sqlite::Tools::executeInsert( m_ml->getConn(), req, mediaId, m_id, sqlite::ForeignKey{ position } );
try
{
return sqlite::Tools::executeInsert( m_ml->getConn(), req, mediaId, m_id, sqlite::ForeignKey{ position } );
}
catch (const sqlite::errors::ConstraintViolation& ex)
{
LOG_WARN( "Rejected playlist insertion: ", ex.what() );
return false;
}
}
bool Playlist::move( int64_t mediaId, unsigned int position )
......
......@@ -291,3 +291,12 @@ TEST_F( Playlists, Sort )
ASSERT_EQ( pl2->id(), pls[1]->id() );
ASSERT_EQ( pl->id(), pls[0]->id() );
}
TEST_F( Playlists, AddDuplicate )
{
auto m = ml->addFile( "file.mkv" );
auto res = pl->append( m->id() );
ASSERT_TRUE( res );
res = pl->append( m->id() );
ASSERT_FALSE( res );
}
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