@ -36,13 +36,9 @@ namespace Emby.Server.Implementations.Data
/// </summary>
/// </summary>
public class SqliteItemRepository : BaseSqliteRepository , IItemRepository
public class SqliteItemRepository : BaseSqliteRepository , IItemRepository
{
{
private readonly TypeMapper _typeMapper ;
private const string ChaptersTableName = "Chapters2" ;
/// <summary>
private readonly TypeMapper _typeMapper ;
/// Gets the name of the repository
/// </summary>
/// <value>The name.</value>
public string Name = > "SQLite" ;
/// <summary>
/// <summary>
/// Gets the json serializer.
/// Gets the json serializer.
@ -54,12 +50,9 @@ namespace Emby.Server.Implementations.Data
/// The _app paths
/// The _app paths
/// </summary>
/// </summary>
private readonly IServerConfigurationManager _config ;
private readonly IServerConfigurationManager _config ;
private IServerApplicationHost _appHost ;
private readonly IServerApplicationHost _appHost ;
private readonly ILocalizationManager _localization ;
private readonly ILocalizationManager _localization ;
public IImageProcessor ImageProcessor { get ; set ; }
/// <summary>
/// <summary>
/// Initializes a new instance of the <see cref="SqliteItemRepository"/> class.
/// Initializes a new instance of the <see cref="SqliteItemRepository"/> class.
/// </summary>
/// </summary>
@ -90,21 +83,24 @@ namespace Emby.Server.Implementations.Data
DbFilePath = Path . Combine ( _config . ApplicationPaths . DataPath , "library.db" ) ;
DbFilePath = Path . Combine ( _config . ApplicationPaths . DataPath , "library.db" ) ;
}
}
private const string ChaptersTableName = "Chapters2" ;
/// <inheritdoc />
public string Name = > "SQLite" ;
/// <inheritdoc />
protected override int? CacheSize = > 20000 ;
protected override int? CacheSize = > 20000 ;
protected override bool EnableTempStoreMemory = > true ;
/// <inheritdoc />
protected override TempStoreMode TempStore = > TempStoreMode . Memory ;
public IImageProcessor ImageProcessor { get ; set ; }
/// <summary>
/// <summary>
/// Opens the connection to the database
/// Opens the connection to the database
/// </summary>
/// </summary>
public void Initialize ( SqliteUserDataRepository userDataRepo , IUserManager userManager )
public void Initialize ( SqliteUserDataRepository userDataRepo , IUserManager userManager )
{
{
using ( var connection = Create Connection( ) )
using ( var connection = Get Connection( ) )
{
{
RunDefaultInitialization ( connection ) ;
const string createMediaStreamsTableCommand
const string 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, CodecTag TEXT NULL, Comment TEXT NULL, NalLengthSize TEXT NULL, IsAvc BIT NULL, Title TEXT NULL, TimeBase TEXT NULL, CodecTimeBase TEXT NULL, ColorPrimaries TEXT NULL, ColorSpace TEXT NULL, ColorTransfer 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, CodecTag TEXT NULL, Comment TEXT NULL, NalLengthSize TEXT NULL, IsAvc BIT NULL, Title TEXT NULL, TimeBase TEXT NULL, CodecTimeBase TEXT NULL, ColorPrimaries TEXT NULL, ColorSpace TEXT NULL, ColorTransfer TEXT NULL, PRIMARY KEY (ItemId, StreamIndex))" ;
@ -319,7 +315,7 @@ namespace Emby.Server.Implementations.Data
connection . RunQueries ( postQueries ) ;
connection . RunQueries ( postQueries ) ;
}
}
userDataRepo . Initialize ( WriteLock, _connection , userManager ) ;
userDataRepo . Initialize ( userManager, WriteLock , WriteConnection ) ;
}
}
private static readonly string [ ] _retriveItemColumns =
private static readonly string [ ] _retriveItemColumns =
@ -520,10 +516,11 @@ namespace Emby.Server.Implementations.Data
{
{
saveItemCommandCommandText + = "," ;
saveItemCommandCommandText + = "," ;
}
}
saveItemCommandCommandText + = "@" + saveColumns [ i ] ;
saveItemCommandCommandText + = "@" + saveColumns [ i ] ;
}
}
saveItemCommandCommandText + = ")" ;
return saveItemCommandCommandText ;
return saveItemCommandCommandText + ")" ;
}
}
/// <summary>
/// <summary>
@ -551,13 +548,11 @@ namespace Emby.Server.Implementations.Data
CheckDisposed ( ) ;
CheckDisposed ( ) ;
using ( WriteLock . Write ( ) )
using ( var connection = GetConnection ( ) )
{
using ( var connection = CreateConnection ( ) )
{
{
connection . RunInTransaction ( db = >
connection . RunInTransaction ( db = >
{
{
using ( var saveImagesStatement = PrepareStatement ( db , "Update TypedBaseItems set Images=@Images where guid=@Id" ) )
using ( var saveImagesStatement = base . PrepareStatement ( db , "Update TypedBaseItems set Images=@Images where guid=@Id" ) )
{
{
saveImagesStatement . TryBind ( "@Id" , item . Id . ToGuidBlob ( ) ) ;
saveImagesStatement . TryBind ( "@Id" , item . Id . ToGuidBlob ( ) ) ;
saveImagesStatement . TryBind ( "@Images" , SerializeImages ( item ) ) ;
saveImagesStatement . TryBind ( "@Images" , SerializeImages ( item ) ) ;
@ -567,7 +562,6 @@ namespace Emby.Server.Implementations.Data
} , TransactionMode ) ;
} , TransactionMode ) ;
}
}
}
}
}
/// <summary>
/// <summary>
/// Saves the items.
/// Saves the items.
@ -605,26 +599,22 @@ namespace Emby.Server.Implementations.Data
tuples . Add ( ( item , ancestorIds , topParent , userdataKey , inheritedTags ) ) ;
tuples . Add ( ( item , ancestorIds , topParent , userdataKey , inheritedTags ) ) ;
}
}
using ( WriteLock . Write ( ) )
using ( var connection = GetConnection ( ) )
{
using ( var connection = CreateConnection ( ) )
{
{
connection . RunInTransaction ( db = >
connection . RunInTransaction ( db = >
{
{
SaveItemsInTranscation ( db , tuples ) ;
SaveItemsInTranscation ( db , tuples ) ;
} , TransactionMode ) ;
} , TransactionMode ) ;
}
}
}
}
}
private void SaveItemsInTranscation ( IDatabaseConnection db , IEnumerable < ( BaseItem , List < Guid > , BaseItem , string , List < string > ) > tuples )
private void SaveItemsInTranscation ( IDatabaseConnection db , IEnumerable < ( BaseItem , List < Guid > , BaseItem , string , List < string > ) > tuples )
{
{
var statements = PrepareAll Safe ( db , new string [ ]
var statements = PrepareAll ( db , new string [ ]
{
{
GetSaveItemCommandText ( ) ,
GetSaveItemCommandText ( ) ,
"delete from AncestorIds where ItemId=@ItemId"
"delete from AncestorIds where ItemId=@ItemId"
} ) ;
} ) .ToList ( ) ;
using ( var saveItemStatement = statements [ 0 ] )
using ( var saveItemStatement = statements [ 0 ] )
using ( var deleteAncestorsStatement = statements [ 1 ] )
using ( var deleteAncestorsStatement = statements [ 1 ] )
@ -999,6 +989,7 @@ namespace Emby.Server.Implementations.Data
{
{
albumArtists = string . Join ( "|" , hasAlbumArtists . AlbumArtists ) ;
albumArtists = string . Join ( "|" , hasAlbumArtists . AlbumArtists ) ;
}
}
saveItemStatement . TryBind ( "@AlbumArtists" , albumArtists ) ;
saveItemStatement . TryBind ( "@AlbumArtists" , albumArtists ) ;
saveItemStatement . TryBind ( "@ExternalId" , item . ExternalId ) ;
saveItemStatement . TryBind ( "@ExternalId" , item . ExternalId ) ;
@ -1035,6 +1026,7 @@ namespace Emby.Server.Implementations.Data
{
{
continue ;
continue ;
}
}
str . Append ( $"{i.Key}={i.Value}|" ) ;
str . Append ( $"{i.Key}={i.Value}|" ) ;
}
}
@ -1042,6 +1034,7 @@ namespace Emby.Server.Implementations.Data
{
{
return null ;
return null ;
}
}
str . Length - = 1 ; // Remove last |
str . Length - = 1 ; // Remove last |
return str . ToString ( ) ;
return str . ToString ( ) ;
}
}
@ -1079,6 +1072,7 @@ namespace Emby.Server.Implementations.Data
{
{
return null ;
return null ;
}
}
StringBuilder str = new StringBuilder ( ) ;
StringBuilder str = new StringBuilder ( ) ;
foreach ( var i in images )
foreach ( var i in images )
{
{
@ -1088,6 +1082,7 @@ namespace Emby.Server.Implementations.Data
}
}
str . Append ( ToValueString ( i ) + "|" ) ;
str . Append ( ToValueString ( i ) + "|" ) ;
}
}
str . Length - = 1 ; // Remove last |
str . Length - = 1 ; // Remove last |
return str . ToString ( ) ;
return str . ToString ( ) ;
}
}
@ -1193,11 +1188,9 @@ namespace Emby.Server.Implementations.Data
CheckDisposed ( ) ;
CheckDisposed ( ) ;
using ( WriteLock . Read ( ) )
using ( var connection = GetConnection ( true ) )
{
{
using ( var connection = CreateConnection ( true ) )
using ( var statement = PrepareStatement ( connection , "select " + string . Join ( "," , _retriveItemColumns ) + " from TypedBaseItems where guid = @guid" ) )
{
using ( var statement = PrepareStatementSafe ( connection , "select " + string . Join ( "," , _retriveItemColumns ) + " from TypedBaseItems where guid = @guid" ) )
{
{
statement . TryBind ( "@guid" , id ) ;
statement . TryBind ( "@guid" , id ) ;
@ -1206,11 +1199,10 @@ namespace Emby.Server.Implementations.Data
return GetItem ( row , new InternalItemsQuery ( ) ) ;
return GetItem ( row , new InternalItemsQuery ( ) ) ;
}
}
}
}
}
return null ;
return null ;
}
}
}
}
private bool TypeRequiresDeserialization ( Type type )
private bool TypeRequiresDeserialization ( Type type )
{
{
@ -1909,24 +1901,21 @@ namespace Emby.Server.Implementations.Data
{
{
CheckDisposed ( ) ;
CheckDisposed ( ) ;
using ( WriteLock . Read ( ) )
using ( var connection = GetConnection ( true ) )
{
using ( var connection = CreateConnection ( true ) )
{
{
var list = new List < ChapterInfo > ( ) ;
var chapters = new List < ChapterInfo > ( ) ;
using ( var statement = PrepareStatement Safe ( connection , "select StartPositionTicks,Name,ImagePath,ImageDateModified from " + ChaptersTableName + " where ItemId = @ItemId order by ChapterIndex asc" ) )
using ( var statement = PrepareStatement ( connection , "select StartPositionTicks,Name,ImagePath,ImageDateModified from " + ChaptersTableName + " where ItemId = @ItemId order by ChapterIndex asc" ) )
{
{
statement . TryBind ( "@ItemId" , item . Id ) ;
statement . TryBind ( "@ItemId" , item . Id ) ;
foreach ( var row in statement . ExecuteQuery ( ) )
foreach ( var row in statement . ExecuteQuery ( ) )
{
{
list . Add ( GetChapter ( row , item ) ) ;
chapters . Add ( GetChapter ( row , item ) ) ;
}
}
}
}
return list ;
return chapters ;
}
}
}
}
}
@ -1941,11 +1930,9 @@ namespace Emby.Server.Implementations.Data
{
{
CheckDisposed ( ) ;
CheckDisposed ( ) ;
using ( WriteLock . Read ( ) )
using ( var connection = GetConnection ( true ) )
{
{
using ( var connection = CreateConnection ( true ) )
using ( var statement = PrepareStatement ( connection , "select StartPositionTicks,Name,ImagePath,ImageDateModified from " + ChaptersTableName + " where ItemId = @ItemId and ChapterIndex=@ChapterIndex" ) )
{
using ( var statement = PrepareStatementSafe ( connection , "select StartPositionTicks,Name,ImagePath,ImageDateModified from " + ChaptersTableName + " where ItemId = @ItemId and ChapterIndex=@ChapterIndex" ) )
{
{
statement . TryBind ( "@ItemId" , item . Id ) ;
statement . TryBind ( "@ItemId" , item . Id ) ;
statement . TryBind ( "@ChapterIndex" , index ) ;
statement . TryBind ( "@ChapterIndex" , index ) ;
@ -1956,7 +1943,7 @@ namespace Emby.Server.Implementations.Data
}
}
}
}
}
}
}
return null ;
return null ;
}
}
@ -2012,9 +1999,7 @@ namespace Emby.Server.Implementations.Data
throw new ArgumentNullException ( nameof ( chapters ) ) ;
throw new ArgumentNullException ( nameof ( chapters ) ) ;
}
}
using ( WriteLock . Write ( ) )
using ( var connection = GetConnection ( ) )
{
using ( var connection = CreateConnection ( ) )
{
{
connection . RunInTransaction ( db = >
connection . RunInTransaction ( db = >
{
{
@ -2028,7 +2013,6 @@ namespace Emby.Server.Implementations.Data
} , TransactionMode ) ;
} , TransactionMode ) ;
}
}
}
}
}
private void InsertChapters ( byte [ ] idBlob , List < ChapterInfo > chapters , IDatabaseConnection db )
private void InsertChapters ( byte [ ] idBlob , List < ChapterInfo > chapters , IDatabaseConnection db )
{
{
@ -2048,7 +2032,7 @@ namespace Emby.Server.Implementations.Data
}
}
insertText . Length - = 1 ; // Remove last ,
insertText . Length - = 1 ; // Remove last ,
using ( var statement = PrepareStatement Safe ( db , insertText . ToString ( ) ) )
using ( var statement = PrepareStatement ( db , insertText . ToString ( ) ) )
{
{
statement . TryBind ( "@ItemId" , idBlob ) ;
statement . TryBind ( "@ItemId" , idBlob ) ;
@ -2551,11 +2535,9 @@ namespace Emby.Server.Implementations.Data
commandText + = " where " + string . Join ( " AND " , whereClauses ) ;
commandText + = " where " + string . Join ( " AND " , whereClauses ) ;
}
}
using ( WriteLock . Read ( ) )
using ( var connection = GetConnection ( true ) )
{
using ( var connection = CreateConnection ( true ) )
{
{
using ( var statement = PrepareStatement Safe ( connection , commandText ) )
using ( var statement = PrepareStatement ( connection , commandText ) )
{
{
if ( EnableJoinUserData ( query ) )
if ( EnableJoinUserData ( query ) )
{
{
@ -2573,8 +2555,6 @@ namespace Emby.Server.Implementations.Data
return count ;
return count ;
}
}
}
}
}
}
}
public List < BaseItem > GetItemList ( InternalItemsQuery query )
public List < BaseItem > GetItemList ( InternalItemsQuery query )
@ -2624,13 +2604,11 @@ namespace Emby.Server.Implementations.Data
}
}
}
}
using ( WriteLock . Read ( ) )
using ( var connection = GetConnection ( true ) )
{
using ( var connection = CreateConnection ( true ) )
{
{
var l is t = new List < BaseItem > ( ) ;
var items = new List < BaseItem > ( ) ;
using ( var statement = PrepareStatement Safe ( connection , commandText ) )
using ( var statement = PrepareStatement ( connection , commandText ) )
{
{
if ( EnableJoinUserData ( query ) )
if ( EnableJoinUserData ( query ) )
{
{
@ -2656,7 +2634,7 @@ namespace Emby.Server.Implementations.Data
var item = GetItem ( row , query , hasProgramAttributes , hasEpisodeAttributes , hasServiceName , hasStartDate , hasTrailerTypes , hasArtistFields , hasSeriesFields ) ;
var item = GetItem ( row , query , hasProgramAttributes , hasEpisodeAttributes , hasServiceName , hasStartDate , hasTrailerTypes , hasArtistFields , hasSeriesFields ) ;
if ( item ! = null )
if ( item ! = null )
{
{
l is t. Add ( item ) ;
items . Add ( item ) ;
}
}
}
}
}
}
@ -2668,7 +2646,7 @@ namespace Emby.Server.Implementations.Data
limit - = 4 ;
limit - = 4 ;
var newList = new List < BaseItem > ( ) ;
var newList = new List < BaseItem > ( ) ;
foreach ( var item in l ist )
foreach ( var item in item s)
{
{
AddItem ( newList , item ) ;
AddItem ( newList , item ) ;
@ -2678,13 +2656,12 @@ namespace Emby.Server.Implementations.Data
}
}
}
}
l is t = newList ;
items = newList ;
}
}
LogQueryTime ( "GetItemList" , commandText , now ) ;
LogQueryTime ( "GetItemList" , commandText , now ) ;
return list ;
return items ;
}
}
}
}
}
@ -2845,14 +2822,12 @@ namespace Emby.Server.Implementations.Data
statementTexts . Add ( commandText ) ;
statementTexts . Add ( commandText ) ;
}
}
using ( WriteLock . Read ( ) )
using ( var connection = GetConnection ( true ) )
{
using ( var connection = CreateConnection ( true ) )
{
{
return connection . RunInTransaction ( db = >
return connection . RunInTransaction ( db = >
{
{
var result = new QueryResult < BaseItem > ( ) ;
var result = new QueryResult < BaseItem > ( ) ;
var statements = PrepareAll Safe ( db , statementTexts ) ;
var statements = PrepareAll ( db , statementTexts ) . ToList ( ) ;
if ( ! isReturningZeroItems )
if ( ! isReturningZeroItems )
{
{
@ -2915,7 +2890,6 @@ namespace Emby.Server.Implementations.Data
} , ReadTransactionMode ) ;
} , ReadTransactionMode ) ;
}
}
}
}
}
private string GetOrderByText ( InternalItemsQuery query )
private string GetOrderByText ( InternalItemsQuery query )
{
{
@ -3080,13 +3054,11 @@ namespace Emby.Server.Implementations.Data
}
}
}
}
using ( WriteLock . Read ( ) )
using ( var connection = GetConnection ( true ) )
{
using ( var connection = CreateConnection ( true ) )
{
{
var list = new List < Guid > ( ) ;
var list = new List < Guid > ( ) ;
using ( var statement = PrepareStatement Safe ( connection , commandText ) )
using ( var statement = PrepareStatement ( connection , commandText ) )
{
{
if ( EnableJoinUserData ( query ) )
if ( EnableJoinUserData ( query ) )
{
{
@ -3110,7 +3082,6 @@ namespace Emby.Server.Implementations.Data
return list ;
return list ;
}
}
}
}
}
public List < Tuple < Guid , string > > GetItemIdsWithPath ( InternalItemsQuery query )
public List < Tuple < Guid , string > > GetItemIdsWithPath ( InternalItemsQuery query )
{
{
@ -3149,12 +3120,10 @@ namespace Emby.Server.Implementations.Data
}
}
}
}
using ( WriteLock . Read ( ) )
{
var list = new List < Tuple < Guid , string > > ( ) ;
var list = new List < Tuple < Guid , string > > ( ) ;
using ( var connection = Create Connection( true ) )
using ( var connection = GetConnection ( true ) )
{
{
using ( var statement = PrepareStatement Safe ( connection , commandText ) )
using ( var statement = PrepareStatement ( connection , commandText ) )
{
{
if ( EnableJoinUserData ( query ) )
if ( EnableJoinUserData ( query ) )
{
{
@ -3182,7 +3151,6 @@ namespace Emby.Server.Implementations.Data
return list ;
return list ;
}
}
}
public QueryResult < Guid > GetItemIds ( InternalItemsQuery query )
public QueryResult < Guid > GetItemIds ( InternalItemsQuery query )
{
{
@ -3265,15 +3233,13 @@ namespace Emby.Server.Implementations.Data
statementTexts . Add ( commandText ) ;
statementTexts . Add ( commandText ) ;
}
}
using ( WriteLock . Read ( ) )
using ( var connection = GetConnection ( true ) )
{
using ( var connection = CreateConnection ( true ) )
{
{
return connection . RunInTransaction ( db = >
return connection . RunInTransaction ( db = >
{
{
var result = new QueryResult < Guid > ( ) ;
var result = new QueryResult < Guid > ( ) ;
var statements = PrepareAll Safe ( db , statementTexts ) ;
var statements = PrepareAll ( db , statementTexts ) . ToList ( ) ;
if ( ! isReturningZeroItems )
if ( ! isReturningZeroItems )
{
{
@ -3324,7 +3290,6 @@ namespace Emby.Server.Implementations.Data
} , ReadTransactionMode ) ;
} , ReadTransactionMode ) ;
}
}
}
}
}
private bool IsAlphaNumeric ( string str )
private bool IsAlphaNumeric ( string str )
{
{
@ -4899,9 +4864,7 @@ namespace Emby.Server.Implementations.Data
private void UpdateInheritedTags ( CancellationToken cancellationToken )
private void UpdateInheritedTags ( CancellationToken cancellationToken )
{
{
using ( WriteLock . Write ( ) )
using ( var connection = GetConnection ( ) )
{
using ( var connection = CreateConnection ( ) )
{
{
connection . RunInTransaction ( db = >
connection . RunInTransaction ( db = >
{
{
@ -4921,7 +4884,6 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
} , TransactionMode ) ;
} , TransactionMode ) ;
}
}
}
}
}
private static Dictionary < string , string [ ] > GetTypeMapDictionary ( )
private static Dictionary < string , string [ ] > GetTypeMapDictionary ( )
{
{
@ -4965,9 +4927,7 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
CheckDisposed ( ) ;
CheckDisposed ( ) ;
using ( WriteLock . Write ( ) )
using ( var connection = GetConnection ( ) )
{
using ( var connection = CreateConnection ( ) )
{
{
connection . RunInTransaction ( db = >
connection . RunInTransaction ( db = >
{
{
@ -4993,7 +4953,6 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
} , TransactionMode ) ;
} , TransactionMode ) ;
}
}
}
}
}
private void ExecuteWithSingleParam ( IDatabaseConnection db , string query , byte [ ] value )
private void ExecuteWithSingleParam ( IDatabaseConnection db , string query , byte [ ] value )
{
{
@ -5025,12 +4984,10 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
commandText + = " order by ListOrder" ;
commandText + = " order by ListOrder" ;
using ( WriteLock . Read ( ) )
using ( var connection = GetConnection ( true ) )
{
using ( var connection = CreateConnection ( true ) )
{
{
var list = new List < string > ( ) ;
var list = new List < string > ( ) ;
using ( var statement = PrepareStatement Safe ( connection , commandText ) )
using ( var statement = PrepareStatement ( connection , commandText ) )
{
{
// Run this again to bind the params
// Run this again to bind the params
GetPeopleWhereClauses ( query , statement ) ;
GetPeopleWhereClauses ( query , statement ) ;
@ -5043,7 +5000,6 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
return list ;
return list ;
}
}
}
}
}
public List < PersonInfo > GetPeople ( InternalPeopleQuery query )
public List < PersonInfo > GetPeople ( InternalPeopleQuery query )
{
{
@ -5065,13 +5021,11 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
commandText + = " order by ListOrder" ;
commandText + = " order by ListOrder" ;
using ( WriteLock . Read ( ) )
using ( var connection = GetConnection ( true ) )
{
using ( var connection = CreateConnection ( true ) )
{
{
var list = new List < PersonInfo > ( ) ;
var list = new List < PersonInfo > ( ) ;
using ( var statement = PrepareStatement Safe ( connection , commandText ) )
using ( var statement = PrepareStatement ( connection , commandText ) )
{
{
// Run this again to bind the params
// Run this again to bind the params
GetPeopleWhereClauses ( query , statement ) ;
GetPeopleWhereClauses ( query , statement ) ;
@ -5085,7 +5039,6 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
return list ;
return list ;
}
}
}
}
}
private List < string > GetPeopleWhereClauses ( InternalPeopleQuery query , IStatement statement )
private List < string > GetPeopleWhereClauses ( InternalPeopleQuery query , IStatement statement )
{
{
@ -5197,7 +5150,7 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
insertText . AppendFormat ( "(@ItemId, @AncestorId{0}, @AncestorIdText{0})" , i . ToString ( CultureInfo . InvariantCulture ) ) ;
insertText . AppendFormat ( "(@ItemId, @AncestorId{0}, @AncestorIdText{0})" , i . ToString ( CultureInfo . InvariantCulture ) ) ;
}
}
using ( var statement = PrepareStatement Safe ( db , insertText . ToString ( ) ) )
using ( var statement = PrepareStatement ( db , insertText . ToString ( ) ) )
{
{
statement . TryBind ( "@ItemId" , itemIdBlob ) ;
statement . TryBind ( "@ItemId" , itemIdBlob ) ;
@ -5294,13 +5247,11 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
commandText + = " Group By CleanValue" ;
commandText + = " Group By CleanValue" ;
using ( WriteLock . Read ( ) )
using ( var connection = GetConnection ( true ) )
{
using ( var connection = CreateConnection ( true ) )
{
{
var list = new List < string > ( ) ;
var list = new List < string > ( ) ;
using ( var statement = PrepareStatement Safe ( connection , commandText ) )
using ( var statement = PrepareStatement ( connection , commandText ) )
{
{
foreach ( var row in statement . ExecuteQuery ( ) )
foreach ( var row in statement . ExecuteQuery ( ) )
{
{
@ -5316,7 +5267,6 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
return list ;
return list ;
}
}
}
}
}
private QueryResult < ( BaseItem , ItemCounts ) > GetItemValues ( InternalItemsQuery query , int [ ] itemValueTypes , string returnType )
private QueryResult < ( BaseItem , ItemCounts ) > GetItemValues ( InternalItemsQuery query , int [ ] itemValueTypes , string returnType )
{
{
@ -5483,16 +5433,14 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
statementTexts . Add ( countText ) ;
statementTexts . Add ( countText ) ;
}
}
using ( WriteLock . Read ( ) )
using ( var connection = GetConnection ( true ) )
{
using ( var connection = CreateConnection ( true ) )
{
{
return connection . RunInTransaction ( db = >
return connection . RunInTransaction ( db = >
{
{
var list = new List < ( BaseItem , ItemCounts ) > ( ) ;
var list = new List < ( BaseItem , ItemCounts ) > ( ) ;
var result = new QueryResult < ( BaseItem , ItemCounts ) > ( ) ;
var result = new QueryResult < ( BaseItem , ItemCounts ) > ( ) ;
var statements = PrepareAll Safe ( db , statementTexts ) ;
var statements = PrepareAll ( db , statementTexts ) . ToList ( ) ;
if ( ! isReturningZeroItems )
if ( ! isReturningZeroItems )
{
{
@ -5578,7 +5526,6 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
} , ReadTransactionMode ) ;
} , ReadTransactionMode ) ;
}
}
}
}
}
private ItemCounts GetItemCounts ( IReadOnlyList < IResultSetValue > reader , int countStartColumn , string [ ] typesToCount )
private ItemCounts GetItemCounts ( IReadOnlyList < IResultSetValue > reader , int countStartColumn , string [ ] typesToCount )
{
{
@ -5708,7 +5655,7 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
isSubsequentRow = true ;
isSubsequentRow = true ;
}
}
using ( var statement = PrepareStatement Safe ( db , insertText . ToString ( ) ) )
using ( var statement = PrepareStatement ( db , insertText . ToString ( ) ) )
{
{
statement . TryBind ( "@ItemId" , idBlob ) ;
statement . TryBind ( "@ItemId" , idBlob ) ;
@ -5753,9 +5700,7 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
CheckDisposed ( ) ;
CheckDisposed ( ) ;
using ( WriteLock . Write ( ) )
using ( var connection = GetConnection ( ) )
{
using ( var connection = CreateConnection ( ) )
{
{
connection . RunInTransaction ( db = >
connection . RunInTransaction ( db = >
{
{
@ -5767,8 +5712,6 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
InsertPeople ( itemIdBlob , people , db ) ;
InsertPeople ( itemIdBlob , people , db ) ;
} , TransactionMode ) ;
} , TransactionMode ) ;
}
}
}
}
}
@ -5796,7 +5739,7 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
isSubsequentRow = true ;
isSubsequentRow = true ;
}
}
using ( var statement = PrepareStatement Safe ( db , insertText . ToString ( ) ) )
using ( var statement = PrepareStatement ( db , insertText . ToString ( ) ) )
{
{
statement . TryBind ( "@ItemId" , idBlob ) ;
statement . TryBind ( "@ItemId" , idBlob ) ;
@ -5874,13 +5817,11 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
cmdText + = " order by StreamIndex ASC" ;
cmdText + = " order by StreamIndex ASC" ;
using ( WriteLock . Read ( ) )
using ( var connection = GetConnection ( true ) )
{
using ( var connection = CreateConnection ( true ) )
{
{
var list = new List < MediaStream > ( ) ;
var list = new List < MediaStream > ( ) ;
using ( var statement = PrepareStatement Safe ( connection , cmdText ) )
using ( var statement = PrepareStatement ( connection , cmdText ) )
{
{
statement . TryBind ( "@ItemId" , query . ItemId . ToGuidBlob ( ) ) ;
statement . TryBind ( "@ItemId" , query . ItemId . ToGuidBlob ( ) ) ;
@ -5903,7 +5844,6 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
return list ;
return list ;
}
}
}
}
}
public void SaveMediaStreams ( Guid id , List < MediaStream > streams , CancellationToken cancellationToken )
public void SaveMediaStreams ( Guid id , List < MediaStream > streams , CancellationToken cancellationToken )
{
{
@ -5921,9 +5861,7 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
cancellationToken . ThrowIfCancellationRequested ( ) ;
cancellationToken . ThrowIfCancellationRequested ( ) ;
using ( WriteLock . Write ( ) )
using ( var connection = GetConnection ( ) )
{
using ( var connection = CreateConnection ( ) )
{
{
connection . RunInTransaction ( db = >
connection . RunInTransaction ( db = >
{
{
@ -5937,7 +5875,6 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
} , TransactionMode ) ;
} , TransactionMode ) ;
}
}
}
}
}
private void InsertMediaStreams ( byte [ ] idBlob , List < MediaStream > streams , IDatabaseConnection db )
private void InsertMediaStreams ( byte [ ] idBlob , List < MediaStream > streams , IDatabaseConnection db )
{
{
@ -5969,7 +5906,7 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
insertText . Append ( ")" ) ;
insertText . Append ( ")" ) ;
}
}
using ( var statement = PrepareStatement Safe ( db , insertText . ToString ( ) ) )
using ( var statement = PrepareStatement ( db , insertText . ToString ( ) ) )
{
{
statement . TryBind ( "@ItemId" , idBlob ) ;
statement . TryBind ( "@ItemId" , idBlob ) ;