From 613f4296e395b0442984e472a996eaadc07915fe Mon Sep 17 00:00:00 2001 From: cvium Date: Mon, 21 Aug 2023 12:13:32 +0200 Subject: loading works --- .../Data/BaseSqliteRepository.cs | 104 +++------------------ 1 file changed, 11 insertions(+), 93 deletions(-) (limited to 'Emby.Server.Implementations/Data/BaseSqliteRepository.cs') diff --git a/Emby.Server.Implementations/Data/BaseSqliteRepository.cs b/Emby.Server.Implementations/Data/BaseSqliteRepository.cs index d05534ee7..2ce87f5b4 100644 --- a/Emby.Server.Implementations/Data/BaseSqliteRepository.cs +++ b/Emby.Server.Implementations/Data/BaseSqliteRepository.cs @@ -5,8 +5,8 @@ using System; using System.Collections.Generic; using Jellyfin.Extensions; +using Microsoft.Data.Sqlite; using Microsoft.Extensions.Logging; -using SQLitePCL.pretty; namespace Emby.Server.Implementations.Data { @@ -45,24 +45,6 @@ namespace Emby.Server.Implementations.Data /// The logger. protected ILogger Logger { get; } - /// - /// Gets the default connection flags. - /// - /// The default connection flags. - protected virtual ConnectionFlags DefaultConnectionFlags => ConnectionFlags.NoMutex; - - /// - /// Gets the transaction mode. - /// - /// The transaction mode.> - protected TransactionMode TransactionMode => TransactionMode.Deferred; - - /// - /// Gets the transaction mode for read-only operations. - /// - /// The transaction mode. - protected TransactionMode ReadTransactionMode => TransactionMode.Deferred; - /// /// Gets the cache size. /// @@ -107,23 +89,8 @@ namespace Emby.Server.Implementations.Data /// protected virtual SynchronousMode? Synchronous => SynchronousMode.Normal; - /// - /// Gets or sets the write lock. - /// - /// The write lock. - protected ConnectionPool WriteConnections { get; set; } - - /// - /// Gets or sets the write connection. - /// - /// The write connection. - protected ConnectionPool ReadConnections { get; set; } - public virtual void Initialize() { - WriteConnections = new ConnectionPool(WriteConnectionsCount, CreateWriteConnection); - ReadConnections = new ConnectionPool(ReadConnectionsCount, CreateReadConnection); - // Configuration and pragmas can affect VACUUM so it needs to be last. using (var connection = GetConnection()) { @@ -131,15 +98,9 @@ namespace Emby.Server.Implementations.Data } } - protected ManagedConnection GetConnection(bool readOnly = false) - => readOnly ? ReadConnections.GetConnection() : WriteConnections.GetConnection(); - - protected SQLiteDatabaseConnection CreateWriteConnection() + protected SqliteConnection GetConnection(bool readOnly = false) { - var writeConnection = SQLite3.Open( - DbFilePath, - DefaultConnectionFlags | ConnectionFlags.Create | ConnectionFlags.ReadWrite, - null); + var writeConnection = new SqliteConnection($"Filename={DbFilePath}"); if (CacheSize.HasValue) { @@ -176,50 +137,14 @@ namespace Emby.Server.Implementations.Data return writeConnection; } - protected SQLiteDatabaseConnection CreateReadConnection() + public SqliteCommand PrepareStatement(SqliteConnection connection, string sql) { - var connection = SQLite3.Open( - DbFilePath, - DefaultConnectionFlags | ConnectionFlags.ReadOnly, - null); - - if (CacheSize.HasValue) - { - connection.Execute("PRAGMA cache_size=" + CacheSize.Value); - } - - if (!string.IsNullOrWhiteSpace(LockingMode)) - { - connection.Execute("PRAGMA locking_mode=" + LockingMode); - } - - if (!string.IsNullOrWhiteSpace(JournalMode)) - { - connection.Execute("PRAGMA journal_mode=" + JournalMode); - } - - if (JournalSizeLimit.HasValue) - { - connection.Execute("PRAGMA journal_size_limit=" + JournalSizeLimit.Value); - } - - if (Synchronous.HasValue) - { - connection.Execute("PRAGMA synchronous=" + (int)Synchronous.Value); - } - - connection.Execute("PRAGMA temp_store=" + (int)TempStore); - - return connection; + var command = connection.CreateCommand(); + command.CommandText = sql; + return command; } - public IStatement PrepareStatement(ManagedConnection connection, string sql) - => connection.PrepareStatement(sql); - - public IStatement PrepareStatement(IDatabaseConnection connection, string sql) - => connection.PrepareStatement(sql); - - protected bool TableExists(ManagedConnection connection, string name) + protected bool TableExists(SqliteConnection connection, string name) { return connection.RunInTransaction( db => @@ -236,11 +161,10 @@ namespace Emby.Server.Implementations.Data } return false; - }, - ReadTransactionMode); + }); } - protected List GetColumnNames(IDatabaseConnection connection, string table) + protected List GetColumnNames(SqliteConnection connection, string table) { var columnNames = new List(); @@ -255,7 +179,7 @@ namespace Emby.Server.Implementations.Data return columnNames; } - protected void AddColumn(IDatabaseConnection connection, string table, string columnName, string type, List existingColumnNames) + protected void AddColumn(SqliteConnection connection, string table, string columnName, string type, List existingColumnNames) { if (existingColumnNames.Contains(columnName, StringComparison.OrdinalIgnoreCase)) { @@ -291,12 +215,6 @@ namespace Emby.Server.Implementations.Data return; } - if (dispose) - { - WriteConnections.Dispose(); - ReadConnections.Dispose(); - } - _disposed = true; } } -- cgit v1.2.3