Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
VideoLAN
medialibrary
Commits
9424f441
Commit
9424f441
authored
Feb 25, 2016
by
Hugo Beauzée-Luyssen
Browse files
Playlist: Detect duplicated insertions
parent
069b7f55
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/Playlist.cpp
View file @
9424f441
...
...
@@ -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
)
...
...
test/unittest/PlaylistTests.cpp
View file @
9424f441
...
...
@@ -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
);
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment