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

Playlist: Make the playlist name UNIQUE

parent 9424f441
......@@ -52,9 +52,17 @@ std::shared_ptr<Playlist> Playlist::create( MediaLibraryPtr ml, const std::strin
auto self = std::make_shared<Playlist>( ml, name );
static const std::string req = "INSERT INTO " + policy::PlaylistTable::Name + \
"(name, creation_date) VALUES(?, ?)";
if ( insert( ml, self, req, name, self->m_creationDate ) == false )
return nullptr;
return self;
try
{
if ( insert( ml, self, req, name, self->m_creationDate ) == false )
return nullptr;
return self;
}
catch( sqlite::errors::ConstraintViolation& ex )
{
LOG_WARN( "Failed to create playlist: ", ex.what() );
}
return nullptr;
}
int64_t Playlist::id() const
......@@ -132,7 +140,7 @@ bool Playlist::createTable( DBConnection dbConn )
{
static const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::PlaylistTable::Name + "("
+ policy::PlaylistTable::PrimaryKeyColumn + " INTEGER PRIMARY KEY AUTOINCREMENT,"
"name TEXT,"
"name TEXT UNIQUE,"
"creation_date UNSIGNED INT NOT NULL"
")";
static const std::string relTableReq = "CREATE TABLE IF NOT EXISTS PlaylistMediaRelation("
......
......@@ -46,6 +46,12 @@ TEST_F( Playlists, Create )
ASSERT_NE( 0u, pl->creationDate() );
}
TEST_F( Playlists, CreateDuplicate )
{
auto p = ml->createPlaylist(pl->name());
ASSERT_EQ( nullptr, p );
}
TEST_F( Playlists, Fetch )
{
auto pl2 = ml->playlist( pl->id() );
......
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