From 88dde32fc7bcbd51a54a34c4a6d71457972bb13c Mon Sep 17 00:00:00 2001 From: Julien BLACHE <jb@jblache.org> Date: Sat, 6 Mar 2010 17:39:35 +0100 Subject: [PATCH] Recompute all songalbumids at startup Due to the two Murmur64 implementations for 64 and 32bit machines, the hash is not compatible when moving the SQLite DB between 32/64 bit hosts. So we'll recompute all the songalbumids at startup, just in case. --- src/db.c | 19 +++++++++++++++++++ src/db.h | 3 +++ src/filescanner.c | 5 +++++ 3 files changed, 27 insertions(+) diff --git a/src/db.c b/src/db.c index 9c188f68..c9ce861b 100644 --- a/src/db.c +++ b/src/db.c @@ -1118,6 +1118,25 @@ db_files_get_count(void) return db_get_count("SELECT COUNT(*) FROM files WHERE disabled = 0;"); } +void +db_files_update_songalbumid(void) +{ +#define Q_SONGALBUMID "UPDATE files SET songalbumid = daap_songalbumid(album_artist, album);" + char *errmsg; + int ret; + + DPRINTF(E_DBG, L_DB, "Running query '%s'\n", Q_SONGALBUMID); + + errmsg = NULL; + ret = sqlite3_exec(hdl, Q_SONGALBUMID, NULL, NULL, &errmsg); + if (ret != SQLITE_OK) + DPRINTF(E_LOG, L_DB, "Error updating songalbumid: %s\n", errmsg); + + sqlite3_free(errmsg); + +#undef Q_SONGALBUMID +} + void db_file_inc_playcount(int id) { diff --git a/src/db.h b/src/db.h index 2c690a6e..19328a98 100644 --- a/src/db.h +++ b/src/db.h @@ -289,6 +289,9 @@ db_query_fetch_string(struct query_params *qp, char **string); int db_files_get_count(void); +void +db_files_update_songalbumid(void); + void db_file_inc_playcount(int id); diff --git a/src/filescanner.c b/src/filescanner.c index fca1c57a..da2f4478 100644 --- a/src/filescanner.c +++ b/src/filescanner.c @@ -697,6 +697,11 @@ filescanner(void *arg) pthread_exit(NULL); } + /* Recompute all songalbumids, in case the SQLite DB got transferred + * to a different host; the hash is not portable. + */ + db_files_update_songalbumid(); + bulk_scan(); if (!scan_exit)