From 185476c08ac942b942623362a8f9e917c2d8c3a0 Mon Sep 17 00:00:00 2001
From: Matt Montgomery <33811686+ConfusedPolarBear@users.noreply.github.com>
Date: Fri, 27 Nov 2020 16:12:16 -0600
Subject: [PATCH] Add support for query negation
---
.../Data/SqliteItemRepository.cs | 27 ++++++++++++++-----
1 file changed, 21 insertions(+), 6 deletions(-)
diff --git a/Emby.Server.Implementations/Data/SqliteItemRepository.cs b/Emby.Server.Implementations/Data/SqliteItemRepository.cs
index 95ffa48f5..50c7a07d4 100644
--- a/Emby.Server.Implementations/Data/SqliteItemRepository.cs
+++ b/Emby.Server.Implementations/Data/SqliteItemRepository.cs
@@ -4517,19 +4517,19 @@ namespace Emby.Server.Implementations.Data
}
}
- if (query.HasImdbId.HasValue && query.HasImdbId.Value)
+ if (query.HasImdbId.HasValue)
{
- whereClauses.Add("ProviderIds like '%imdb=%'");
+ whereClauses.Add(GetProviderIdClause(query.HasImdbId.Value, "imdb"));
}
- if (query.HasTmdbId.HasValue && query.HasTmdbId.Value)
+ if (query.HasTmdbId.HasValue)
{
- whereClauses.Add("ProviderIds like '%tmdb=%'");
+ whereClauses.Add(GetProviderIdClause(query.HasTmdbId.Value, "tmdb"));
}
- if (query.HasTvdbId.HasValue && query.HasTvdbId.Value)
+ if (query.HasTvdbId.HasValue)
{
- whereClauses.Add("ProviderIds like '%tvdb=%'");
+ whereClauses.Add(GetProviderIdClause(query.HasTvdbId.Value, "tvdb"));
}
var includedItemByNameTypes = GetItemByNameTypesInQuery(query).SelectMany(MapIncludeItemTypes).ToList();
@@ -4769,6 +4769,21 @@ namespace Emby.Server.Implementations.Data
return whereClauses;
}
+ ///
+ /// Formats a where clause for the specified provider.
+ ///
+ /// Whether or not to include items with this provider's ids.
+ /// Provider name.
+ /// Formatted SQL clause.
+ private string GetProviderIdClause(bool includeResults, string provider)
+ {
+ return string.Format(
+ CultureInfo.InvariantCulture,
+ "ProviderIds {0} like '%{1}=%'",
+ includeResults ? string.Empty : "not",
+ provider);
+ }
+
private List GetItemByNameTypesInQuery(InternalItemsQuery query)
{
var list = new List();