@ -95,7 +95,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
private IDbCommand _updateInheritedRatingCommand ;
private IDbCommand _updateInheritedTagsCommand ;
public const int LatestSchemaVersion = 10 8 ;
public const int LatestSchemaVersion = 10 9 ;
/// <summary>
/// Initializes a new instance of the <see cref="SqliteItemRepository"/> class.
@ -915,7 +915,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
}
else
{
_saveItemCommand . GetParameter ( index + + ) . Value = item. Name . RemoveDiacritics ( ) ;
_saveItemCommand . GetParameter ( index + + ) . Value = GetCleanValue( item . Name ) ;
}
_saveItemCommand . GetParameter ( index + + ) . Value = item . PresentationUniqueKey ;
@ -2763,13 +2763,13 @@ namespace MediaBrowser.Server.Implementations.Persistence
if ( ! string . IsNullOrWhiteSpace ( query . Name ) )
{
whereClauses . Add ( "CleanName=@Name" ) ;
cmd . Parameters . Add ( cmd , "@Name" , DbType . String ) . Value = query. Name . RemoveDiacritics ( ) ;
cmd . Parameters . Add ( cmd , "@Name" , DbType . String ) . Value = GetCleanValue( query . Name ) ;
}
if ( ! string . IsNullOrWhiteSpace ( query . NameContains ) )
{
whereClauses . Add ( "CleanName like @NameContains" ) ;
cmd . Parameters . Add ( cmd , "@NameContains" , DbType . String ) . Value = "%" + query. NameContains . RemoveDiacritics ( ) + "%" ;
cmd . Parameters . Add ( cmd , "@NameContains" , DbType . String ) . Value = "%" + GetCleanValue( query. NameContains ) + "%" ;
}
if ( ! string . IsNullOrWhiteSpace ( query . NameStartsWith ) )
{
@ -2877,7 +2877,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
foreach ( var artist in query . ArtistNames )
{
clauses . Add ( "@ArtistName" + index + " in (select CleanValue from itemvalues where ItemId=Guid and Type <= 1)" ) ;
cmd . Parameters . Add ( cmd , "@ArtistName" + index , DbType . String ) . Value = artist. RemoveDiacritics ( ) ;
cmd . Parameters . Add ( cmd , "@ArtistName" + index , DbType . String ) . Value = GetCleanValue( artist ) ;
index + + ;
}
var clause = "(" + string . Join ( " OR " , clauses . ToArray ( ) ) + ")" ;
@ -2894,7 +2894,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
if ( artistItem ! = null )
{
clauses . Add ( "@ExcludeArtistName" + index + " not in (select CleanValue from itemvalues where ItemId=Guid and Type <= 1)" ) ;
cmd . Parameters . Add ( cmd , "@ExcludeArtistName" + index , DbType . String ) . Value = artistItem. Name . RemoveDiacritics ( ) ;
cmd . Parameters . Add ( cmd , "@ExcludeArtistName" + index , DbType . String ) . Value = GetCleanValue( artistItem. Name ) ;
index + + ;
}
}
@ -2915,7 +2915,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
foreach ( var item in query . Genres )
{
clauses . Add ( "@Genre" + index + " in (select CleanValue from itemvalues where ItemId=Guid and Type=2)" ) ;
cmd . Parameters . Add ( cmd , "@Genre" + index , DbType . String ) . Value = item. RemoveDiacritics ( ) ;
cmd . Parameters . Add ( cmd , "@Genre" + index , DbType . String ) . Value = GetCleanValue( item ) ;
index + + ;
}
var clause = "(" + string . Join ( " OR " , clauses . ToArray ( ) ) + ")" ;
@ -2929,7 +2929,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
foreach ( var item in query . Tags )
{
clauses . Add ( "@Tag" + index + " in (select CleanValue from itemvalues where ItemId=Guid and Type=4)" ) ;
cmd . Parameters . Add ( cmd , "@Tag" + index , DbType . String ) . Value = item. RemoveDiacritics ( ) ;
cmd . Parameters . Add ( cmd , "@Tag" + index , DbType . String ) . Value = GetCleanValue( item ) ;
index + + ;
}
var clause = "(" + string . Join ( " OR " , clauses . ToArray ( ) ) + ")" ;
@ -2949,7 +2949,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
foreach ( var item in query . Studios )
{
clauses . Add ( "@Studio" + index + " in (select CleanValue from itemvalues where ItemId=Guid and Type=3)" ) ;
cmd . Parameters . Add ( cmd , "@Studio" + index , DbType . String ) . Value = item. RemoveDiacritics ( ) ;
cmd . Parameters . Add ( cmd , "@Studio" + index , DbType . String ) . Value = GetCleanValue( item ) ;
index + + ;
}
var clause = "(" + string . Join ( " OR " , clauses . ToArray ( ) ) + ")" ;
@ -2963,7 +2963,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
foreach ( var item in query . Keywords )
{
clauses . Add ( "@Keyword" + index + " in (select CleanValue from itemvalues where ItemId=Guid and Type=5)" ) ;
cmd . Parameters . Add ( cmd , "@Keyword" + index , DbType . String ) . Value = item. RemoveDiacritics ( ) ;
cmd . Parameters . Add ( cmd , "@Keyword" + index , DbType . String ) . Value = GetCleanValue( item ) ;
index + + ;
}
var clause = "(" + string . Join ( " OR " , clauses . ToArray ( ) ) + ")" ;
@ -3298,6 +3298,16 @@ namespace MediaBrowser.Server.Implementations.Persistence
return whereClauses ;
}
private string GetCleanValue ( string value )
{
if ( string . IsNullOrWhiteSpace ( value ) )
{
return value ;
}
return value . RemoveDiacritics ( ) . ToLower ( ) ;
}
private bool EnableGroupByPresentationUniqueKey ( InternalItemsQuery query )
{
if ( ! query . GroupByPresentationUniqueKey )
@ -3817,37 +3827,42 @@ namespace MediaBrowser.Server.Implementations.Persistence
}
}
public QueryResult < Tuple < BaseItem , ItemCounts > > GetAllArtists ( InternalItemsQuery query )
{
return GetItemValues ( query , new [ ] { 0 , 1 } , typeof ( MusicArtist ) . FullName ) ;
}
public QueryResult < Tuple < BaseItem , ItemCounts > > GetArtists ( InternalItemsQuery query )
{
return GetItemValues ( query , 0 , typeof ( MusicArtist ) . FullName ) ;
return GetItemValues ( query , new [ ] { 0 } , typeof ( MusicArtist ) . FullName ) ;
}
public QueryResult < Tuple < BaseItem , ItemCounts > > GetAlbumArtists ( InternalItemsQuery query )
{
return GetItemValues ( query , 1 , typeof ( MusicArtist ) . FullName ) ;
return GetItemValues ( query , new [ ] { 1 } , typeof ( MusicArtist ) . FullName ) ;
}
public QueryResult < Tuple < BaseItem , ItemCounts > > GetStudios ( InternalItemsQuery query )
{
return GetItemValues ( query , 3 , typeof ( Studio ) . FullName ) ;
return GetItemValues ( query , new [ ] { 3 } , typeof ( Studio ) . FullName ) ;
}
public QueryResult < Tuple < BaseItem , ItemCounts > > GetGenres ( InternalItemsQuery query )
{
return GetItemValues ( query , 2 , typeof ( Genre ) . FullName ) ;
return GetItemValues ( query , new [ ] { 2 } , typeof ( Genre ) . FullName ) ;
}
public QueryResult < Tuple < BaseItem , ItemCounts > > GetGameGenres ( InternalItemsQuery query )
{
return GetItemValues ( query , 2 , typeof ( GameGenre ) . FullName ) ;
return GetItemValues ( query , new [ ] { 2 } , typeof ( GameGenre ) . FullName ) ;
}
public QueryResult < Tuple < BaseItem , ItemCounts > > GetMusicGenres ( InternalItemsQuery query )
{
return GetItemValues ( query , 2 , typeof ( MusicGenre ) . FullName ) ;
return GetItemValues ( query , new [ ] { 2 } , typeof ( MusicGenre ) . FullName ) ;
}
private QueryResult < Tuple < BaseItem , ItemCounts > > GetItemValues ( InternalItemsQuery query , int itemValueType , string returnType )
private QueryResult < Tuple < BaseItem , ItemCounts > > GetItemValues ( InternalItemsQuery query , int [ ] itemValueType s , string returnType )
{
if ( query = = null )
{
@ -3863,6 +3878,10 @@ namespace MediaBrowser.Server.Implementations.Persistence
var now = DateTime . UtcNow ;
var typeClause = itemValueTypes . Length = = 1 ?
( "Type=" + itemValueTypes [ 0 ] . ToString ( CultureInfo . InvariantCulture ) ) :
( "Type in (" + string . Join ( "," , itemValueTypes . Select ( i = > i . ToString ( CultureInfo . InvariantCulture ) ) . ToArray ( ) ) + ")" ) ;
using ( var cmd = _connection . CreateCommand ( ) )
{
var itemCountColumns = new List < Tuple < string , string > > ( ) ;
@ -3887,7 +3906,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
} ;
var whereClauses = GetWhereClauses ( typeSubQuery , cmd , "itemTypes" ) ;
whereClauses . Add ( "guid in (select ItemId from ItemValues where ItemValues.CleanValue=A.CleanName AND Type=@ItemValueType )") ;
whereClauses . Add ( "guid in (select ItemId from ItemValues where ItemValues.CleanValue=A.CleanName AND " + typeClause + " )") ;
var typeWhereText = whereClauses . Count = = 0 ?
string . Empty :
@ -3929,12 +3948,12 @@ namespace MediaBrowser.Server.Implementations.Persistence
if ( typesToCount . Count = = 0 )
{
whereText + = " And CleanName In (Select CleanValue from ItemValues where Type=@ItemValueType AND ItemId in (select guid from TypedBaseItems" + innerWhereText + "))" ;
whereText + = " And CleanName In (Select CleanValue from ItemValues where " + typeClause + " AND ItemId in (select guid from TypedBaseItems" + innerWhereText + "))" ;
}
else
{
//whereText += " And itemTypes not null";
whereText + = " And CleanName In (Select CleanValue from ItemValues where Type=@ItemValueType AND ItemId in (select guid from TypedBaseItems" + innerWhereText + "))" ;
whereText + = " And CleanName In (Select CleanValue from ItemValues where " + typeClause + " AND ItemId in (select guid from TypedBaseItems" + innerWhereText + "))" ;
}
var outerQuery = new InternalItemsQuery ( query . User )
@ -3964,7 +3983,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
cmd . CommandText + = " group by PresentationUniqueKey" ;
cmd . Parameters . Add ( cmd , "@SelectType" , DbType . String ) . Value = returnType ;
cmd . Parameters . Add ( cmd , "@ItemValueType" , DbType . Int32 ) . Value = itemValueType ;
if ( EnableJoinUserData ( query ) )
{
@ -4016,7 +4034,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
? ( CommandBehavior . SequentialAccess | CommandBehavior . SingleResult )
: CommandBehavior . SequentialAccess ;
//Logger.Debug("GetItemValues: " + cmd.CommandText) ;
Logger . Debug ( "GetItemValues: " + cmd . CommandText ) ;
using ( var reader = cmd . ExecuteReader ( commandBehavior ) )
{
@ -4260,7 +4278,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
}
else
{
_saveItemValuesCommand . GetParameter ( 3 ) . Value = pair. Item2 . RemoveDiacritics ( ) ;
_saveItemValuesCommand . GetParameter ( 3 ) . Value = GetCleanValue( pair. Item2 ) ;
}
_saveItemValuesCommand . Transaction = transaction ;