Check for valid playlist on add
This commit is contained in:
parent
e7d5aa986a
commit
1c7c77be1c
|
@ -187,13 +187,14 @@ extern void db_dispose_item(MP3FILE *pmp3);
|
||||||
extern void db_dispose_playlist(M3UFILE *pm3u);
|
extern void db_dispose_playlist(M3UFILE *pm3u);
|
||||||
|
|
||||||
|
|
||||||
#define DB_E_SUCCESS 0
|
#define DB_E_SUCCESS 0x00
|
||||||
#define DB_E_SQL_ERROR 1 /**< some kind of sql error - typically bad syntax */
|
#define DB_E_SQL_ERROR 0x01 /**< some kind of sql error - typically bad syntax */
|
||||||
#define DB_E_DUPLICATE_PLAYLIST 2 /**< playlist already exists when adding */
|
#define DB_E_DUPLICATE_PLAYLIST 0x02 /**< playlist already exists when adding */
|
||||||
#define DB_E_NOCLAUSE 3 /**< adding smart playlist with no clause */
|
#define DB_E_NOCLAUSE 0x03 /**< adding smart playlist with no clause */
|
||||||
#define DB_E_INVALIDTYPE 4 /**< trying to add playlist items to invalid type */
|
#define DB_E_INVALIDTYPE 0x04 /**< trying to add playlist items to invalid type */
|
||||||
#define DB_E_NOROWS 5 /**< sql query returned no rows */
|
#define DB_E_NOROWS 0x05 /**< sql query returned no rows */
|
||||||
#define DB_E_INVALID_PLAYLIST 6 /**< bad playlist id */
|
#define DB_E_INVALID_PLAYLIST 0x06 /**< bad playlist id */
|
||||||
#define DB_E_INVALID_SONGID 7 /**< bad song id */
|
#define DB_E_INVALID_SONGID 0x07 /**< bad song id */
|
||||||
|
#define DB_E_PARSE 0x08 /**< could not parse result */
|
||||||
|
|
||||||
#endif /* _DB_GENERIC_H_ */
|
#endif /* _DB_GENERIC_H_ */
|
||||||
|
|
|
@ -438,6 +438,7 @@ int db_sqlite_delete_playlist_item(int playlistid, int songid) {
|
||||||
int db_sqlite_add_playlist(char *name, int type, char *clause, char *path, int index, int *playlistid) {
|
int db_sqlite_add_playlist(char *name, int type, char *clause, char *path, int index, int *playlistid) {
|
||||||
int cnt=0;
|
int cnt=0;
|
||||||
int result=DB_E_SUCCESS;
|
int result=DB_E_SUCCESS;
|
||||||
|
char *criteria;
|
||||||
|
|
||||||
db_sqlite_get_int(E_DBG,&cnt,"select count(*) from playlists where "
|
db_sqlite_get_int(E_DBG,&cnt,"select count(*) from playlists where "
|
||||||
"upper(title)=upper('%q')",name);
|
"upper(title)=upper('%q')",name);
|
||||||
|
@ -455,11 +456,13 @@ int db_sqlite_add_playlist(char *name, int type, char *clause, char *path, int i
|
||||||
"values ('%q',%d,0,NULL,%d,'%q',%d)",name,type,time(NULL),path,index);
|
"values ('%q',%d,0,NULL,%d,'%q',%d)",name,type,time(NULL),path,index);
|
||||||
break;
|
break;
|
||||||
case PL_SMART: /* smart */
|
case PL_SMART: /* smart */
|
||||||
result=db_sqlite_get_int(E_DBG,&cnt,"select count (*) from songs where %s",clause);
|
criteria = db_sqlite_parse_smart(clause);
|
||||||
if(result != DB_E_SUCCESS) return result;
|
if(!criteria)
|
||||||
|
return DB_E_PARSE;
|
||||||
result = db_sqlite_exec(E_LOG,"insert into playlists "
|
result = db_sqlite_exec(E_LOG,"insert into playlists "
|
||||||
"(title,type,items,query,db_timestamp,idx) "
|
"(title,type,items,query,db_timestamp,idx) "
|
||||||
"values ('%q',%d,%d,'%q',%d,0)",name,PL_SMART,cnt,clause,time(NULL));
|
"values ('%q',%d,%d,'%q',%d,0)",name,PL_SMART,cnt,clause,time(NULL));
|
||||||
|
free(criteria);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue