Force a full rescan when the database version is too new

This commit is contained in:
Ron Pedde 2007-05-03 00:18:25 +00:00
parent f3d5caedb1
commit 61f5e96ea7
6 changed files with 22 additions and 14 deletions

View File

@ -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);
}

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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);