From 1c7c77be1c2caad87dc7f8310f8c1def32ab3117 Mon Sep 17 00:00:00 2001 From: Ron Pedde Date: Mon, 24 Oct 2005 00:17:56 +0000 Subject: [PATCH] Check for valid playlist on add --- src/db-generic.h | 17 +++++++++-------- src/dbs-sqlite.c | 7 +++++-- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/db-generic.h b/src/db-generic.h index 2dfa07d4..49331c25 100644 --- a/src/db-generic.h +++ b/src/db-generic.h @@ -187,13 +187,14 @@ extern void db_dispose_item(MP3FILE *pmp3); extern void db_dispose_playlist(M3UFILE *pm3u); -#define DB_E_SUCCESS 0 -#define DB_E_SQL_ERROR 1 /**< some kind of sql error - typically bad syntax */ -#define DB_E_DUPLICATE_PLAYLIST 2 /**< playlist already exists when adding */ -#define DB_E_NOCLAUSE 3 /**< adding smart playlist with no clause */ -#define DB_E_INVALIDTYPE 4 /**< trying to add playlist items to invalid type */ -#define DB_E_NOROWS 5 /**< sql query returned no rows */ -#define DB_E_INVALID_PLAYLIST 6 /**< bad playlist id */ -#define DB_E_INVALID_SONGID 7 /**< bad song id */ +#define DB_E_SUCCESS 0x00 +#define DB_E_SQL_ERROR 0x01 /**< some kind of sql error - typically bad syntax */ +#define DB_E_DUPLICATE_PLAYLIST 0x02 /**< playlist already exists when adding */ +#define DB_E_NOCLAUSE 0x03 /**< adding smart playlist with no clause */ +#define DB_E_INVALIDTYPE 0x04 /**< trying to add playlist items to invalid type */ +#define DB_E_NOROWS 0x05 /**< sql query returned no rows */ +#define DB_E_INVALID_PLAYLIST 0x06 /**< bad playlist id */ +#define DB_E_INVALID_SONGID 0x07 /**< bad song id */ +#define DB_E_PARSE 0x08 /**< could not parse result */ #endif /* _DB_GENERIC_H_ */ diff --git a/src/dbs-sqlite.c b/src/dbs-sqlite.c index 7c0dad63..195c6689 100644 --- a/src/dbs-sqlite.c +++ b/src/dbs-sqlite.c @@ -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 cnt=0; int result=DB_E_SUCCESS; + char *criteria; db_sqlite_get_int(E_DBG,&cnt,"select count(*) from playlists where " "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); break; case PL_SMART: /* smart */ - result=db_sqlite_get_int(E_DBG,&cnt,"select count (*) from songs where %s",clause); - if(result != DB_E_SUCCESS) return result; + criteria = db_sqlite_parse_smart(clause); + if(!criteria) + return DB_E_PARSE; result = db_sqlite_exec(E_LOG,"insert into playlists " "(title,type,items,query,db_timestamp,idx) " "values ('%q',%d,%d,'%q',%d,0)",name,PL_SMART,cnt,clause,time(NULL)); + free(criteria); break; }