mirror of
https://github.com/owntone/owntone-server.git
synced 2024-12-25 22:55:56 -05:00
add function to delete a playlist item
This commit is contained in:
parent
7b3333df19
commit
c2de7ce606
@ -49,6 +49,7 @@ typedef struct tag_db_functions {
|
||||
int(*dbs_add_playlist)(char *, int, char *,char *, int *);
|
||||
int(*dbs_add_playlist_item)(int, int);
|
||||
int(*dbs_delete_playlist)(int);
|
||||
int(*dbs_delete_playlist_item)(int, int);
|
||||
int(*dbs_enum_start)(DBQUERYINFO *);
|
||||
int(*dbs_enum_size)(DBQUERYINFO *, int *);
|
||||
int(*dbs_enum_fetch)(DBQUERYINFO *, unsigned char **);
|
||||
@ -76,6 +77,7 @@ DB_FUNCTIONS db_functions[] = {
|
||||
db_sqlite_add_playlist,
|
||||
db_sqlite_add_playlist_item,
|
||||
db_sqlite_delete_playlist,
|
||||
db_sqlite_delete_playlist_item,
|
||||
db_sqlite_enum_start,
|
||||
db_sqlite_enum_size,
|
||||
db_sqlite_enum_fetch,
|
||||
@ -523,6 +525,25 @@ int db_delete_playlist(int playlistid) {
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* delete an item from a playlist
|
||||
*
|
||||
* \param playlistid id of the playlist to delete
|
||||
* \param songid id of the song to delete
|
||||
* \returns 0 on success, error code otherwise
|
||||
*/
|
||||
int db_delete_playlist_item(int playlistid, int songid) {
|
||||
int retval;
|
||||
|
||||
db_writelock();
|
||||
retval=db_current->dbs_delete_playlist_item(playlistid,songid);
|
||||
if(retval == DB_E_SUCCESS)
|
||||
db_revision_no++;
|
||||
db_unlock();
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* start a db enumeration, based info in the DBQUERYINFO struct
|
||||
*
|
||||
|
@ -331,6 +331,46 @@ int db_sqlite_delete_playlist(int playlistid) {
|
||||
return DB_E_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* delete a song from a playlist
|
||||
*
|
||||
* \param playlistid playlist to delete item from
|
||||
* \param songid song to delete from playlist
|
||||
*/
|
||||
extern int db_sqlite_delete_playlist_item(int playlistid, int songid) {
|
||||
int result;
|
||||
int playlist_type;
|
||||
int count;
|
||||
|
||||
/* first, check the playlist */
|
||||
result=db_sqlite_get_int(E_DBG,&playlist_type,
|
||||
"select type from playlists where id=%d",playlistid);
|
||||
|
||||
if(result != DB_E_SUCCESS) {
|
||||
if(result == DB_E_NOROWS)
|
||||
return DB_E_INVALID_PLAYLIST;
|
||||
return result;
|
||||
}
|
||||
|
||||
if(playlist_type == 1) /* can't delete from a smart playlist */
|
||||
return DB_E_INVALIDTYPE;
|
||||
|
||||
/* make sure the songid is valid */
|
||||
result=db_sqlite_get_int(E_DBG,&count,"select count(*) from playlistitems where id=%d "
|
||||
"and songid=%d",playlistid,songid);
|
||||
if(result != DB_E_SUCCESS) {
|
||||
if(result == DB_E_NOROWS)
|
||||
return DB_E_INVALID_SONGID;
|
||||
return result;
|
||||
}
|
||||
|
||||
/* looks valid, so lets add the item */
|
||||
result=db_sqlite_exec(E_DBG,"delete from playlistitems where id=%d and songid=%d",
|
||||
playlistid,songid);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* add a playlist
|
||||
*
|
||||
@ -396,7 +436,7 @@ int db_sqlite_add_playlist_item(int playlistid, int songid) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if(playlist_type != 0) /* can't add to smart playlists, or static */
|
||||
if(playlist_type == 1) /* can't add to smart playlists, or static */
|
||||
return DB_E_INVALIDTYPE;
|
||||
|
||||
/* make sure the songid is valid */
|
||||
|
@ -42,6 +42,7 @@ extern void db_sqlite_dispose_playlist(M3UFILE *pm3u);
|
||||
extern int db_sqlite_add_playlist(char *name, int type, char *clause, char *path, int *playlistid);
|
||||
extern int db_sqlite_add_playlist_item(int playlistid, int songid);
|
||||
extern int db_sqlite_delete_playlist(int playlistid);
|
||||
extern int db_sqlite_delete_playlist_item(int playlistid, int songid);
|
||||
|
||||
typedef enum {
|
||||
songID,
|
||||
|
Loading…
Reference in New Issue
Block a user