The Free Software Media System - Server Backend & API
Add mapping from BaseItemKind to Type.FullName for querying
Cody Robibero249a1ca955a2
diff --git a/Emby.Server.Implementations/Data/SqliteItemRepository.cs b/Emby.Server.Implementations/Data/SqliteItemRepository.csindex 48c3710cb5..8fe0b98d0c 100644--- a/Emby.Server.Implementations/Data/SqliteItemRepository.cs+++ b/Emby.Server.Implementations/Data/SqliteItemRepository.cs@@ -62,7 +62,7 @@ namespace Emby.Server.Implementations.Dataprivate readonly ItemFields[] _allItemFields = Enum.GetValues<ItemFields>();- private static readonly string[] _retriveItemColumns =+ private static readonly string[] _retrieveItemColumns ={"type","data",@@ -133,7 +133,7 @@ namespace Emby.Server.Implementations.Data"OwnerId"};- private static readonly string _retriveItemColumnsSelectQuery = $"select {string.Join(',', _retriveItemColumns)} from TypedBaseItems where guid = @guid";+ private static readonly string _retrieveItemColumnsSelectQuery = $"select {string.Join(',', _retrieveItemColumns)} from TypedBaseItems where guid = @guid";private static readonly string[] _mediaStreamSaveColumns ={@@ -284,6 +284,43 @@ namespace Emby.Server.Implementations.Dataprivate readonly Dictionary<string, string> _types = GetTypeMapDictionary();+ private static readonly Dictionary<BaseItemKind, string> _baseItemKindNames = new()+ {+ { BaseItemKind.AggregateFolder, typeof(AggregateFolder).FullName },+ { BaseItemKind.Audio, typeof(Audio).FullName },+ { BaseItemKind.AudioBook, typeof(AudioBook).FullName },+ { BaseItemKind.BasePluginFolder, typeof(BasePluginFolder).FullName },+ { BaseItemKind.Book, typeof(Book).FullName },+ { BaseItemKind.BoxSet, typeof(BoxSet).FullName },+ { BaseItemKind.Channel, typeof(Channel).FullName },+ { BaseItemKind.CollectionFolder, typeof(CollectionFolder).FullName },+ { BaseItemKind.Episode, typeof(Episode).FullName },+ { BaseItemKind.Folder, typeof(Folder).FullName },+ { BaseItemKind.Genre, typeof(Genre).FullName },+ { BaseItemKind.Movie, typeof(Movie).FullName },+ { BaseItemKind.LiveTvChannel, typeof(LiveTvChannel).FullName },+ { BaseItemKind.LiveTvProgram, typeof(LiveTvProgram).FullName },+ { BaseItemKind.MusicAlbum, typeof(MusicAlbum).FullName },+ { BaseItemKind.MusicArtist, typeof(MusicArtist).FullName },+ { BaseItemKind.MusicGenre, typeof(MusicGenre).FullName },+ { BaseItemKind.MusicVideo, typeof(MusicVideo).FullName },+ { BaseItemKind.Person, typeof(Person).FullName },+ { BaseItemKind.Photo, typeof(Photo).FullName },+ { BaseItemKind.PhotoAlbum, typeof(PhotoAlbum).FullName },+ { BaseItemKind.Playlist, typeof(Playlist).FullName },+ { BaseItemKind.PlaylistsFolder, typeof(PlaylistsFolder).FullName },+ { BaseItemKind.Season, typeof(Season).FullName },+ { BaseItemKind.Series, typeof(Series).FullName },+ { BaseItemKind.Studio, typeof(Studio).FullName },+ { BaseItemKind.Trailer, typeof(Trailer).FullName },+ { BaseItemKind.TvChannel, typeof(LiveTvChannel).FullName },+ { BaseItemKind.TvProgram, typeof(LiveTvProgram).FullName },+ { BaseItemKind.UserRootFolder, typeof(UserRootFolder).FullName },+ { BaseItemKind.UserView, typeof(UserView).FullName },+ { BaseItemKind.Video, typeof(Video).FullName },+ { BaseItemKind.Year, typeof(Year).FullName }+ };+static SqliteItemRepository(){var queryPrefixText = new StringBuilder();@@ -1319,7 +1356,7 @@ namespace Emby.Server.Implementations.Datausing (var connection = GetConnection(true)){- using (var statement = PrepareStatement(connection, _retriveItemColumnsSelectQuery))+ using (var statement = PrepareStatement(connection, _retrieveItemColumnsSelectQuery)){statement.TryBind("@guid", id);@@ -2629,7 +2666,7 @@ namespace Emby.Server.Implementations.Dataquery.Limit = query.Limit.Value + 4;}- var columns = _retriveItemColumns.ToList();+ var columns = _retrieveItemColumns.ToList();SetFinalColumnsToSelect(query, columns);var commandTextBuilder = new StringBuilder("select ", 1024).AppendJoin(',', columns)@@ -2820,7 +2857,7 @@ namespace Emby.Server.Implementations.Dataquery.Limit = query.Limit.Value + 4;}- var columns = _retriveItemColumns.ToList();+ var columns = _retrieveItemColumns.ToList();SetFinalColumnsToSelect(query, columns);var commandTextBuilder = new StringBuilder("select ", 512).AppendJoin(',', columns)@@ -3569,23 +3606,37 @@ namespace Emby.Server.Implementations.Datavar excludeTypes = query.ExcludeItemTypes;if (excludeTypes.Length == 1){- whereClauses.Add("type<>@type");- statement?.TryBind("@type", excludeTypes[0].ToString());+ if (_baseItemKindNames.TryGetValue(excludeTypes[0], out var excludeTypeName))+ {+ whereClauses.Add("type<>@type");+ statement?.TryBind("@type", excludeTypeName);+ }}else if (excludeTypes.Length > 1){- var inClause = string.Join(',', excludeTypes.Select(i => "'" + i + "'"));+ var inClause = string.Join(+ ',',+ excludeTypes+ .Select(i => _baseItemKindNames.TryGetValue(i, out var baseItemKindName) ? "'" + baseItemKindName + "'" : null)+ .Where(i => !string.IsNullOrEmpty(i)));whereClauses.Add($"type not in ({inClause})");}}else if (includeTypes.Length == 1){- whereClauses.Add("type=@type");- statement?.TryBind("@type", includeTypes[0].ToString());+ if (_baseItemKindNames.TryGetValue(includeTypes[0], out var includeTypeName))+ {+ whereClauses.Add("type=@type");+ statement?.TryBind("@type", includeTypeName);+ }}else if (includeTypes.Length > 1){- var inClause = string.Join(',', includeTypes.Select(i => "'" + i + "'"));+ var inClause = string.Join(+ ',',+ includeTypes+ .Select(i => _baseItemKindNames.TryGetValue(i, out var baseItemKindName) ? "'" + baseItemKindName + "'" : null)+ .Where(i => !string.IsNullOrEmpty(i)));whereClauses.Add($"type in ({inClause})");}@@ -5334,7 +5385,7 @@ AND Type = @InternalPersonType)");stringBuilder.Clear();}- List<string> columns = _retriveItemColumns.ToList();+ List<string> columns = _retrieveItemColumns.ToList();// Unfortunately we need to add it to columns to ensure the order of the columns in the selectif (!string.IsNullOrEmpty(itemCountColumns)){