mirror of
https://github.com/owntone/owntone-server.git
synced 2025-01-24 13:13:17 -05:00
Force a full rescan when the database version is too new
This commit is contained in:
parent
f3d5caedb1
commit
61f5e96ea7
@ -53,7 +53,7 @@
|
||||
typedef struct tag_db_functions {
|
||||
char *name;
|
||||
int(*dbs_open)(char **, char *);
|
||||
int(*dbs_init)(int*);
|
||||
int(*dbs_init)(int);
|
||||
int(*dbs_deinit)(void);
|
||||
int(*dbs_add)(char **, MP3FILE*, int*);
|
||||
int(*dbs_add_playlist)(char **, char *, int, char *,char *, int, int *);
|
||||
@ -284,7 +284,7 @@ int db_open(char **pe, char *type, char *parameters) {
|
||||
*
|
||||
* \param reload whether or not to do a full reload of the database
|
||||
*/
|
||||
int db_init(int *reload) {
|
||||
int db_init(int reload) {
|
||||
return db_current->dbs_init(reload);
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ typedef struct tag_dbqueryinfo {
|
||||
} DBQUERYINFO;
|
||||
|
||||
extern int db_open(char **pe, char *type, char *parameters);
|
||||
extern int db_init(int *reload);
|
||||
extern int db_init(int reload);
|
||||
extern int db_deinit(void);
|
||||
|
||||
extern int db_revision(void);
|
||||
|
@ -156,12 +156,17 @@ int db_sqlite2_open(char **pe, char *dsn) {
|
||||
if(pe) { free(*pe); }
|
||||
/* we'll catch this on the init */
|
||||
DPRINTF(E_LOG,L_DB,"Can't get db version. New database?\n");
|
||||
} else if(ver != DB_SQLITE2_VERSION) {
|
||||
} else if(ver < DB_SQLITE2_VERSION) {
|
||||
/* we'll deal with this in the db handler */
|
||||
DPRINTF(E_LOG,L_DB,"Old database version: %d, expecting %d\n",
|
||||
ver, DB_SQLITE2_VERSION);
|
||||
db_get_error(pe,DB_E_WRONGVERSION);
|
||||
return DB_E_WRONGVERSION;
|
||||
} else if(ver > DB_SQLITE2_VERSION) { /* Back-grade from nightlies ? */
|
||||
DPRINTF(E_LOG,L_DB,"Bad db version: %d, expecting %d\n",
|
||||
ver, DB_SQLITE2_VERSION);
|
||||
db_sqlite2_exec(pe,E_FATAL,"insert into config (term, value) "
|
||||
"values ('rescan',1)");
|
||||
}
|
||||
|
||||
return DB_E_SUCCESS;
|
||||
|
@ -152,11 +152,14 @@ int db_sqlite3_open(char **pe, char *dsn) {
|
||||
if(pe) { free(*pe); }
|
||||
/* we'll catch this on the init */
|
||||
DPRINTF(E_LOG,L_DB,"Can't get db version. New database?\n");
|
||||
} else if(ver != DB_SQLITE3_VERSION) {
|
||||
} else if(ver < DB_SQLITE3_VERSION) {
|
||||
DPRINTF(E_LOG,L_DB,"Old database version: %d, expecting %d\n",
|
||||
ver,DB_SQLITE3_VERSION);
|
||||
db_get_error(pe,DB_E_WRONGVERSION);
|
||||
return DB_E_WRONGVERSION;
|
||||
} else if(ver > DB_SQLITE3_VERSION) {
|
||||
db_sqlite3_exec(pe,E_FATAL,"insert into config (term, value) "
|
||||
"values ('rescan',1)");
|
||||
}
|
||||
|
||||
return DB_E_SUCCESS;
|
||||
|
16
src/db-sql.c
16
src/db-sql.c
@ -383,10 +383,11 @@ int db_sql_open(char **pe, char *parameters) {
|
||||
* on return, reload is set to 1 if the db MUST be rescanned
|
||||
* @returns DB_E_SUCCESS on success, error code otherwise
|
||||
*/
|
||||
int db_sql_init(int *reload) {
|
||||
int db_sql_init(int reload) {
|
||||
int items;
|
||||
int rescan = 0;
|
||||
int err;
|
||||
int do_reload = reload;
|
||||
|
||||
err=db_sql_get_count(NULL,&items, countSongs);
|
||||
if(err != DB_E_SUCCESS)
|
||||
@ -394,23 +395,22 @@ int db_sql_init(int *reload) {
|
||||
|
||||
/* check if a request has been written into the db (by a db upgrade?) */
|
||||
if(db_sql_fetch_int(NULL,&rescan,"select value from config where "
|
||||
"term='rescan'") == DB_E_SUCCESS)
|
||||
{
|
||||
"term='rescan'") == DB_E_SUCCESS) {
|
||||
if(rescan)
|
||||
*reload=1;
|
||||
do_reload=1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(*reload || (!items)) {
|
||||
/* we could pass back a status to describe whether a reaload was
|
||||
* required (for reasons other than expicit request)
|
||||
*/
|
||||
if(do_reload || (!items)) {
|
||||
DPRINTF(E_LOG,L_DB,"Full reload...\n");
|
||||
db_sql_event_fn(DB_SQL_EVENT_FULLRELOAD);
|
||||
db_sql_reload=1;
|
||||
*reload=1;
|
||||
} else {
|
||||
db_sql_event_fn(DB_SQL_EVENT_STARTUP);
|
||||
db_sql_reload=0;
|
||||
*reload=0;
|
||||
}
|
||||
|
||||
return DB_E_SUCCESS;
|
||||
|
@ -32,7 +32,7 @@ extern int db_sql_open_sqlite3(char **pe, char *parameters);
|
||||
#endif
|
||||
|
||||
extern int db_sql_open(char **pe, char *parameters);
|
||||
extern int db_sql_init(int *reload);
|
||||
extern int db_sql_init(int reload);
|
||||
extern int db_sql_deinit(void);
|
||||
extern int db_sql_escape(char *buffer, int *size, char *fmt, ...);
|
||||
extern int db_sql_add(char **pe, MP3FILE *pmp3, int *id);
|
||||
|
Loading…
x
Reference in New Issue
Block a user