@ -19,7 +19,6 @@ using System.Runtime.Serialization;
using System.Threading ;
using System.Threading.Tasks ;
using MediaBrowser.Controller.Channels ;
using MediaBrowser.Model.LiveTv ;
namespace MediaBrowser.Server.Implementations.Persistence
{
@ -77,12 +76,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
private IDbCommand _deleteStreamsCommand ;
private IDbCommand _saveStreamCommand ;
private IDbCommand _deleteAncestorsCommand ;
private IDbCommand _saveAncestorCommand ;
private IDbCommand _updateInheritedRatingCommand ;
private const int LatestSchemaVersion = 40 ;
private const int LatestSchemaVersion = 13 ;
/// <summary>
/// Initializes a new instance of the <see cref="SqliteItemRepository"/> class.
@ -127,24 +121,17 @@ namespace MediaBrowser.Server.Implementations.Persistence
_connection = await SqliteExtensions . ConnectToDb ( dbFile , _logger ) . ConfigureAwait ( false ) ;
var createMediaStreamsTableCommand
= "create table if not exists mediastreams (ItemId GUID, StreamIndex INT, StreamType TEXT, Codec TEXT, Language TEXT, ChannelLayout TEXT, Profile TEXT, AspectRatio TEXT, Path TEXT, IsInterlaced BIT, BitRate INT NULL, Channels INT NULL, SampleRate INT NULL, IsDefault BIT, IsForced BIT, IsExternal BIT, Height INT NULL, Width INT NULL, AverageFrameRate FLOAT NULL, RealFrameRate FLOAT NULL, Level FLOAT NULL, PixelFormat TEXT, BitDepth INT NULL, IsAnamorphic BIT NULL, RefFrames INT NULL, IsCabac BIT NULL, CodecTag TEXT NULL, PRIMARY KEY (ItemId, StreamIndex))";
= "create table if not exists mediastreams (ItemId GUID, StreamIndex INT, StreamType TEXT, Codec TEXT, Language TEXT, ChannelLayout TEXT, Profile TEXT, AspectRatio TEXT, Path TEXT, IsInterlaced BIT, BitRate INT NULL, Channels INT NULL, SampleRate INT NULL, IsDefault BIT, IsForced BIT, IsExternal BIT, Height INT NULL, Width INT NULL, AverageFrameRate FLOAT NULL, RealFrameRate FLOAT NULL, Level FLOAT NULL, PixelFormat TEXT, BitDepth INT NULL, IsAnamorphic BIT NULL, RefFrames INT NULL, IsCabac BIT NULL, KeyFrames TEXT NULL, PRIMARY KEY (ItemId, StreamIndex))";
string [ ] queries = {
"create table if not exists TypedBaseItems (guid GUID primary key, type TEXT, data BLOB , ParentId GUID )",
"create table if not exists TypedBaseItems (guid GUID primary key, type TEXT, data BLOB )",
"create index if not exists idx_TypedBaseItems on TypedBaseItems(guid)" ,
"create index if not exists idx_ParentIdTypedBaseItems on TypedBaseItems(ParentId)" ,
"create table if not exists AncestorIds (ItemId GUID, AncestorId GUID, AncestorIdText TEXT, PRIMARY KEY (ItemId, AncestorId))" ,
"create index if not exists idx_AncestorIds1 on AncestorIds(AncestorId)" ,
"create index if not exists idx_AncestorIds2 on AncestorIds(AncestorIdText)" ,
"create table if not exists ChildrenIds (ParentId GUID, ItemId GUID, PRIMARY KEY (ParentId, ItemId))" ,
"create index if not exists idx_ChildrenIds on ChildrenIds(ParentId,ItemId)" ,
"create table if not exists People (ItemId GUID, Name TEXT NOT NULL, Role TEXT, PersonType TEXT, SortOrder int, ListOrder int)" ,
"create index if not exists idxPeopleItemId on People(ItemId)" ,
"create index if not exists idxPeopleName on People(Name)" ,
"create table if not exists " + ChaptersTableName + " (ItemId GUID, ChapterIndex INT, StartPositionTicks BIGINT, Name TEXT, ImagePath TEXT, PRIMARY KEY (ItemId, ChapterIndex))" ,
"create index if not exists idx_" + ChaptersTableName + " on " + ChaptersTableName + "(ItemId, ChapterIndex)" ,
@ -160,8 +147,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
_connection . RunQueries ( queries , _logger ) ;
_connection . AddColumn ( _logger , "AncestorIds" , "AncestorIdText" , "Text" ) ;
_connection . AddColumn ( _logger , "TypedBaseItems" , "Path" , "Text" ) ;
_connection . AddColumn ( _logger , "TypedBaseItems" , "StartDate" , "DATETIME" ) ;
_connection . AddColumn ( _logger , "TypedBaseItems" , "EndDate" , "DATETIME" ) ;
@ -213,18 +198,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
_connection . AddColumn ( _logger , "TypedBaseItems" , "ExternalEtag" , "Text" ) ;
_connection . AddColumn ( _logger , "TypedBaseItems" , "DateLastRefreshed" , "DATETIME" ) ;
_connection . AddColumn ( _logger , "TypedBaseItems" , "DateLastSaved" , "DATETIME" ) ;
_connection . AddColumn ( _logger , "TypedBaseItems" , "IsInMixedFolder" , "BIT" ) ;
_connection . AddColumn ( _logger , "TypedBaseItems" , "LockedFields" , "Text" ) ;
_connection . AddColumn ( _logger , "TypedBaseItems" , "Studios" , "Text" ) ;
_connection . AddColumn ( _logger , "TypedBaseItems" , "Audio" , "Text" ) ;
_connection . AddColumn ( _logger , "TypedBaseItems" , "ExternalServiceId" , "Text" ) ;
_connection . AddColumn ( _logger , "TypedBaseItems" , "Tags" , "Text" ) ;
_connection . AddColumn ( _logger , "TypedBaseItems" , "IsFolder" , "BIT" ) ;
_connection . AddColumn ( _logger , "TypedBaseItems" , "InheritedParentalRatingValue" , "INT" ) ;
_connection . AddColumn ( _logger , "TypedBaseItems" , "UnratedType" , "Text" ) ;
_connection . AddColumn ( _logger , "TypedBaseItems" , "TopParentId" , "Text" ) ;
PrepareStatements ( ) ;
new MediaStreamColumns ( _connection , _logger ) . AddColumns ( ) ;
@ -334,27 +307,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
"PreferredMetadataCountryCode" ,
"IsHD" ,
"ExternalEtag" ,
"DateLastRefreshed" ,
"Name" ,
"Path" ,
"PremiereDate" ,
"Overview" ,
"ParentIndexNumber" ,
"ProductionYear" ,
"OfficialRating" ,
"OfficialRatingDescription" ,
"HomePageUrl" ,
"DisplayMediaType" ,
"ForcedSortName" ,
"RunTimeTicks" ,
"VoteCount" ,
"DateCreated" ,
"DateModified" ,
"guid" ,
"Genres" ,
"ParentId" ,
"Audio" ,
"ExternalServiceId"
"DateLastRefreshed"
} ;
private readonly string [ ] _mediaStreamSaveColumns =
@ -385,7 +338,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
"IsAnamorphic" ,
"RefFrames" ,
"IsCabac" ,
" CodecTag "
" KeyFrames "
} ;
/// <summary>
@ -425,7 +378,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
"ParentId" ,
"Genres" ,
"ParentalRatingValue" ,
"InheritedParentalRatingValue" ,
"SchemaVersion" ,
"SortName" ,
"RunTimeTicks" ,
@ -442,17 +394,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
"PreferredMetadataCountryCode" ,
"IsHD" ,
"ExternalEtag" ,
"DateLastRefreshed" ,
"DateLastSaved" ,
"IsInMixedFolder" ,
"LockedFields" ,
"Studios" ,
"Audio" ,
"ExternalServiceId" ,
"Tags" ,
"IsFolder" ,
"UnratedType" ,
"TopParentId"
"DateLastRefreshed"
} ;
_saveItemCommand = _connection . CreateCommand ( ) ;
_saveItemCommand . CommandText = "replace into TypedBaseItems (" + string . Join ( "," , saveColumns . ToArray ( ) ) + ") values (" ;
@ -496,17 +438,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
_savePersonCommand . Parameters . Add ( _savePersonCommand , "@SortOrder" ) ;
_savePersonCommand . Parameters . Add ( _savePersonCommand , "@ListOrder" ) ;
// Ancestors
_deleteAncestorsCommand = _connection . CreateCommand ( ) ;
_deleteAncestorsCommand . CommandText = "delete from AncestorIds where ItemId=@Id" ;
_deleteAncestorsCommand . Parameters . Add ( _deleteAncestorsCommand , "@Id" ) ;
_saveAncestorCommand = _connection . CreateCommand ( ) ;
_saveAncestorCommand . CommandText = "insert into AncestorIds (ItemId, AncestorId, AncestorIdText) values (@ItemId, @AncestorId, @AncestorIdText)" ;
_saveAncestorCommand . Parameters . Add ( _saveAncestorCommand , "@ItemId" ) ;
_saveAncestorCommand . Parameters . Add ( _saveAncestorCommand , "@AncestorId" ) ;
_saveAncestorCommand . Parameters . Add ( _saveAncestorCommand , "@AncestorIdText" ) ;
// Chapters
_deleteChaptersCommand = _connection . CreateCommand ( ) ;
_deleteChaptersCommand . CommandText = "delete from " + ChaptersTableName + " where ItemId=@ItemId" ;
@ -536,11 +467,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
{
_saveStreamCommand . Parameters . Add ( _saveStreamCommand , "@" + col ) ;
}
_updateInheritedRatingCommand = _connection . CreateCommand ( ) ;
_updateInheritedRatingCommand . CommandText = "Update TypedBaseItems set InheritedParentalRatingValue=@InheritedParentalRatingValue where Guid=@Guid" ;
_updateInheritedRatingCommand . Parameters . Add ( _updateInheritedRatingCommand , "@InheritedParentalRatingValue" ) ;
_updateInheritedRatingCommand . Parameters . Add ( _updateInheritedRatingCommand , "@Guid" ) ;
}
/// <summary>
@ -666,8 +592,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
}
_saveItemCommand . GetParameter ( index + + ) . Value = string . Join ( "|" , item . Genres . ToArray ( ) ) ;
_saveItemCommand . GetParameter ( index + + ) . Value = item . GetParentalRatingValue ( ) ? ? 0 ;
_saveItemCommand . GetParameter ( index + + ) . Value = item . GetInheritedParentalRatingValue ( ) ? ? 0 ;
_saveItemCommand . GetParameter ( index + + ) . Value = item . GetParentalRatingValue ( ) ;
_saveItemCommand . GetParameter ( index + + ) . Value = LatestSchemaVersion ;
_saveItemCommand . GetParameter ( index + + ) . Value = item . SortName ;
@ -698,53 +623,9 @@ namespace MediaBrowser.Server.Implementations.Persistence
_saveItemCommand . GetParameter ( index + + ) . Value = item . DateLastRefreshed ;
}
_saveItemCommand . GetParameter ( index + + ) . Value = item . DateLastSaved ;
_saveItemCommand . GetParameter ( index + + ) . Value = item . IsInMixedFolder ;
_saveItemCommand . GetParameter ( index + + ) . Value = string . Join ( "|" , item . LockedFields . Select ( i = > i . ToString ( ) ) . ToArray ( ) ) ;
_saveItemCommand . GetParameter ( index + + ) . Value = string . Join ( "|" , item . Studios . ToArray ( ) ) ;
if ( item . Audio . HasValue )
{
_saveItemCommand . GetParameter ( index + + ) . Value = item . Audio . Value . ToString ( ) ;
}
else
{
_saveItemCommand . GetParameter ( index + + ) . Value = null ;
}
var tvItem = item as ILiveTvItem ;
if ( tvItem ! = null )
{
_saveItemCommand . GetParameter ( index + + ) . Value = tvItem . ServiceName ;
}
else
{
_saveItemCommand . GetParameter ( index + + ) . Value = null ;
}
_saveItemCommand . GetParameter ( index + + ) . Value = string . Join ( "|" , item . Tags . ToArray ( ) ) ;
_saveItemCommand . GetParameter ( index + + ) . Value = item . IsFolder ;
_saveItemCommand . GetParameter ( index + + ) . Value = item . GetBlockUnratedType ( ) . ToString ( ) ;
var topParent = item . GetTopParent ( ) ;
if ( topParent ! = null )
{
_saveItemCommand . GetParameter ( index + + ) . Value = topParent . Id . ToString ( "N" ) ;
}
else
{
_saveItemCommand . GetParameter ( index + + ) . Value = null ;
}
_saveItemCommand . Transaction = transaction ;
_saveItemCommand . ExecuteNonQuery ( ) ;
if ( item . SupportsAncestors )
{
UpdateAncestors ( item . Id , item . GetAncestorIds ( ) . Distinct ( ) . ToList ( ) , transaction ) ;
}
}
transaction . Commit ( ) ;
@ -825,32 +706,22 @@ namespace MediaBrowser.Server.Implementations.Persistence
return null ;
}
BaseItem item = null ;
BaseItem item ;
using ( var stream = reader . GetMemoryStream ( 1 ) )
{
try
{
item = _jsonSerializer . DeserializeFromStream ( stream , type ) as BaseItem ;
}
catch ( SerializationException ex )
{
_logger . ErrorException ( "Error deserializing item" , ex ) ;
}
if ( item = = null )
{
try
{
item = Activator . CreateInstance ( type ) as BaseItem ;
}
catch
if ( item = = null )
{
return null ;
}
}
if ( item = = null )
catch ( SerializationException ex )
{
_logger . ErrorException ( "Error deserializing item" , ex ) ;
return null ;
}
}
@ -973,107 +844,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
item . DateLastRefreshed = reader . GetDateTime ( 23 ) . ToUniversalTime ( ) ;
}
if ( ! reader . IsDBNull ( 24 ) )
{
item . Name = reader . GetString ( 24 ) ;
}
if ( ! reader . IsDBNull ( 25 ) )
{
item . Path = reader . GetString ( 25 ) ;
}
if ( ! reader . IsDBNull ( 26 ) )
{
item . PremiereDate = reader . GetDateTime ( 26 ) . ToUniversalTime ( ) ;
}
if ( ! reader . IsDBNull ( 27 ) )
{
item . Overview = reader . GetString ( 27 ) ;
}
if ( ! reader . IsDBNull ( 28 ) )
{
item . ParentIndexNumber = reader . GetInt32 ( 28 ) ;
}
if ( ! reader . IsDBNull ( 29 ) )
{
item . ProductionYear = reader . GetInt32 ( 29 ) ;
}
if ( ! reader . IsDBNull ( 30 ) )
{
item . OfficialRating = reader . GetString ( 30 ) ;
}
if ( ! reader . IsDBNull ( 31 ) )
{
item . OfficialRating = reader . GetString ( 31 ) ;
}
if ( ! reader . IsDBNull ( 32 ) )
{
item . HomePageUrl = reader . GetString ( 32 ) ;
}
if ( ! reader . IsDBNull ( 33 ) )
{
item . DisplayMediaType = reader . GetString ( 33 ) ;
}
if ( ! reader . IsDBNull ( 34 ) )
{
item . ForcedSortName = reader . GetString ( 34 ) ;
}
if ( ! reader . IsDBNull ( 35 ) )
{
item . RunTimeTicks = reader . GetInt64 ( 35 ) ;
}
if ( ! reader . IsDBNull ( 36 ) )
{
item . VoteCount = reader . GetInt32 ( 36 ) ;
}
if ( ! reader . IsDBNull ( 37 ) )
{
item . DateCreated = reader . GetDateTime ( 37 ) . ToUniversalTime ( ) ;
}
if ( ! reader . IsDBNull ( 38 ) )
{
item . DateModified = reader . GetDateTime ( 38 ) . ToUniversalTime ( ) ;
}
item . Id = reader . GetGuid ( 39 ) ;
if ( ! reader . IsDBNull ( 40 ) )
{
item . Genres = reader . GetString ( 40 ) . Split ( '|' ) . Where ( i = > ! string . IsNullOrWhiteSpace ( i ) ) . ToList ( ) ;
}
if ( ! reader . IsDBNull ( 41 ) )
{
item . ParentId = reader . GetGuid ( 41 ) ;
}
if ( ! reader . IsDBNull ( 42 ) )
{
item . Audio = ( ProgramAudio ) Enum . Parse ( typeof ( ProgramAudio ) , reader . GetString ( 42 ) , true ) ;
}
if ( ! reader . IsDBNull ( 43 ) )
{
var tvItem = item as ILiveTvItem ;
if ( tvItem ! = null )
{
tvItem . ServiceName = reader . GetString ( 43 ) ;
}
}
return item ;
}
@ -1398,8 +1168,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
cmd . Parameters . Add ( cmd , "@ParentId" , DbType . Guid ) . Value = parentId ;
//_logger.Debug(cmd.CommandText);
using ( var reader = cmd . ExecuteReader ( CommandBehavior . SequentialAccess | CommandBehavior . SingleResult ) )
{
while ( reader . Read ( ) )
@ -1445,50 +1213,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
}
}
public IEnumerable < BaseItem > GetItemList ( InternalItemsQuery query )
{
if ( query = = null )
{
throw new ArgumentNullException ( "query" ) ;
}
CheckDisposed ( ) ;
using ( var cmd = _connection . CreateCommand ( ) )
{
cmd . CommandText = "select " + string . Join ( "," , _retriveItemColumns ) + " from TypedBaseItems" ;
var whereClauses = GetWhereClauses ( query , cmd , true ) ;
var whereText = whereClauses . Count = = 0 ?
string . Empty :
" where " + string . Join ( " AND " , whereClauses . ToArray ( ) ) ;
cmd . CommandText + = whereText ;
cmd . CommandText + = GetOrderByText ( query ) ;
if ( query . Limit . HasValue )
{
cmd . CommandText + = " LIMIT " + query . Limit . Value . ToString ( CultureInfo . InvariantCulture ) ;
}
//_logger.Debug(cmd.CommandText);
using ( var reader = cmd . ExecuteReader ( CommandBehavior . SequentialAccess | CommandBehavior . SingleResult ) )
{
while ( reader . Read ( ) )
{
var item = GetItem ( reader ) ;
if ( item ! = null )
{
yield return item ;
}
}
}
}
}
public QueryResult < BaseItem > GetItems ( InternalItemsQuery query )
{
if ( query = = null )
@ -1569,12 +1293,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
private string MapOrderByField ( string name )
{
if ( string . Equals ( name , "airtime" , StringComparison . OrdinalIgnoreCase ) )
{
// TODO
return "SortName" ;
}
return name ;
}
@ -1610,7 +1328,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
_logger . Debug ( cmd . CommandText ) ;
using ( var reader = cmd . ExecuteReader ( CommandBehavior . SequentialAccess | CommandBehavior . SingleResult ) )
using ( var reader = cmd . ExecuteReader ( CommandBehavior . SequentialAccess ) )
{
while ( reader . Read ( ) )
{
@ -1794,11 +1512,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
whereClauses . Add ( "IsSports=@IsSports" ) ;
cmd . Parameters . Add ( cmd , "@IsSports" , DbType . Boolean ) . Value = query . IsSports ;
}
if ( query . IsFolder . HasValue )
{
whereClauses . Add ( "IsFolder=@IsFolder" ) ;
cmd . Parameters . Add ( cmd , "@IsFolder" , DbType . Boolean ) . Value = query . IsFolder ;
}
var includeTypes = query . IncludeItemTypes . SelectMany ( MapIncludeItemTypes ) . ToArray ( ) ;
if ( includeTypes . Length = = 1 )
@ -1859,12 +1572,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
cmd . Parameters . Add ( cmd , "@MinStartDate" , DbType . Date ) . Value = query . MinStartDate . Value ;
}
if ( query . MinPremiereDate . HasValue )
{
whereClauses . Add ( "PremiereDate>=@MinPremiereDate" ) ;
cmd . Parameters . Add ( cmd , "@MinPremiereDate" , DbType . Date ) . Value = query . MinPremiereDate . Value ;
}
if ( query . MaxStartDate . HasValue )
{
whereClauses . Add ( "StartDate<=@MaxStartDate" ) ;
@ -1916,7 +1623,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
if ( query . MaxParentalRating . HasValue )
{
whereClauses . Add ( " InheritedParentalRatingValue<=@MaxParentalRating ") ;
whereClauses . Add ( " (ParentalRatingValue is NULL OR ParentalRatingValue<=@MaxParentalRating) ") ;
cmd . Parameters . Add ( cmd , "@MaxParentalRating" , DbType . Int32 ) . Value = query . MaxParentalRating . Value ;
}
@ -1924,11 +1631,11 @@ namespace MediaBrowser.Server.Implementations.Persistence
{
if ( query . HasParentalRating . Value )
{
whereClauses . Add ( " InheritedParentalRatingValue > 0 ") ;
whereClauses . Add ( " ParentalRatingValue NOT NULL ") ;
}
else
{
whereClauses . Add ( " InheritedParentalRatingValue = 0 ") ;
whereClauses . Add ( " ParentalRatingValue IS NULL ") ;
}
}
@ -1939,60 +1646,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
whereClauses . Add ( "ParentId NOT NULL AND ParentId NOT IN (select guid from TypedBaseItems)" ) ;
}
}
if ( query . ExcludeLocationTypes . Length = = 1 )
{
whereClauses . Add ( "LocationType<>@LocationType" ) ;
cmd . Parameters . Add ( cmd , "@LocationType" , DbType . String ) . Value = query . ExcludeLocationTypes [ 0 ] . ToString ( ) ;
}
if ( query . ExcludeLocationTypes . Length > 1 )
{
var val = string . Join ( "," , query . ExcludeLocationTypes . Select ( i = > "'" + i + "'" ) . ToArray ( ) ) ;
whereClauses . Add ( "LocationType not in (" + val + ")" ) ;
}
if ( query . TopParentIds . Length = = 1 )
{
whereClauses . Add ( "(TopParentId=@TopParentId)" ) ;
cmd . Parameters . Add ( cmd , "@TopParentId" , DbType . String ) . Value = query . TopParentIds [ 0 ] ;
}
if ( query . TopParentIds . Length > 1 )
{
var val = string . Join ( "," , query . TopParentIds . Select ( i = > "'" + i + "'" ) . ToArray ( ) ) ;
whereClauses . Add ( "(TopParentId in (" + val + "))" ) ;
}
if ( query . AncestorIds . Length = = 1 )
{
whereClauses . Add ( "Guid in (select itemId from AncestorIds where AncestorId=@AncestorId)" ) ;
cmd . Parameters . Add ( cmd , "@AncestorId" , DbType . Guid ) . Value = new Guid ( query . AncestorIds [ 0 ] ) ;
}
if ( query . AncestorIds . Length > 1 )
{
var inClause = string . Join ( "," , query . AncestorIds . Select ( i = > "'" + new Guid ( i ) . ToString ( "N" ) + "'" ) . ToArray ( ) ) ;
whereClauses . Add ( string . Format ( "Guid in (select itemId from AncestorIds where AncestorIdText in ({0}))" , inClause ) ) ;
}
if ( query . BlockUnratedItems . Length = = 1 )
{
whereClauses . Add ( "(InheritedParentalRatingValue > 0 or UnratedType <> @UnratedType)" ) ;
cmd . Parameters . Add ( cmd , "@UnratedType" , DbType . String ) . Value = query . BlockUnratedItems [ 0 ] . ToString ( ) ;
}
if ( query . BlockUnratedItems . Length > 1 )
{
var inClause = string . Join ( "," , query . BlockUnratedItems . Select ( i = > "'" + i . ToString ( ) + "'" ) . ToArray ( ) ) ;
whereClauses . Add ( string . Format ( "(InheritedParentalRatingValue > 0 or UnratedType not in ({0}))" , inClause ) ) ;
}
//var excludeTagIndex = 0;
//foreach (var excludeTag in query.ExcludeTags)
//{
// whereClauses.Add("Tags not like @excludeTag" + excludeTagIndex);
// cmd.Parameters.Add(cmd, "@excludeTag" + excludeTagIndex, DbType.String).Value = "%" + excludeTag + "%";
// excludeTagIndex++;
//}
if ( addPaging )
{
if ( query . StartIndex . HasValue & & query . StartIndex . Value > 0 )
@ -2049,83 +1703,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
typeof ( AggregateFolder )
} ;
public async Task UpdateInheritedValues ( CancellationToken cancellationToken )
{
var newValues = new List < Tuple < Guid , int > > ( ) ;
using ( var cmd = _connection . CreateCommand ( ) )
{
cmd . CommandText = "select Guid,InheritedParentalRatingValue,(select Max(ParentalRatingValue, (select COALESCE(MAX(ParentalRatingValue),0) from TypedBaseItems where guid in (Select AncestorId from AncestorIds where ItemId=Outer.guid)))) as NewInheritedParentalRatingValue from typedbaseitems as Outer where InheritedParentalRatingValue <> NewInheritedParentalRatingValue" ;
using ( var reader = cmd . ExecuteReader ( CommandBehavior . SequentialAccess | CommandBehavior . SingleResult ) )
{
while ( reader . Read ( ) )
{
var id = reader . GetGuid ( 0 ) ;
var newValue = reader . GetInt32 ( 2 ) ;
newValues . Add ( new Tuple < Guid , int > ( id , newValue ) ) ;
}
}
}
if ( newValues . Count = = 0 )
{
return ;
}
await _writeLock . WaitAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
IDbTransaction transaction = null ;
try
{
transaction = _connection . BeginTransaction ( ) ;
foreach ( var item in newValues )
{
_updateInheritedRatingCommand . GetParameter ( 0 ) . Value = item . Item1 ;
_updateInheritedRatingCommand . GetParameter ( 1 ) . Value = item . Item2 ;
_updateInheritedRatingCommand . Transaction = transaction ;
_updateInheritedRatingCommand . ExecuteNonQuery ( ) ;
_updateInheritedRatingCommand . ExecuteNonQuery ( ) ;
}
transaction . Commit ( ) ;
}
catch ( OperationCanceledException )
{
if ( transaction ! = null )
{
transaction . Rollback ( ) ;
}
throw ;
}
catch ( Exception e )
{
_logger . ErrorException ( "Error running query:" , e ) ;
if ( transaction ! = null )
{
transaction . Rollback ( ) ;
}
throw ;
}
finally
{
if ( transaction ! = null )
{
transaction . Dispose ( ) ;
}
_writeLock . Release ( ) ;
}
}
private static Dictionary < string , string [ ] > GetTypeMapDictionary ( )
{
var dict = new Dictionary < string , string [ ] > ( ) ;
@ -2135,8 +1712,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
dict [ t . Name ] = new [ ] { t . FullName } ;
}
dict [ "ChannelItem" ] = new [ ] { typeof ( ChannelVideoItem ) . FullName , typeof ( ChannelAudioItem ) . FullName , typeof ( ChannelFolderItem ) . FullName } ;
dict [ "LiveTvItem" ] = new [ ] { typeof ( LiveTvAudioRecording ) . FullName , typeof ( LiveTvVideoRecording ) . FullName , typeof ( LiveTvChannel ) . FullName , typeof ( LiveTvProgram ) . FullName } ;
dict [ "Recording" ] = new [ ] { typeof ( LiveTvAudioRecording ) . FullName , typeof ( LiveTvVideoRecording ) . FullName } ;
dict [ "Program" ] = new [ ] { typeof ( LiveTvProgram ) . FullName } ;
dict [ "TvChannel" ] = new [ ] { typeof ( LiveTvChannel ) . FullName } ;
@ -2195,16 +1770,11 @@ namespace MediaBrowser.Server.Implementations.Persistence
_deleteStreamsCommand . Transaction = transaction ;
_deleteStreamsCommand . ExecuteNonQuery ( ) ;
// Delete ancestors
_deleteAncestorsCommand . GetParameter ( 0 ) . Value = id ;
_deleteAncestorsCommand . Transaction = transaction ;
_deleteAncestorsCommand . ExecuteNonQuery ( ) ;
// Delete the item
_deleteItemCommand . GetParameter ( 0 ) . Value = id ;
_deleteItemCommand . Transaction = transaction ;
_deleteItemCommand . ExecuteNonQuery ( ) ;
transaction . Commit ( ) ;
}
catch ( OperationCanceledException )
@ -2433,38 +2003,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
return whereClauses ;
}
private void UpdateAncestors ( Guid itemId , List < Guid > ancestorIds , IDbTransaction transaction )
{
if ( itemId = = Guid . Empty )
{
throw new ArgumentNullException ( "itemId" ) ;
}
if ( ancestorIds = = null )
{
throw new ArgumentNullException ( "ancestorIds" ) ;
}
CheckDisposed ( ) ;
// First delete
_deleteAncestorsCommand . GetParameter ( 0 ) . Value = itemId ;
_deleteAncestorsCommand . Transaction = transaction ;
_deleteAncestorsCommand . ExecuteNonQuery ( ) ;
foreach ( var ancestorId in ancestorIds )
{
_saveAncestorCommand . GetParameter ( 0 ) . Value = itemId ;
_saveAncestorCommand . GetParameter ( 1 ) . Value = ancestorId ;
_saveAncestorCommand . GetParameter ( 2 ) . Value = ancestorId . ToString ( "N" ) ;
_saveAncestorCommand . Transaction = transaction ;
_saveAncestorCommand . ExecuteNonQuery ( ) ;
}
}
public async Task UpdatePeople ( Guid itemId , List < PersonInfo > people )
{
if ( itemId = = Guid . Empty )
@ -2682,7 +2220,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
_saveStreamCommand . GetParameter ( index + + ) . Value = stream . RefFrames ;
_saveStreamCommand . GetParameter ( index + + ) . Value = stream . IsCabac ;
_saveStreamCommand . GetParameter ( index + + ) . Value = stream . CodecTag ;
_saveStreamCommand . GetParameter ( index + + ) . Value = null ;
_saveStreamCommand . Transaction = transaction ;
_saveStreamCommand . ExecuteNonQuery ( ) ;
@ -2838,7 +2376,10 @@ namespace MediaBrowser.Server.Implementations.Persistence
if ( ! reader . IsDBNull ( 26 ) )
{
item . CodecTag = reader . GetString ( 26 ) ;
var frames = reader . GetString ( 26 ) ;
if ( ! string . IsNullOrWhiteSpace ( frames ) )
{
}
}
return item ;