mirror of
https://github.com/owntone/owntone-server.git
synced 2025-01-24 13:13:17 -05:00
Add idx to songs table to allow for index per path
This commit is contained in:
parent
8623fecab9
commit
f61fbb60b3
@ -60,7 +60,7 @@ typedef struct tag_db_functions {
|
||||
int(*dbs_end_scan)(void);
|
||||
int(*dbs_get_count)(CountType_t);
|
||||
MP3FILE*(*dbs_fetch_item)(int);
|
||||
MP3FILE*(*dbs_fetch_path)(char *);
|
||||
MP3FILE*(*dbs_fetch_path)(char *,int);
|
||||
M3UFILE*(*dbs_fetch_playlist)(char *, int);
|
||||
void(*dbs_dispose_item)(MP3FILE*);
|
||||
void(*dbs_dispose_playlist)(M3UFILE*);
|
||||
@ -628,11 +628,11 @@ MP3FILE *db_fetch_item(int id) {
|
||||
return retval;
|
||||
}
|
||||
|
||||
MP3FILE *db_fetch_path(char *path) {
|
||||
MP3FILE *db_fetch_path(char *path,int index) {
|
||||
MP3FILE *retval;
|
||||
|
||||
db_readlock();
|
||||
retval=db_current->dbs_fetch_path(path);
|
||||
retval=db_current->dbs_fetch_path(path, index);
|
||||
db_unlock();
|
||||
|
||||
return retval;
|
||||
|
@ -162,7 +162,7 @@ extern int db_delete_playlist(int playlistid);
|
||||
extern int db_delete_playlist_item(int playlistid, int songid);
|
||||
|
||||
extern MP3FILE *db_fetch_item(int id);
|
||||
extern MP3FILE *db_fetch_path(char *path);
|
||||
extern MP3FILE *db_fetch_path(char *path, int index);
|
||||
extern M3UFILE *db_fetch_playlist(char *path, int index);
|
||||
|
||||
|
||||
|
@ -364,7 +364,7 @@ int db_sqlite_delete_playlist(int playlistid) {
|
||||
* \param playlistid playlist to delete item from
|
||||
* \param songid song to delete from playlist
|
||||
*/
|
||||
extern int db_sqlite_delete_playlist_item(int playlistid, int songid) {
|
||||
int db_sqlite_delete_playlist_item(int playlistid, int songid) {
|
||||
int result;
|
||||
int playlist_type;
|
||||
int count;
|
||||
@ -509,6 +509,7 @@ int db_sqlite_add(MP3FILE *pmp3) {
|
||||
err=db_sqlite_exec(E_DBG,"INSERT INTO songs VALUES "
|
||||
"(NULL," // id
|
||||
"'%q'," // path
|
||||
"'%d'," // index
|
||||
"'%q'," // fname
|
||||
"'%q'," // title
|
||||
"'%q'," // artist
|
||||
@ -546,6 +547,7 @@ int db_sqlite_add(MP3FILE *pmp3) {
|
||||
"0," // force_update
|
||||
"'%q')", // codectype
|
||||
STR(pmp3->path),
|
||||
pmp3->index,
|
||||
STR(pmp3->fname),
|
||||
STR(pmp3->title),
|
||||
STR(pmp3->artist),
|
||||
@ -1316,6 +1318,7 @@ void db_sqlite_build_m3ufile(char **valarray, M3UFILE *pm3u) {
|
||||
pm3u->index=db_sqlite_atoi(valarray[7]);
|
||||
return;
|
||||
}
|
||||
|
||||
void db_sqlite_build_mp3file(char **valarray, MP3FILE *pmp3) {
|
||||
memset(pmp3,0x00,sizeof(MP3FILE));
|
||||
pmp3->id=db_sqlite_atoi(valarray[0]);
|
||||
@ -1356,6 +1359,7 @@ void db_sqlite_build_mp3file(char **valarray, MP3FILE *pmp3) {
|
||||
pmp3->sample_count=db_sqlite_atoi(valarray[35]);
|
||||
pmp3->force_update=db_sqlite_atoi(valarray[36]);
|
||||
pmp3->codectype=db_sqlite_strdup(valarray[37]);
|
||||
pmp3->index=db_sqlite_atoi(valarray[38]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1428,13 +1432,14 @@ MP3FILE *db_sqlite_fetch_item(int id) {
|
||||
*
|
||||
* \param path path of the file to retreive
|
||||
*/
|
||||
MP3FILE *db_sqlite_fetch_path(char *path) {
|
||||
MP3FILE *db_sqlite_fetch_path(char *path, int index) {
|
||||
int rows,cols;
|
||||
char **resarray;
|
||||
MP3FILE *pmp3=NULL;
|
||||
|
||||
db_sqlite_get_table(E_DBG,&resarray,&rows,&cols,
|
||||
"SELECT * FROM songs WHERE path='%q'",path);
|
||||
"SELECT * FROM songs WHERE path='%q' and idx=%d",
|
||||
path,index);
|
||||
|
||||
if(rows != 0) {
|
||||
pmp3=(MP3FILE*)malloc(sizeof(MP3FILE));
|
||||
@ -1712,6 +1717,57 @@ char *db_sqlite_upgrade_scripts[] = {
|
||||
"drop table tempplaylists;\n"
|
||||
"update config set value=5 where term='version';\n",
|
||||
|
||||
/* version 5 -> version 6 */
|
||||
"drop index idx_path;\n"
|
||||
"create temp table tempsongs as select * from songs;\n"
|
||||
"drop table songs;\n"
|
||||
"CREATE TABLE songs (\n"
|
||||
" id INTEGER PRIMARY KEY NOT NULL,\n"
|
||||
" path VARCHAR(4096) UNIQUE NOT NULL,\n"
|
||||
" fname VARCHAR(255) NOT NULL,\n"
|
||||
" title VARCHAR(1024) DEFAULT NULL,\n"
|
||||
" artist VARCHAR(1024) DEFAULT NULL,\n"
|
||||
" album VARCHAR(1024) DEFAULT NULL,\n"
|
||||
" genre VARCHAR(255) DEFAULT NULL,\n"
|
||||
" comment VARCHAR(4096) DEFAULT NULL,\n"
|
||||
" type VARCHAR(255) DEFAULT NULL,\n"
|
||||
" composer VARCHAR(1024) DEFAULT NULL,\n"
|
||||
" orchestra VARCHAR(1024) DEFAULT NULL,\n"
|
||||
" conductor VARCHAR(1024) DEFAULT NULL,\n"
|
||||
" grouping VARCHAR(1024) DEFAULT NULL,\n"
|
||||
" url VARCHAR(1024) DEFAULT NULL,\n"
|
||||
" bitrate INTEGER DEFAULT 0,\n"
|
||||
" samplerate INTEGER DEFAULT 0,\n"
|
||||
" song_length INTEGER DEFAULT 0,\n"
|
||||
" file_size INTEGER DEFAULT 0,\n"
|
||||
" year INTEGER DEFAULT 0,\n"
|
||||
" track INTEGER DEFAULT 0,\n"
|
||||
" total_tracks INTEGER DEFAULT 0,\n"
|
||||
" disc INTEGER DEFAULT 0,\n"
|
||||
" total_discs INTEGER DEFAULT 0,\n"
|
||||
" bpm INTEGER DEFAULT 0,\n"
|
||||
" compilation INTEGER DEFAULT 0,\n"
|
||||
" rating INTEGER DEFAULT 0,\n"
|
||||
" play_count INTEGER DEFAULT 0,\n"
|
||||
" data_kind INTEGER DEFAULT 0,\n"
|
||||
" item_kind INTEGER DEFAULT 0,\n"
|
||||
" description INTEGER DEFAULT 0,\n"
|
||||
" time_added INTEGER DEFAULT 0,\n"
|
||||
" time_modified INTEGER DEFAULT 0,\n"
|
||||
" time_played INTEGER DEFAULT 0,\n"
|
||||
" db_timestamp INTEGER DEFAULT 0,\n"
|
||||
" disabled INTEGER DEFAULT 0,\n"
|
||||
" sample_count INTEGER DEFAULT 0,\n"
|
||||
" force_update INTEGER DEFAULT 0,\n"
|
||||
" codectype VARCHAR(5) DEFAULT NULL,\n"
|
||||
" idx INTEGER NOT NULL\n"
|
||||
");\n"
|
||||
"begin transaction;\n"
|
||||
"insert into songs select *,0 from tempsongs;\n"
|
||||
"commit transaction;\n"
|
||||
"create index idx_path on songs(path);\n"
|
||||
"drop table tempsongs;\n"
|
||||
"update config set value=6 where term='version';\n",
|
||||
NULL /* No more versions! */
|
||||
};
|
||||
|
||||
|
@ -36,7 +36,7 @@ extern int db_sqlite_end_song_scan(void);
|
||||
extern int db_sqlite_end_scan(void);
|
||||
extern int db_sqlite_get_count(CountType_t type);
|
||||
extern MP3FILE *db_sqlite_fetch_item(int id);
|
||||
extern MP3FILE *db_sqlite_fetch_path(char *path);
|
||||
extern MP3FILE *db_sqlite_fetch_path(char *path,int index);
|
||||
extern M3UFILE *db_sqlite_fetch_playlist(char *path, int index);
|
||||
extern void db_sqlite_dispose_item(MP3FILE *pmp3);
|
||||
extern void db_sqlite_dispose_playlist(M3UFILE *pm3u);
|
||||
|
@ -311,7 +311,7 @@ int scan_path(char *path) {
|
||||
(strcasestr(config.extensions, ext))) {
|
||||
/* only scan if it's been changed, or empty db */
|
||||
modified_time=sb.st_mtime;
|
||||
pmp3=db_fetch_path(mp3_path);
|
||||
pmp3=db_fetch_path(mp3_path,0);
|
||||
|
||||
if((!pmp3) || (pmp3->db_timestamp < modified_time) ||
|
||||
(pmp3->force_update)) {
|
||||
@ -413,7 +413,7 @@ int scan_static_playlist(char *path) {
|
||||
DPRINTF(E_DBG,L_SCAN|L_PL,"Checking %s\n",real_path);
|
||||
|
||||
// might be valid, might not...
|
||||
if((pmp3=db_fetch_path(real_path))) {
|
||||
if((pmp3=db_fetch_path(real_path,0))) {
|
||||
db_add_playlist_item(playlistid,pmp3->id);
|
||||
db_dispose_item(pmp3);
|
||||
} else {
|
||||
|
@ -26,6 +26,7 @@
|
||||
|
||||
typedef struct tag_mp3file {
|
||||
char *path;
|
||||
int index;
|
||||
char *fname;
|
||||
char *title; /* TIT2 */
|
||||
char *artist; /* TPE1 */
|
||||
|
@ -538,7 +538,7 @@ int scan_xml_tracks_section(int action, char *info) {
|
||||
scan_xml_real_base_path,
|
||||
(char*)&song_path[strlen(scan_xml_itunes_decoded_base_path)]);
|
||||
realpath(physical_path,real_path);
|
||||
pmp3=db_fetch_path(real_path);
|
||||
pmp3=db_fetch_path(real_path,0);
|
||||
if(pmp3) {
|
||||
/* Update the existing record with the
|
||||
* updated stuff we got from the iTunes xml file
|
||||
|
Loading…
x
Reference in New Issue
Block a user