fix sql layout to store disc_num on song

The album id is hashed from the string, so joining it from the shared album entry doesn't make much sense
This commit is contained in:
Adrian Ulrich committed 2017-01-02 13:01:30 +01:00
1 parent e92e24ec00
commit e4cbf3e4fe
5 files changed
+29 -11

No files matched your search

@@ -415,6 +415,10 @@ public class MediaLibrary {
* The position in the album of this song
*/
String SONG_NUMBER = "song_num";
/**
* The disc in a multi-disc album containing this song
*/
String DISC_NUMBER = "disc_num";
/**
* The album where this song belongs to
*/
@@ -459,10 +463,6 @@ public class MediaLibrary {
* The sortable title of this album
*/
String ALBUM_SORT = "album_sort";
/**
* The disc number of this album
*/
String DISC_NUMBER = "disc_num";
/**
* The primary contributor / artist reference for this album
*/
@@ -35,7 +35,7 @@ public class MediaLibraryBackend extends SQLiteOpenHelper {
/**
* The database version we are using
*/
private static final int DATABASE_VERSION = 1;
private static final int DATABASE_VERSION = 20170101;
/**
* on-disk file to store the database
*/
@@ -78,6 +78,7 @@ public class MediaLibraryBackend extends SQLiteOpenHelper {
*/
@Override
public void onUpgrade(SQLiteDatabase dbh, int oldVersion, int newVersion) {
MediaSchema.upgradeDatabaseSchema(dbh, oldVersion);
}
/**
@@ -383,6 +383,7 @@ public class MediaScanner implements Handler.Callback {
v.put(MediaLibrary.SongColumns.ALBUM_ID, albumId);
v.put(MediaLibrary.SongColumns.DURATION, tags.getFirst(MediaMetadataExtractor.DURATION));
v.put(MediaLibrary.SongColumns.SONG_NUMBER, tags.getFirst(MediaMetadataExtractor.TRACK_NUMBER));
v.put(MediaLibrary.SongColumns.DISC_NUMBER, tags.getFirst(MediaMetadataExtractor.DISC_NUMBER));
v.put(MediaLibrary.SongColumns.YEAR, tags.getFirst(MediaMetadataExtractor.YEAR));
v.put(MediaLibrary.SongColumns.PATH, path);
mBackend.insert(MediaLibrary.TABLE_SONGS, null, v);
@@ -393,7 +394,6 @@ public class MediaScanner implements Handler.Callback {
v.put(MediaLibrary.AlbumColumns.ALBUM_SORT, MediaLibrary.keyFor(album));
v.put(MediaLibrary.AlbumColumns.PRIMARY_ARTIST_ID, artistId);
v.put(MediaLibrary.AlbumColumns.PRIMARY_ALBUM_YEAR,tags.getFirst(MediaMetadataExtractor.YEAR));
v.put(MediaLibrary.AlbumColumns.DISC_NUMBER, tags.getFirst(MediaMetadataExtractor.DISC_NUMBER));
mBackend.insert(MediaLibrary.TABLE_ALBUMS, null, v);
v.clear();
@@ -28,6 +28,7 @@ public class MediaSchema {
+ MediaLibrary.SongColumns.TITLE +" TEXT NOT NULL, "
+ MediaLibrary.SongColumns.TITLE_SORT +" VARCHAR(64) NOT NULL, "
+ MediaLibrary.SongColumns.SONG_NUMBER +" INTEGER, "
+ MediaLibrary.SongColumns.DISC_NUMBER +" INTEGER, "
+ MediaLibrary.SongColumns.YEAR +" INTEGER, "
+ MediaLibrary.SongColumns.ALBUM_ID +" INTEGER NOT NULL, "
+ MediaLibrary.SongColumns.PLAYCOUNT +" INTEGER NOT NULL DEFAULT 0, "
@@ -44,7 +45,6 @@ public class MediaSchema {
+ MediaLibrary.AlbumColumns._ID +" INTEGER PRIMARY KEY, "
+ MediaLibrary.AlbumColumns.ALBUM +" TEXT NOT NULL, "
+ MediaLibrary.AlbumColumns.ALBUM_SORT +" VARCHAR(64) NOT NULL, "
+ MediaLibrary.AlbumColumns.DISC_NUMBER +" INTEGER, "
+ MediaLibrary.AlbumColumns.PRIMARY_ALBUM_YEAR+" INTEGER, "
+ MediaLibrary.AlbumColumns.PRIMARY_ARTIST_ID +" INTEGER NOT NULL DEFAULT 0, "
+ MediaLibrary.AlbumColumns.MTIME +" TIMESTAMP DEFAULT CURRENT_TIMESTAMP "
@@ -202,4 +202,21 @@ public class MediaSchema {
dbh.execSQL(VIEW_CREATE_PLAYLIST_SONGS);
}
/**
* Upgrades an existing database
*
* @param dbh the writeable dbh to use
* @param oldVersion the version of the old (aka: existing) database
*/
public static void upgradeDatabaseSchema(SQLiteDatabase dbh, int oldVersion) {
if (oldVersion < 20170101) {
// this is ugly but was never released as a stable version, so
// it's good enough to keep playlists for testers
dbh.execSQL("DROP TABLE songs");
dbh.execSQL("DROP TABLE albums");
dbh.execSQL(DATABASE_CREATE_SONGS);
dbh.execSQL(DATABASE_CREATE_ALBUMS);
}
}
}
@@ -203,10 +203,10 @@ public class MediaAdapter
mFieldKeys = new String[] { MediaLibrary.SongColumns.TITLE_SORT, MediaLibrary.AlbumColumns.ALBUM_SORT, MediaLibrary.ContributorColumns.ARTIST_SORT };
mSortEntries = new int[] { R.string.name, R.string.artist_album_track, R.string.artist_album_title, R.string.album_track, R.string.year, R.string.date_added, R.string.song_playcount };
mAdapterSortValues = new String[] { MediaLibrary.SongColumns.TITLE_SORT+" %1$s",
MediaLibrary.ContributorColumns.ARTIST_SORT+" %1$s,"+MediaLibrary.AlbumColumns.ALBUM_SORT+" %1$s,"+MediaLibrary.AlbumColumns.DISC_NUMBER+","+MediaLibrary.SongColumns.SONG_NUMBER,
MediaLibrary.ContributorColumns.ARTIST_SORT+" %1$s,"+MediaLibrary.AlbumColumns.ALBUM_SORT+" %1$s,"+MediaLibrary.SongColumns.DISC_NUMBER+","+MediaLibrary.SongColumns.SONG_NUMBER,
MediaLibrary.ContributorColumns.ARTIST_SORT+" %1$s,"+MediaLibrary.AlbumColumns.ALBUM_SORT+" %1$s,"+MediaLibrary.SongColumns.TITLE_SORT+" %1$s",
MediaLibrary.AlbumColumns.ALBUM_SORT+" %1$s,"+MediaLibrary.AlbumColumns.DISC_NUMBER+","+MediaLibrary.SongColumns.SONG_NUMBER,
MediaLibrary.SongColumns.YEAR+" %1$s,"+MediaLibrary.AlbumColumns.ALBUM_SORT+" %1$s,"+MediaLibrary.AlbumColumns.DISC_NUMBER+","+MediaLibrary.SongColumns.SONG_NUMBER,
MediaLibrary.AlbumColumns.ALBUM_SORT+" %1$s,"+MediaLibrary.SongColumns.DISC_NUMBER+","+MediaLibrary.SongColumns.SONG_NUMBER,
MediaLibrary.SongColumns.YEAR+" %1$s,"+MediaLibrary.AlbumColumns.ALBUM_SORT+" %1$s,"+MediaLibrary.SongColumns.DISC_NUMBER+","+MediaLibrary.SongColumns.SONG_NUMBER,
MediaLibrary.SongColumns.MTIME+" %1$s",
MediaLibrary.SongColumns.PLAYCOUNT+" %1$s",
};
@@ -311,7 +311,7 @@ public class MediaAdapter
if (mType == MediaUtils.TYPE_ARTIST)
sortRaw += ", "+MediaLibrary.AlbumColumns.ALBUM_SORT+" %1$s";
// and this is for all types:
sortRaw += ", "+MediaLibrary.AlbumColumns.DISC_NUMBER+", "+MediaLibrary.SongColumns.SONG_NUMBER;
sortRaw += ", "+MediaLibrary.SongColumns.DISC_NUMBER+", "+MediaLibrary.SongColumns.SONG_NUMBER;
}
// ...and assemble the SQL string we are really going to use