From 554c967dd6a0e7e75e737912e869b7269cd72081 Mon Sep 17 00:00:00 2001 From: Neil Burrows Date: Fri, 13 Dec 2019 10:29:38 +0000 Subject: [PATCH 1/4] Add Excluded Tags using SQLite parameters --- .../Data/SqliteItemRepository.cs | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/Emby.Server.Implementations/Data/SqliteItemRepository.cs b/Emby.Server.Implementations/Data/SqliteItemRepository.cs index 69cfcb67b..3f96b43b3 100644 --- a/Emby.Server.Implementations/Data/SqliteItemRepository.cs +++ b/Emby.Server.Implementations/Data/SqliteItemRepository.cs @@ -4593,10 +4593,26 @@ namespace Emby.Server.Implementations.Data if (query.ExcludeInheritedTags.Length > 0) { - var tagValues = query.ExcludeInheritedTags.Select(i => "'" + GetCleanValue(i) + "'"); - var tagValuesList = string.Join(",", tagValues); + var paramName = "@ExcludeInheritedTags"; - whereClauses.Add("((select CleanValue from itemvalues where ItemId=Guid and Type=6 and cleanvalue in (" + tagValuesList + ")) is null)"); + if (statement == null) + { + List tagParamList = new List(); + + for (int index = 0; index < query.ExcludeInheritedTags.Length; index++) + { + tagParamList.Add(paramName + index); + } + + whereClauses.Add("((select CleanValue from itemvalues where ItemId=Guid and Type=6 and cleanvalue in (" + string.Join(",", tagParamList) + ")) is null)"); + } + else + { + for (int index = 0; index < query.ExcludeInheritedTags.Length; index++) + { + statement.TryBind(paramName + index, GetCleanValue(query.ExcludeInheritedTags[0])); + } + } } if (query.SeriesStatuses.Length > 0) From 12bb4a92eb69a0dfe06add8f4aebf5da749c6126 Mon Sep 17 00:00:00 2001 From: Neil Burrows Date: Fri, 13 Dec 2019 11:08:19 +0000 Subject: [PATCH 2/4] Tidying up code --- .../Data/SqliteItemRepository.cs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/Emby.Server.Implementations/Data/SqliteItemRepository.cs b/Emby.Server.Implementations/Data/SqliteItemRepository.cs index 3f96b43b3..2a74a826b 100644 --- a/Emby.Server.Implementations/Data/SqliteItemRepository.cs +++ b/Emby.Server.Implementations/Data/SqliteItemRepository.cs @@ -4594,17 +4594,10 @@ namespace Emby.Server.Implementations.Data if (query.ExcludeInheritedTags.Length > 0) { var paramName = "@ExcludeInheritedTags"; - if (statement == null) { - List tagParamList = new List(); - - for (int index = 0; index < query.ExcludeInheritedTags.Length; index++) - { - tagParamList.Add(paramName + index); - } - - whereClauses.Add("((select CleanValue from itemvalues where ItemId=Guid and Type=6 and cleanvalue in (" + string.Join(",", tagParamList) + ")) is null)"); + int index = 0; + whereClauses.Add("((select CleanValue from itemvalues where ItemId=Guid and Type=6 and cleanvalue in (" + string.Join(",", query.ExcludeInheritedTags.Select(t => paramName + index++)) + ")) is null)"); } else { From 55317b5c749a36411f6582f8cf6a9477f1a2c880 Mon Sep 17 00:00:00 2001 From: Neil Burrows Date: Fri, 13 Dec 2019 13:45:04 +0000 Subject: [PATCH 3/4] Fixing index error & split out code for readability --- .../Data/SqliteItemRepository.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Emby.Server.Implementations/Data/SqliteItemRepository.cs b/Emby.Server.Implementations/Data/SqliteItemRepository.cs index 2a74a826b..b664738cb 100644 --- a/Emby.Server.Implementations/Data/SqliteItemRepository.cs +++ b/Emby.Server.Implementations/Data/SqliteItemRepository.cs @@ -4596,14 +4596,19 @@ namespace Emby.Server.Implementations.Data var paramName = "@ExcludeInheritedTags"; if (statement == null) { - int index = 0; - whereClauses.Add("((select CleanValue from itemvalues where ItemId=Guid and Type=6 and cleanvalue in (" + string.Join(",", query.ExcludeInheritedTags.Select(t => paramName + index++)) + ")) is null)"); + List paramList = new List(); + for (int index = 0; index < query.ExcludeInheritedTags.Length; index++) + { + paramList.Add(paramName + index); + } + + whereClauses.Add("((select CleanValue from itemvalues where ItemId=Guid and Type=6 and cleanvalue in (" + string.Join(",", paramList) + ")) is null)"); } else { for (int index = 0; index < query.ExcludeInheritedTags.Length; index++) { - statement.TryBind(paramName + index, GetCleanValue(query.ExcludeInheritedTags[0])); + statement.TryBind(paramName + index, GetCleanValue(query.ExcludeInheritedTags[index])); } } } From d9c0721e3dee52ec8a101cf3d35ca18ef5bd6cf3 Mon Sep 17 00:00:00 2001 From: Neil Burrows Date: Sat, 14 Dec 2019 17:48:30 +0000 Subject: [PATCH 4/4] Reformatting code --- .../Data/SqliteItemRepository.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Emby.Server.Implementations/Data/SqliteItemRepository.cs b/Emby.Server.Implementations/Data/SqliteItemRepository.cs index b664738cb..ef1fe07c1 100644 --- a/Emby.Server.Implementations/Data/SqliteItemRepository.cs +++ b/Emby.Server.Implementations/Data/SqliteItemRepository.cs @@ -4596,13 +4596,9 @@ namespace Emby.Server.Implementations.Data var paramName = "@ExcludeInheritedTags"; if (statement == null) { - List paramList = new List(); - for (int index = 0; index < query.ExcludeInheritedTags.Length; index++) - { - paramList.Add(paramName + index); - } - - whereClauses.Add("((select CleanValue from itemvalues where ItemId=Guid and Type=6 and cleanvalue in (" + string.Join(",", paramList) + ")) is null)"); + int index = 0; + string excludedTags = string.Join(",", query.ExcludeInheritedTags.Select(t => paramName + index++)); + whereClauses.Add("((select CleanValue from itemvalues where ItemId=Guid and Type=6 and cleanvalue in (" + excludedTags + ")) is null)"); } else {