diff --git a/Emby.Server.Implementations/Data/SqliteExtensions.cs b/Emby.Server.Implementations/Data/SqliteExtensions.cs index d9536ae9c5..3dc3cec8e9 100644 --- a/Emby.Server.Implementations/Data/SqliteExtensions.cs +++ b/Emby.Server.Implementations/Data/SqliteExtensions.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Globalization; using MediaBrowser.Model.IO; using MediaBrowser.Model.Serialization; @@ -127,5 +128,14 @@ namespace Emby.Server.Implementations.Data return stream.ToArray(); } } + + public static void Attach(IDatabaseConnection db, string path, string alias) + { + var commandText = string.Format("attach ? as {0};", alias); + var paramList = new List(); + paramList.Add(path); + + db.Execute(commandText, paramList.ToArray()); + } } } diff --git a/Emby.Server.Implementations/Data/SqliteItemRepository.cs b/Emby.Server.Implementations/Data/SqliteItemRepository.cs index c88bffe045..32cfecfce4 100644 --- a/Emby.Server.Implementations/Data/SqliteItemRepository.cs +++ b/Emby.Server.Implementations/Data/SqliteItemRepository.cs @@ -139,7 +139,7 @@ // /// Task. // public async Task Initialize(SqliteUserDataRepository userDataRepo) // { -// _connection = await CreateConnection(false).ConfigureAwait(false); +// _connection = CreateConnection(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, CodecTag TEXT NULL, Comment TEXT NULL, NalLengthSize TEXT NULL, IsAvc BIT NULL, Title TEXT NULL, TimeBase TEXT NULL, CodecTimeBase TEXT NULL, PRIMARY KEY (ItemId, StreamIndex))"; @@ -168,109 +168,131 @@ // }; -// _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"); -// _connection.AddColumn(Logger, "TypedBaseItems", "ChannelId", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "IsMovie", "BIT"); -// _connection.AddColumn(Logger, "TypedBaseItems", "IsSports", "BIT"); -// _connection.AddColumn(Logger, "TypedBaseItems", "IsKids", "BIT"); -// _connection.AddColumn(Logger, "TypedBaseItems", "CommunityRating", "Float"); -// _connection.AddColumn(Logger, "TypedBaseItems", "CustomRating", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "IndexNumber", "INT"); -// _connection.AddColumn(Logger, "TypedBaseItems", "IsLocked", "BIT"); -// _connection.AddColumn(Logger, "TypedBaseItems", "Name", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "OfficialRating", "Text"); - -// _connection.AddColumn(Logger, "TypedBaseItems", "MediaType", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "Overview", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "ParentIndexNumber", "INT"); -// _connection.AddColumn(Logger, "TypedBaseItems", "PremiereDate", "DATETIME"); -// _connection.AddColumn(Logger, "TypedBaseItems", "ProductionYear", "INT"); -// _connection.AddColumn(Logger, "TypedBaseItems", "ParentId", "GUID"); -// _connection.AddColumn(Logger, "TypedBaseItems", "Genres", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "SchemaVersion", "INT"); -// _connection.AddColumn(Logger, "TypedBaseItems", "SortName", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "RunTimeTicks", "BIGINT"); - -// _connection.AddColumn(Logger, "TypedBaseItems", "OfficialRatingDescription", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "HomePageUrl", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "VoteCount", "INT"); -// _connection.AddColumn(Logger, "TypedBaseItems", "DisplayMediaType", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "DateCreated", "DATETIME"); -// _connection.AddColumn(Logger, "TypedBaseItems", "DateModified", "DATETIME"); - -// _connection.AddColumn(Logger, "TypedBaseItems", "ForcedSortName", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "IsOffline", "BIT"); -// _connection.AddColumn(Logger, "TypedBaseItems", "LocationType", "Text"); - -// _connection.AddColumn(Logger, "TypedBaseItems", "IsSeries", "BIT"); -// _connection.AddColumn(Logger, "TypedBaseItems", "IsLive", "BIT"); -// _connection.AddColumn(Logger, "TypedBaseItems", "IsNews", "BIT"); -// _connection.AddColumn(Logger, "TypedBaseItems", "IsPremiere", "BIT"); - -// _connection.AddColumn(Logger, "TypedBaseItems", "EpisodeTitle", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "IsRepeat", "BIT"); - -// _connection.AddColumn(Logger, "TypedBaseItems", "PreferredMetadataLanguage", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "PreferredMetadataCountryCode", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "IsHD", "BIT"); -// _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"); -// _connection.AddColumn(Logger, "TypedBaseItems", "IsItemByName", "BIT"); -// _connection.AddColumn(Logger, "TypedBaseItems", "SourceType", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "TrailerTypes", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "CriticRating", "Float"); -// _connection.AddColumn(Logger, "TypedBaseItems", "CriticRatingSummary", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "InheritedTags", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "CleanName", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "PresentationUniqueKey", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "SlugName", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "OriginalTitle", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "PrimaryVersionId", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "DateLastMediaAdded", "DATETIME"); -// _connection.AddColumn(Logger, "TypedBaseItems", "Album", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "IsVirtualItem", "BIT"); -// _connection.AddColumn(Logger, "TypedBaseItems", "SeriesName", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "UserDataKey", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "SeasonName", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "SeasonId", "GUID"); -// _connection.AddColumn(Logger, "TypedBaseItems", "SeriesId", "GUID"); -// _connection.AddColumn(Logger, "TypedBaseItems", "SeriesSortName", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "ExternalSeriesId", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "ShortOverview", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "Tagline", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "Keywords", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "ProviderIds", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "Images", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "ProductionLocations", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "ThemeSongIds", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "ThemeVideoIds", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "TotalBitrate", "INT"); -// _connection.AddColumn(Logger, "TypedBaseItems", "ExtraType", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "Artists", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "AlbumArtists", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "ExternalId", "Text"); - -// _connection.AddColumn(Logger, "ItemValues", "CleanValue", "Text"); - -// _connection.AddColumn(Logger, ChaptersTableName, "ImageDateModified", "DATETIME"); +// _connection.RunQueries(queries); + +// _connection.RunInTransaction(db => +// { +// var existingColumnNames = GetColumnNames(db, "AncestorIds"); +// AddColumn(db, "AncestorIds", "AncestorIdText", "Text", existingColumnNames); + +// existingColumnNames = GetColumnNames(db, "TypedBaseItems"); + +// AddColumn(db, "TypedBaseItems", "Path", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "StartDate", "DATETIME", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "EndDate", "DATETIME", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "ChannelId", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "IsMovie", "BIT", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "IsSports", "BIT", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "IsKids", "BIT", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "CommunityRating", "Float", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "CustomRating", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "IndexNumber", "INT", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "IsLocked", "BIT", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "Name", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "OfficialRating", "Text", existingColumnNames); + +// AddColumn(db, "TypedBaseItems", "MediaType", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "Overview", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "ParentIndexNumber", "INT", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "PremiereDate", "DATETIME", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "ProductionYear", "INT", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "ParentId", "GUID", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "Genres", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "SchemaVersion", "INT", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "SortName", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "RunTimeTicks", "BIGINT", existingColumnNames); + +// AddColumn(db, "TypedBaseItems", "OfficialRatingDescription", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "HomePageUrl", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "VoteCount", "INT", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "DisplayMediaType", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "DateCreated", "DATETIME", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "DateModified", "DATETIME", existingColumnNames); + +// AddColumn(db, "TypedBaseItems", "ForcedSortName", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "IsOffline", "BIT", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "LocationType", "Text", existingColumnNames); + +// AddColumn(db, "TypedBaseItems", "IsSeries", "BIT", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "IsLive", "BIT", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "IsNews", "BIT", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "IsPremiere", "BIT", existingColumnNames); + +// AddColumn(db, "TypedBaseItems", "EpisodeTitle", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "IsRepeat", "BIT", existingColumnNames); + +// AddColumn(db, "TypedBaseItems", "PreferredMetadataLanguage", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "PreferredMetadataCountryCode", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "IsHD", "BIT", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "ExternalEtag", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "DateLastRefreshed", "DATETIME", existingColumnNames); + +// AddColumn(db, "TypedBaseItems", "DateLastSaved", "DATETIME", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "IsInMixedFolder", "BIT", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "LockedFields", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "Studios", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "Audio", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "ExternalServiceId", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "Tags", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "IsFolder", "BIT", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "InheritedParentalRatingValue", "INT", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "UnratedType", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "TopParentId", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "IsItemByName", "BIT", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "SourceType", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "TrailerTypes", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "CriticRating", "Float", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "CriticRatingSummary", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "InheritedTags", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "CleanName", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "PresentationUniqueKey", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "SlugName", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "OriginalTitle", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "PrimaryVersionId", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "DateLastMediaAdded", "DATETIME", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "Album", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "IsVirtualItem", "BIT", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "SeriesName", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "UserDataKey", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "SeasonName", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "SeasonId", "GUID", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "SeriesId", "GUID", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "SeriesSortName", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "ExternalSeriesId", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "ShortOverview", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "Tagline", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "Keywords", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "ProviderIds", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "Images", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "ProductionLocations", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "ThemeSongIds", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "ThemeVideoIds", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "TotalBitrate", "INT", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "ExtraType", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "Artists", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "AlbumArtists", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "ExternalId", "Text", existingColumnNames); + +// existingColumnNames = GetColumnNames(db, "ItemValues"); +// AddColumn(db, "ItemValues", "CleanValue", "Text", existingColumnNames); + +// existingColumnNames = GetColumnNames(db, ChaptersTableName); +// AddColumn(db, ChaptersTableName, "ImageDateModified", "DATETIME", existingColumnNames); + +// existingColumnNames = GetColumnNames(db, "MediaStreams"); +// AddColumn(db, "MediaStreams", "IsAvc", "BIT", existingColumnNames); +// AddColumn(db, "MediaStreams", "TimeBase", "TEXT", existingColumnNames); +// AddColumn(db, "MediaStreams", "CodecTimeBase", "TEXT", existingColumnNames); +// AddColumn(db, "MediaStreams", "Title", "TEXT", existingColumnNames); +// AddColumn(db, "MediaStreams", "NalLengthSize", "TEXT", existingColumnNames); +// AddColumn(db, "MediaStreams", "Comment", "TEXT", existingColumnNames); +// AddColumn(db, "MediaStreams", "CodecTag", "TEXT", existingColumnNames); +// AddColumn(db, "MediaStreams", "PixelFormat", "TEXT", existingColumnNames); +// AddColumn(db, "MediaStreams", "BitDepth", "INT", existingColumnNames); +// AddColumn(db, "MediaStreams", "RefFrames", "INT", existingColumnNames); +// AddColumn(db, "MediaStreams", "KeyFrames", "TEXT", existingColumnNames); +// AddColumn(db, "MediaStreams", "IsAnamorphic", "BIT", existingColumnNames); +// }); // string[] postQueries = @@ -334,14 +356,12 @@ // "create index if not exists idx_ItemValues7 on ItemValues(Type,CleanValue,ItemId)" // }; -// _connection.RunQueries(postQueries, Logger); +// _connection.RunQueries(postQueries); // PrepareStatements(); -// new MediaStreamColumns(_connection, Logger).AddColumns(); - -// DataExtensions.Attach(_connection, Path.Combine(_config.ApplicationPaths.DataPath, "userdata_v2.db"), "UserDataDb"); -// await userDataRepo.Initialize(_connection, WriteLock).ConfigureAwait(false); +// SqliteExtensions.Attach(_connection, Path.Combine(_config.ApplicationPaths.DataPath, "userdata_v2.db"), "UserDataDb"); +// userDataRepo.Initialize(_connection, WriteLock); // //await Vacuum(_connection).ConfigureAwait(false); // } diff --git a/Emby.Server.Implementations/Data/SqliteUserDataRepository.cs b/Emby.Server.Implementations/Data/SqliteUserDataRepository.cs index 4c73b6c6a1..5556c45027 100644 --- a/Emby.Server.Implementations/Data/SqliteUserDataRepository.cs +++ b/Emby.Server.Implementations/Data/SqliteUserDataRepository.cs @@ -1,331 +1,331 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using MediaBrowser.Common.Configuration; -using MediaBrowser.Controller.Entities; -using MediaBrowser.Controller.Persistence; -using MediaBrowser.Model.Logging; -using SQLitePCL.pretty; - -namespace Emby.Server.Implementations.Data -{ - public class SqliteUserDataRepository : BaseSqliteRepository, IUserDataRepository - { - private SQLiteDatabaseConnection _connection; - - public SqliteUserDataRepository(ILogger logger, IApplicationPaths appPaths) - : base(logger) - { - DbFilePath = Path.Combine(appPaths.DataPath, "userdata_v2.db"); - } - - protected override bool EnableConnectionPooling - { - get { return false; } - } - - /// - /// Gets the name of the repository - /// - /// The name. - public string Name - { - get - { - return "SQLite"; - } - } - - /// - /// Opens the connection to the database - /// - /// Task. - public void Initialize(SQLiteDatabaseConnection connection, ReaderWriterLockSlim writeLock) - { - WriteLock.Dispose(); - WriteLock = writeLock; - _connection = connection; - - string[] queries = { - - "create table if not exists UserDataDb.userdata (key nvarchar, userId GUID, rating float null, played bit, playCount int, isFavorite bit, playbackPositionTicks bigint, lastPlayedDate datetime null)", - - "drop index if exists UserDataDb.idx_userdata", - "drop index if exists UserDataDb.idx_userdata1", - "drop index if exists UserDataDb.idx_userdata2", - "drop index if exists UserDataDb.userdataindex1", - - "create unique index if not exists UserDataDb.userdataindex on userdata (key, userId)", - "create index if not exists UserDataDb.userdataindex2 on userdata (key, userId, played)", - "create index if not exists UserDataDb.userdataindex3 on userdata (key, userId, playbackPositionTicks)", - "create index if not exists UserDataDb.userdataindex4 on userdata (key, userId, isFavorite)", - - //pragmas - "pragma temp_store = memory", - - "pragma shrink_memory" - }; - - _connection.RunQueries(queries); - - connection.RunInTransaction(db => - { - var existingColumnNames = GetColumnNames(db, "userdata"); - - AddColumn(db, "userdata", "AudioStreamIndex", "int", existingColumnNames); - AddColumn(db, "userdata", "SubtitleStreamIndex", "int", existingColumnNames); - }); - } - - /// - /// Saves the user data. - /// - /// The user id. - /// The key. - /// The user data. - /// The cancellation token. - /// Task. - /// userData - /// or - /// cancellationToken - /// or - /// userId - /// or - /// userDataId - public Task SaveUserData(Guid userId, string key, UserItemData userData, CancellationToken cancellationToken) - { - if (userData == null) - { - throw new ArgumentNullException("userData"); - } - if (userId == Guid.Empty) - { - throw new ArgumentNullException("userId"); - } - if (string.IsNullOrEmpty(key)) - { - throw new ArgumentNullException("key"); - } - - return PersistUserData(userId, key, userData, cancellationToken); - } - - public Task SaveAllUserData(Guid userId, IEnumerable userData, CancellationToken cancellationToken) - { - if (userData == null) - { - throw new ArgumentNullException("userData"); - } - if (userId == Guid.Empty) - { - throw new ArgumentNullException("userId"); - } - - return PersistAllUserData(userId, userData.ToList(), cancellationToken); - } - - /// - /// Persists the user data. - /// - /// The user id. - /// The key. - /// The user data. - /// The cancellation token. - /// Task. - public async Task PersistUserData(Guid userId, string key, UserItemData userData, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - - using (WriteLock.Write()) - { - _connection.RunInTransaction(db => - { - SaveUserData(db, userId, key, userData); - }); - } - } - - private void SaveUserData(IDatabaseConnection db, Guid userId, string key, UserItemData userData) - { - var paramList = new List(); - var commandText = "replace into userdata (key, userId, rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex) values (?, ?, ?,?,?,?,?,?,?,?)"; - - paramList.Add(key); - paramList.Add(userId.ToGuidParamValue()); - paramList.Add(userData.Rating); - paramList.Add(userData.Played); - paramList.Add(userData.PlayCount); - paramList.Add(userData.IsFavorite); - paramList.Add(userData.PlaybackPositionTicks); - - if (userData.LastPlayedDate.HasValue) - { - paramList.Add(userData.LastPlayedDate.Value.ToDateTimeParamValue()); - } - else - { - paramList.Add(null); - } - paramList.Add(userData.AudioStreamIndex); - paramList.Add(userData.SubtitleStreamIndex); - - db.Execute(commandText, paramList.ToArray()); - } - - /// - /// Persist all user data for the specified user - /// - private async Task PersistAllUserData(Guid userId, List userDataList, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - - using (WriteLock.Write()) - { - _connection.RunInTransaction(db => - { - foreach (var userItemData in userDataList) - { - SaveUserData(db, userId, userItemData.Key, userItemData); - } - }); - } - } - - /// - /// Gets the user data. - /// - /// The user id. - /// The key. - /// Task{UserItemData}. - /// - /// userId - /// or - /// key - /// - public UserItemData GetUserData(Guid userId, string key) - { - if (userId == Guid.Empty) - { - throw new ArgumentNullException("userId"); - } - if (string.IsNullOrEmpty(key)) - { - throw new ArgumentNullException("key"); - } - - var commandText = "select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where key = ? and userId=?"; - - var paramList = new List(); - paramList.Add(key); - paramList.Add(userId.ToGuidParamValue()); - - foreach (var row in _connection.Query(commandText, paramList.ToArray())) - { - return ReadRow(row); - } - - return null; - } - - public UserItemData GetUserData(Guid userId, List keys) - { - if (userId == Guid.Empty) - { - throw new ArgumentNullException("userId"); - } - if (keys == null) - { - throw new ArgumentNullException("keys"); - } - - if (keys.Count == 0) - { - return null; - } - - return GetUserData(userId, keys[0]); - } - - /// - /// Return all user-data associated with the given user - /// - /// - /// - public IEnumerable GetAllUserData(Guid userId) - { - if (userId == Guid.Empty) - { - throw new ArgumentNullException("userId"); - } - - var list = new List(); - - using (WriteLock.Read()) - { - var commandText = "select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where userId=?"; - - var paramList = new List(); - paramList.Add(userId.ToGuidParamValue()); - - foreach (var row in _connection.Query(commandText, paramList.ToArray())) - { - list.Add(ReadRow(row)); - } - } - - return list; - } - - /// - /// Read a row from the specified reader into the provided userData object - /// - /// - private UserItemData ReadRow(IReadOnlyList reader) - { - var userData = new UserItemData(); - - userData.Key = reader[0].ToString(); - userData.UserId = reader[1].ReadGuid(); - - if (reader[2].SQLiteType != SQLiteType.Null) - { - userData.Rating = reader[2].ToDouble(); - } - - userData.Played = reader[3].ToBool(); - userData.PlayCount = reader[4].ToInt(); - userData.IsFavorite = reader[5].ToBool(); - userData.PlaybackPositionTicks = reader[6].ToInt64(); - - if (reader[7].SQLiteType != SQLiteType.Null) - { - userData.LastPlayedDate = reader[7].ReadDateTime(); - } - - if (reader[8].SQLiteType != SQLiteType.Null) - { - userData.AudioStreamIndex = reader[8].ToInt(); - } - - if (reader[9].SQLiteType != SQLiteType.Null) - { - userData.SubtitleStreamIndex = reader[9].ToInt(); - } - - return userData; - } - - protected override void Dispose(bool dispose) - { - // handled by library database - } - - protected override void CloseConnection() - { - // handled by library database - } - } -} \ No newline at end of file +//using System; +//using System.Collections.Generic; +//using System.IO; +//using System.Linq; +//using System.Threading; +//using System.Threading.Tasks; +//using MediaBrowser.Common.Configuration; +//using MediaBrowser.Controller.Entities; +//using MediaBrowser.Controller.Persistence; +//using MediaBrowser.Model.Logging; +//using SQLitePCL.pretty; + +//namespace Emby.Server.Implementations.Data +//{ +// public class SqliteUserDataRepository : BaseSqliteRepository, IUserDataRepository +// { +// private SQLiteDatabaseConnection _connection; + +// public SqliteUserDataRepository(ILogger logger, IApplicationPaths appPaths) +// : base(logger) +// { +// DbFilePath = Path.Combine(appPaths.DataPath, "userdata_v2.db"); +// } + +// protected override bool EnableConnectionPooling +// { +// get { return false; } +// } + +// /// +// /// Gets the name of the repository +// /// +// /// The name. +// public string Name +// { +// get +// { +// return "SQLite"; +// } +// } + +// /// +// /// Opens the connection to the database +// /// +// /// Task. +// public void Initialize(SQLiteDatabaseConnection connection, ReaderWriterLockSlim writeLock) +// { +// WriteLock.Dispose(); +// WriteLock = writeLock; +// _connection = connection; + +// string[] queries = { + +// "create table if not exists UserDataDb.userdata (key nvarchar, userId GUID, rating float null, played bit, playCount int, isFavorite bit, playbackPositionTicks bigint, lastPlayedDate datetime null)", + +// "drop index if exists UserDataDb.idx_userdata", +// "drop index if exists UserDataDb.idx_userdata1", +// "drop index if exists UserDataDb.idx_userdata2", +// "drop index if exists UserDataDb.userdataindex1", + +// "create unique index if not exists UserDataDb.userdataindex on userdata (key, userId)", +// "create index if not exists UserDataDb.userdataindex2 on userdata (key, userId, played)", +// "create index if not exists UserDataDb.userdataindex3 on userdata (key, userId, playbackPositionTicks)", +// "create index if not exists UserDataDb.userdataindex4 on userdata (key, userId, isFavorite)", + +// //pragmas +// "pragma temp_store = memory", + +// "pragma shrink_memory" +// }; + +// _connection.RunQueries(queries); + +// connection.RunInTransaction(db => +// { +// var existingColumnNames = GetColumnNames(db, "userdata"); + +// AddColumn(db, "userdata", "AudioStreamIndex", "int", existingColumnNames); +// AddColumn(db, "userdata", "SubtitleStreamIndex", "int", existingColumnNames); +// }); +// } + +// /// +// /// Saves the user data. +// /// +// /// The user id. +// /// The key. +// /// The user data. +// /// The cancellation token. +// /// Task. +// /// userData +// /// or +// /// cancellationToken +// /// or +// /// userId +// /// or +// /// userDataId +// public Task SaveUserData(Guid userId, string key, UserItemData userData, CancellationToken cancellationToken) +// { +// if (userData == null) +// { +// throw new ArgumentNullException("userData"); +// } +// if (userId == Guid.Empty) +// { +// throw new ArgumentNullException("userId"); +// } +// if (string.IsNullOrEmpty(key)) +// { +// throw new ArgumentNullException("key"); +// } + +// return PersistUserData(userId, key, userData, cancellationToken); +// } + +// public Task SaveAllUserData(Guid userId, IEnumerable userData, CancellationToken cancellationToken) +// { +// if (userData == null) +// { +// throw new ArgumentNullException("userData"); +// } +// if (userId == Guid.Empty) +// { +// throw new ArgumentNullException("userId"); +// } + +// return PersistAllUserData(userId, userData.ToList(), cancellationToken); +// } + +// /// +// /// Persists the user data. +// /// +// /// The user id. +// /// The key. +// /// The user data. +// /// The cancellation token. +// /// Task. +// public async Task PersistUserData(Guid userId, string key, UserItemData userData, CancellationToken cancellationToken) +// { +// cancellationToken.ThrowIfCancellationRequested(); + +// using (WriteLock.Write()) +// { +// _connection.RunInTransaction(db => +// { +// SaveUserData(db, userId, key, userData); +// }); +// } +// } + +// private void SaveUserData(IDatabaseConnection db, Guid userId, string key, UserItemData userData) +// { +// var paramList = new List(); +// var commandText = "replace into userdata (key, userId, rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex) values (?, ?, ?,?,?,?,?,?,?,?)"; + +// paramList.Add(key); +// paramList.Add(userId.ToGuidParamValue()); +// paramList.Add(userData.Rating); +// paramList.Add(userData.Played); +// paramList.Add(userData.PlayCount); +// paramList.Add(userData.IsFavorite); +// paramList.Add(userData.PlaybackPositionTicks); + +// if (userData.LastPlayedDate.HasValue) +// { +// paramList.Add(userData.LastPlayedDate.Value.ToDateTimeParamValue()); +// } +// else +// { +// paramList.Add(null); +// } +// paramList.Add(userData.AudioStreamIndex); +// paramList.Add(userData.SubtitleStreamIndex); + +// db.Execute(commandText, paramList.ToArray()); +// } + +// /// +// /// Persist all user data for the specified user +// /// +// private async Task PersistAllUserData(Guid userId, List userDataList, CancellationToken cancellationToken) +// { +// cancellationToken.ThrowIfCancellationRequested(); + +// using (WriteLock.Write()) +// { +// _connection.RunInTransaction(db => +// { +// foreach (var userItemData in userDataList) +// { +// SaveUserData(db, userId, userItemData.Key, userItemData); +// } +// }); +// } +// } + +// /// +// /// Gets the user data. +// /// +// /// The user id. +// /// The key. +// /// Task{UserItemData}. +// /// +// /// userId +// /// or +// /// key +// /// +// public UserItemData GetUserData(Guid userId, string key) +// { +// if (userId == Guid.Empty) +// { +// throw new ArgumentNullException("userId"); +// } +// if (string.IsNullOrEmpty(key)) +// { +// throw new ArgumentNullException("key"); +// } + +// var commandText = "select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where key = ? and userId=?"; + +// var paramList = new List(); +// paramList.Add(key); +// paramList.Add(userId.ToGuidParamValue()); + +// foreach (var row in _connection.Query(commandText, paramList.ToArray())) +// { +// return ReadRow(row); +// } + +// return null; +// } + +// public UserItemData GetUserData(Guid userId, List keys) +// { +// if (userId == Guid.Empty) +// { +// throw new ArgumentNullException("userId"); +// } +// if (keys == null) +// { +// throw new ArgumentNullException("keys"); +// } + +// if (keys.Count == 0) +// { +// return null; +// } + +// return GetUserData(userId, keys[0]); +// } + +// /// +// /// Return all user-data associated with the given user +// /// +// /// +// /// +// public IEnumerable GetAllUserData(Guid userId) +// { +// if (userId == Guid.Empty) +// { +// throw new ArgumentNullException("userId"); +// } + +// var list = new List(); + +// using (WriteLock.Read()) +// { +// var commandText = "select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where userId=?"; + +// var paramList = new List(); +// paramList.Add(userId.ToGuidParamValue()); + +// foreach (var row in _connection.Query(commandText, paramList.ToArray())) +// { +// list.Add(ReadRow(row)); +// } +// } + +// return list; +// } + +// /// +// /// Read a row from the specified reader into the provided userData object +// /// +// /// +// private UserItemData ReadRow(IReadOnlyList reader) +// { +// var userData = new UserItemData(); + +// userData.Key = reader[0].ToString(); +// userData.UserId = reader[1].ReadGuid(); + +// if (reader[2].SQLiteType != SQLiteType.Null) +// { +// userData.Rating = reader[2].ToDouble(); +// } + +// userData.Played = reader[3].ToBool(); +// userData.PlayCount = reader[4].ToInt(); +// userData.IsFavorite = reader[5].ToBool(); +// userData.PlaybackPositionTicks = reader[6].ToInt64(); + +// if (reader[7].SQLiteType != SQLiteType.Null) +// { +// userData.LastPlayedDate = reader[7].ReadDateTime(); +// } + +// if (reader[8].SQLiteType != SQLiteType.Null) +// { +// userData.AudioStreamIndex = reader[8].ToInt(); +// } + +// if (reader[9].SQLiteType != SQLiteType.Null) +// { +// userData.SubtitleStreamIndex = reader[9].ToInt(); +// } + +// return userData; +// } + +// protected override void Dispose(bool dispose) +// { +// // handled by library database +// } + +// protected override void CloseConnection() +// { +// // handled by library database +// } +// } +//} \ No newline at end of file diff --git a/MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj b/MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj index bd21db6cc8..a0dc59cef6 100644 --- a/MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj +++ b/MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj @@ -230,6 +230,10 @@ PreserveNewest + + Designer + PreserveNewest + PreserveNewest Designer diff --git a/MediaBrowser.Server.Mono/SQLitePCLRaw.provider.sqlite3.dll.config b/MediaBrowser.Server.Mono/SQLitePCLRaw.provider.sqlite3.dll.config new file mode 100644 index 0000000000..83a6cd9f38 --- /dev/null +++ b/MediaBrowser.Server.Mono/SQLitePCLRaw.provider.sqlite3.dll.config @@ -0,0 +1,3 @@ + + + \ No newline at end of file