[db] Remove special icy update function, add db_queue_update_item()

- we will use the latter generalised form from now on, even though it is perhaps a tad slower
This commit is contained in:
ejurgensen 2017-01-22 23:10:15 +01:00
parent e92152cadb
commit 4d4a4ffd70
2 changed files with 92 additions and 135 deletions

221
src/db.c
View File

@ -356,14 +356,12 @@ db_escape_string(const char *str)
void void
free_pi(struct pairing_info *pi, int content_only) free_pi(struct pairing_info *pi, int content_only)
{ {
if (pi->remote_id) if (!pi)
free(pi->remote_id); return;
if (pi->name) free(pi->remote_id);
free(pi->name); free(pi->name);
free(pi->guid);
if (pi->guid)
free(pi->guid);
if (!content_only) if (!content_only)
free(pi); free(pi);
@ -374,77 +372,33 @@ free_pi(struct pairing_info *pi, int content_only)
void void
free_mfi(struct media_file_info *mfi, int content_only) free_mfi(struct media_file_info *mfi, int content_only)
{ {
if (mfi->path) if (!mfi)
free(mfi->path); return;
if (mfi->fname) free(mfi->path);
free(mfi->fname); free(mfi->fname);
free(mfi->title);
if (mfi->title) free(mfi->artist);
free(mfi->title); free(mfi->album);
free(mfi->genre);
if (mfi->artist) free(mfi->comment);
free(mfi->artist); free(mfi->type);
free(mfi->composer);
if (mfi->album) free(mfi->orchestra);
free(mfi->album); free(mfi->conductor);
free(mfi->grouping);
if (mfi->genre) free(mfi->description);
free(mfi->genre); free(mfi->codectype);
free(mfi->album_artist);
if (mfi->comment) free(mfi->tv_series_name);
free(mfi->comment); free(mfi->tv_episode_num_str);
free(mfi->tv_network_name);
if (mfi->type) free(mfi->title_sort);
free(mfi->type); free(mfi->artist_sort);
free(mfi->album_sort);
if (mfi->composer) free(mfi->composer_sort);
free(mfi->composer); free(mfi->album_artist_sort);
free(mfi->virtual_path);
if (mfi->orchestra)
free(mfi->orchestra);
if (mfi->conductor)
free(mfi->conductor);
if (mfi->grouping)
free(mfi->grouping);
if (mfi->description)
free(mfi->description);
if (mfi->codectype)
free(mfi->codectype);
if (mfi->album_artist)
free(mfi->album_artist);
if (mfi->tv_series_name)
free(mfi->tv_series_name);
if (mfi->tv_episode_num_str)
free(mfi->tv_episode_num_str);
if (mfi->tv_network_name)
free(mfi->tv_network_name);
if (mfi->title_sort)
free(mfi->title_sort);
if (mfi->artist_sort)
free(mfi->artist_sort);
if (mfi->album_sort)
free(mfi->album_sort);
if (mfi->composer_sort)
free(mfi->composer_sort);
if (mfi->album_artist_sort)
free(mfi->album_artist_sort);
if (mfi->virtual_path)
free(mfi->virtual_path);
if (!content_only) if (!content_only)
free(mfi); free(mfi);
@ -489,17 +443,13 @@ unicode_fixup_mfi(struct media_file_info *mfi)
void void
free_pli(struct playlist_info *pli, int content_only) free_pli(struct playlist_info *pli, int content_only)
{ {
if (pli->title) if (!pli)
free(pli->title); return;
if (pli->query) free(pli->title);
free(pli->query); free(pli->query);
free(pli->path);
if (pli->path) free(pli->virtual_path);
free(pli->path);
if (pli->virtual_path)
free(pli->virtual_path);
if (!content_only) if (!content_only)
free(pli); free(pli);
@ -510,8 +460,10 @@ free_pli(struct playlist_info *pli, int content_only)
void void
free_di(struct directory_info *di, int content_only) free_di(struct directory_info *di, int content_only)
{ {
if (di->virtual_path) if (!di)
free(di->virtual_path); return;
free(di->virtual_path);
if (!content_only) if (!content_only)
free(di); free(di);
@ -3952,29 +3904,25 @@ db_speaker_clear_all(void)
void void
free_queue_item(struct db_queue_item *queue_item, int content_only) free_queue_item(struct db_queue_item *queue_item, int content_only)
{ {
if (queue_item->path) if (!queue_item)
free(queue_item->path); return;
if (queue_item->virtual_path)
free(queue_item->virtual_path);
if (queue_item->title)
free(queue_item->title);
if (queue_item->artist)
free(queue_item->artist);
if (queue_item->album_artist)
free(queue_item->album_artist);
if (queue_item->album)
free(queue_item->album);
if (queue_item->genre)
free(queue_item->genre);
if (queue_item->artist_sort)
free(queue_item->artist_sort);
if (queue_item->album_sort)
free(queue_item->album_sort);
if (queue_item->album_artist_sort)
free(queue_item->album_artist_sort);
if (!content_only && queue_item) free(queue_item->path);
free(queue_item->virtual_path);
free(queue_item->title);
free(queue_item->artist);
free(queue_item->album_artist);
free(queue_item->album);
free(queue_item->genre);
free(queue_item->artist_sort);
free(queue_item->album_sort);
free(queue_item->album_artist_sort);
free(queue_item->artwork_url);
if (!content_only)
free(queue_item); free(queue_item);
else
memset(queue_item, 0, sizeof(struct db_queue_item));
} }
/* /*
@ -4047,29 +3995,6 @@ queue_inc_version_and_notify()
listener_notify(LISTENER_QUEUE); listener_notify(LISTENER_QUEUE);
} }
void
db_queue_update_icymetadata(int id, char *artist, char *album)
{
#define Q_TMPL "UPDATE queue SET artist = TRIM(%Q), album = TRIM(%Q) WHERE id = %d;"
char *query;
if (id == 0)
return;
query = sqlite3_mprintf(Q_TMPL, artist, album, id);
if (!query)
{
DPRINTF(E_LOG, L_DB, "Out of memory for query string\n");
return;
}
db_query_run(query, 1, 0);
queue_inc_version_and_notify();
#undef Q_TMPL
}
static int static int
queue_add_file(struct db_media_file_info *dbmfi, int pos, int shuffle_pos) queue_add_file(struct db_media_file_info *dbmfi, int pos, int shuffle_pos)
{ {
@ -4102,6 +4027,35 @@ queue_add_file(struct db_media_file_info *dbmfi, int pos, int shuffle_pos)
#undef Q_TMPL #undef Q_TMPL
} }
int
db_queue_update_item(struct db_queue_item *qi)
{
#define Q_TMPL "UPDATE queue SET " \
"file_id = %d, song_length = %d, data_kind = %d, media_kind = %d, " \
"pos = %d, shuffle_pos = %d, path = '%q', virtual_path = %Q, " \
"title = %Q, artist = %Q, album_artist = %Q, album = %Q, " \
"genre = %Q, songalbumid = %" PRIi64 ", time_modified = %d, " \
"artist_sort = %Q, album_sort = %Q, album_artist_sort = %Q, " \
"year = %d, track = %d, disc = %d, artwork_url = %Q " \
"WHERE id = %d;"
char *query;
int ret;
query = sqlite3_mprintf(Q_TMPL,
qi->file_id, qi->song_length, qi->data_kind, qi->media_kind,
qi->pos, qi->shuffle_pos, qi->path, qi->virtual_path,
qi->title, qi->artist, qi->album_artist, qi->album,
qi->genre, qi->songalbumid, qi->time_modified,
qi->artist_sort, qi->album_sort, qi->album_artist_sort,
qi->year, qi->track, qi->disc, qi->artwork_url,
qi->id);
ret = db_query_run(query, 1, 0);
return ret;
#undef Q_TMPL
}
/* /*
* Adds the files matching the given query to the queue after the item with the given item id * Adds the files matching the given query to the queue after the item with the given item id
* *
@ -4434,6 +4388,7 @@ queue_enum_fetch(struct query_params *query_params, struct db_queue_item *queue_
queue_item->year = sqlite3_column_int(query_params->stmt, 19); queue_item->year = sqlite3_column_int(query_params->stmt, 19);
queue_item->track = sqlite3_column_int(query_params->stmt, 20); queue_item->track = sqlite3_column_int(query_params->stmt, 20);
queue_item->disc = sqlite3_column_int(query_params->stmt, 21); queue_item->disc = sqlite3_column_int(query_params->stmt, 21);
queue_item->artwork_url = strdup_if((char *)sqlite3_column_text(query_params->stmt, 22), keep_item);
return 0; return 0;
} }

View File

@ -418,6 +418,8 @@ struct db_queue_item
uint32_t year; uint32_t year;
uint32_t track; uint32_t track;
uint32_t disc; uint32_t disc;
char *artwork_url;
}; };
char * char *
@ -687,8 +689,8 @@ db_speaker_clear_all(void);
int int
db_queue_get_version(); db_queue_get_version();
void int
db_queue_update_icymetadata(int id, char *artist, char *album); db_queue_update_item(struct db_queue_item *queue_item);
int int
db_queue_add_by_queryafteritemid(struct query_params *qp, uint32_t item_id); db_queue_add_by_queryafteritemid(struct query_params *qp, uint32_t item_id);