Implement subcontainer browsing, closing ticket #3

This commit is contained in:
Ron Pedde 2006-03-26 23:24:11 +00:00
parent 9a396eca29
commit 96753e59ca
2 changed files with 47 additions and 31 deletions

View File

@ -978,18 +978,10 @@ int db_sql_enum_start(char **pe, DBQUERYINFO *pinfo) {
query_count[0] = '\0';
query_rest[0] = '\0';
switch(pinfo->query_type) {
case queryTypeItems:
strcpy(query_select,"select * from songs ");
strcpy(query_count,"select count (*) from songs ");
break;
case queryTypePlaylists:
strcpy(query_select,"select * from playlists ");
strcpy(query_count,"select count (*) from playlists ");
break;
case queryTypePlaylistItems: /* Figure out if it's smart or dull */
/* get the where qualifier to filter based on playlist, if there */
if((pinfo->playlist_id) && (pinfo->playlist_id != 1)) {
err = db_sql_enum_begin_fn(pe, "select type,query from playlists "
"where id=%d",pinfo->playlist_id);
@ -1010,7 +1002,6 @@ int db_sql_enum_start(char **pe, DBQUERYINFO *pinfo) {
}
is_smart=(atoi(temprow[0]) == 1);
have_clause=1;
if(is_smart) {
if(!db_sql_parse_smart(NULL,&where_clause,temprow[1]))
where_clause = strdup("0");
@ -1021,31 +1012,43 @@ int db_sql_enum_start(char **pe, DBQUERYINFO *pinfo) {
return DB_E_PARSE;
}
sprintf(query_select,"select * from songs ");
sprintf(query_count,"select count(id) from songs ");
sprintf(query_rest,"where (%s)",where_clause);
snprintf(query_rest,sizeof(query_rest)," where (%s)",where_clause);
free(where_clause);
} else {
sprintf(query_count,"select count(id) from songs ");
/* We need to fix playlist queries to stop
* pulling the whole song db... the performance
* of these playlist queries sucks.
*/
#if 1
sprintf(query_select,"select * from songs ");
sprintf(query_rest,"where songs.id in (select songid from "
"playlistitems where playlistid=%d)",
pinfo->playlist_id);
#else
sprintf(query_select,"select * from songs,playlistitems ");
sprintf(query_rest,"where (songs.id=playlistitems.songid and "
"playlistitems.playlistid=%d) order by "
"playlistitems.id",pinfo->playlist_id);
#endif
}
sprintf(query_rest," where (songs.id in (select songid from "
"playlistitems where playlistid=%d))",
pinfo->playlist_id);
/*
sprintf(query_playlist,"(songs.id=playlistitems.songid and "
"playlistitems.playlistid=%d) order by "
"playlistitems.id",pinfo->playlist_id);
*/
}
have_clause=1;
db_sql_enum_end_fn(NULL);
}
switch(pinfo->query_type) {
case queryTypeItems:
strcpy(query_select,"select * from songs ");
strcpy(query_count,"select count (*) from songs ");
break;
case queryTypePlaylists:
strcpy(query_select,"select * from playlists ");
strcpy(query_count,"select count (*) from playlists ");
// sprintf(query_rest,"where (%s)",query_playlist);
break;
case queryTypePlaylistItems: /* Figure out if it's smart or dull */
sprintf(query_select,"select * from songs ");
sprintf(query_count,"select count(id) from songs ");
break;
/* Note that sqlite doesn't support COUNT(DISTINCT x) */

View File

@ -308,6 +308,7 @@ void daap_handler(WS_CONNINFO *pwsc) {
if(pqi->uri_count == 4) {
if(!strcasecmp(pqi->uri_sections[2],"browse")) {
/* /databases/id/browse/something */
pqi->playlist_id=1; /* browse the library */
dispatch_browse(pwsc,pqi);
dispatch_cleanup(pqi);
return;
@ -371,6 +372,13 @@ void daap_handler(WS_CONNINFO *pwsc) {
dispatch_cleanup(pqi);
return;
}
if((!strcasecmp(pqi->uri_sections[2],"containers")) &&
(!strcasecmp(pqi->uri_sections[4],"browse"))) {
pqi->playlist_id=atoi(pqi->uri_sections[3]);
dispatch_browse(pwsc,pqi);
dispatch_cleanup(pqi);
return;
}
}
}
@ -1208,17 +1216,22 @@ void dispatch_browse(WS_CONNINFO *pwsc, DBQUERYINFO *pqi) {
int list_length;
unsigned char *block;
char *response_type;
int which_field=5;
if(!strcmp(pqi->uri_sections[3],"artists")) {
if(strcasecmp(pqi->uri_sections[2],"browse") == 0) {
which_field = 3;
}
if(!strcmp(pqi->uri_sections[which_field],"artists")) {
response_type = "abar";
pqi->query_type=queryTypeBrowseArtists;
} else if(!strcmp(pqi->uri_sections[3],"genres")) {
} else if(!strcmp(pqi->uri_sections[which_field],"genres")) {
response_type = "abgn";
pqi->query_type=queryTypeBrowseGenres;
} else if(!strcmp(pqi->uri_sections[3],"albums")) {
} else if(!strcmp(pqi->uri_sections[which_field],"albums")) {
response_type = "abal";
pqi->query_type=queryTypeBrowseAlbums;
} else if(!strcmp(pqi->uri_sections[3],"composers")) {
} else if(!strcmp(pqi->uri_sections[which_field],"composers")) {
response_type = "abcp";
pqi->query_type=queryTypeBrowseComposers;
} else {