add function to delete a playlist item

This commit is contained in:
Ron Pedde 2005-04-23 21:01:10 +00:00
parent 7b3333df19
commit c2de7ce606
3 changed files with 63 additions and 1 deletions

View File

@ -49,6 +49,7 @@ typedef struct tag_db_functions {
int(*dbs_add_playlist)(char *, int, char *,char *, int *); int(*dbs_add_playlist)(char *, int, char *,char *, int *);
int(*dbs_add_playlist_item)(int, int); int(*dbs_add_playlist_item)(int, int);
int(*dbs_delete_playlist)(int); int(*dbs_delete_playlist)(int);
int(*dbs_delete_playlist_item)(int, int);
int(*dbs_enum_start)(DBQUERYINFO *); int(*dbs_enum_start)(DBQUERYINFO *);
int(*dbs_enum_size)(DBQUERYINFO *, int *); int(*dbs_enum_size)(DBQUERYINFO *, int *);
int(*dbs_enum_fetch)(DBQUERYINFO *, unsigned char **); int(*dbs_enum_fetch)(DBQUERYINFO *, unsigned char **);
@ -76,6 +77,7 @@ DB_FUNCTIONS db_functions[] = {
db_sqlite_add_playlist, db_sqlite_add_playlist,
db_sqlite_add_playlist_item, db_sqlite_add_playlist_item,
db_sqlite_delete_playlist, db_sqlite_delete_playlist,
db_sqlite_delete_playlist_item,
db_sqlite_enum_start, db_sqlite_enum_start,
db_sqlite_enum_size, db_sqlite_enum_size,
db_sqlite_enum_fetch, db_sqlite_enum_fetch,
@ -523,6 +525,25 @@ int db_delete_playlist(int playlistid) {
return retval; 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 * start a db enumeration, based info in the DBQUERYINFO struct
* *

View File

@ -331,6 +331,46 @@ int db_sqlite_delete_playlist(int playlistid) {
return DB_E_SUCCESS; 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 * add a playlist
* *
@ -396,7 +436,7 @@ int db_sqlite_add_playlist_item(int playlistid, int songid) {
return result; 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; return DB_E_INVALIDTYPE;
/* make sure the songid is valid */ /* make sure the songid is valid */

View File

@ -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(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_add_playlist_item(int playlistid, int songid);
extern int db_sqlite_delete_playlist(int playlistid); extern int db_sqlite_delete_playlist(int playlistid);
extern int db_sqlite_delete_playlist_item(int playlistid, int songid);
typedef enum { typedef enum {
songID, songID,