aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/Data/BaseSqliteRepository.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Emby.Server.Implementations/Data/BaseSqliteRepository.cs')
-rw-r--r--Emby.Server.Implementations/Data/BaseSqliteRepository.cs141
1 files changed, 27 insertions, 114 deletions
diff --git a/Emby.Server.Implementations/Data/BaseSqliteRepository.cs b/Emby.Server.Implementations/Data/BaseSqliteRepository.cs
index d05534ee7..bf079d90c 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
{
@@ -46,24 +46,6 @@ namespace Emby.Server.Implementations.Data
protected ILogger<BaseSqliteRepository> Logger { get; }
/// <summary>
- /// Gets the default connection flags.
- /// </summary>
- /// <value>The default connection flags.</value>
- protected virtual ConnectionFlags DefaultConnectionFlags => ConnectionFlags.NoMutex;
-
- /// <summary>
- /// Gets the transaction mode.
- /// </summary>
- /// <value>The transaction mode.</value>>
- protected TransactionMode TransactionMode => TransactionMode.Deferred;
-
- /// <summary>
- /// Gets the transaction mode for read-only operations.
- /// </summary>
- /// <value>The transaction mode.</value>
- protected TransactionMode ReadTransactionMode => TransactionMode.Deferred;
-
- /// <summary>
/// Gets the cache size.
/// </summary>
/// <value>The cache size or null.</value>
@@ -107,23 +89,8 @@ namespace Emby.Server.Implementations.Data
/// <see cref="SynchronousMode"/>
protected virtual SynchronousMode? Synchronous => SynchronousMode.Normal;
- /// <summary>
- /// Gets or sets the write lock.
- /// </summary>
- /// <value>The write lock.</value>
- protected ConnectionPool WriteConnections { get; set; }
-
- /// <summary>
- /// Gets or sets the write connection.
- /// </summary>
- /// <value>The write connection.</value>
- 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,57 +98,10 @@ namespace Emby.Server.Implementations.Data
}
}
- protected ManagedConnection GetConnection(bool readOnly = false)
- => readOnly ? ReadConnections.GetConnection() : WriteConnections.GetConnection();
-
- protected SQLiteDatabaseConnection CreateWriteConnection()
- {
- var writeConnection = SQLite3.Open(
- DbFilePath,
- DefaultConnectionFlags | ConnectionFlags.Create | ConnectionFlags.ReadWrite,
- null);
-
- if (CacheSize.HasValue)
- {
- writeConnection.Execute("PRAGMA cache_size=" + CacheSize.Value);
- }
-
- if (!string.IsNullOrWhiteSpace(LockingMode))
- {
- writeConnection.Execute("PRAGMA locking_mode=" + LockingMode);
- }
-
- if (!string.IsNullOrWhiteSpace(JournalMode))
- {
- writeConnection.Execute("PRAGMA journal_mode=" + JournalMode);
- }
-
- if (JournalSizeLimit.HasValue)
- {
- writeConnection.Execute("PRAGMA journal_size_limit=" + JournalSizeLimit.Value);
- }
-
- if (Synchronous.HasValue)
- {
- writeConnection.Execute("PRAGMA synchronous=" + (int)Synchronous.Value);
- }
-
- if (PageSize.HasValue)
- {
- writeConnection.Execute("PRAGMA page_size=" + PageSize.Value);
- }
-
- writeConnection.Execute("PRAGMA temp_store=" + (int)TempStore);
-
- return writeConnection;
- }
-
- protected SQLiteDatabaseConnection CreateReadConnection()
+ protected SqliteConnection GetConnection()
{
- var connection = SQLite3.Open(
- DbFilePath,
- DefaultConnectionFlags | ConnectionFlags.ReadOnly,
- null);
+ var connection = new SqliteConnection($"Filename={DbFilePath}");
+ connection.Open();
if (CacheSize.HasValue)
{
@@ -208,39 +128,38 @@ namespace Emby.Server.Implementations.Data
connection.Execute("PRAGMA synchronous=" + (int)Synchronous.Value);
}
+ if (PageSize.HasValue)
+ {
+ connection.Execute("PRAGMA page_size=" + PageSize.Value);
+ }
+
connection.Execute("PRAGMA temp_store=" + (int)TempStore);
return connection;
}
- public IStatement PrepareStatement(ManagedConnection connection, string sql)
- => connection.PrepareStatement(sql);
-
- public IStatement PrepareStatement(IDatabaseConnection connection, string sql)
- => connection.PrepareStatement(sql);
+ public SqliteCommand PrepareStatement(SqliteConnection connection, string sql)
+ {
+ var command = connection.CreateCommand();
+ command.CommandText = sql;
+ return command;
+ }
- protected bool TableExists(ManagedConnection connection, string name)
+ protected bool TableExists(SqliteConnection connection, string name)
{
- return connection.RunInTransaction(
- db =>
+ using var statement = PrepareStatement(connection, "select DISTINCT tbl_name from sqlite_master");
+ foreach (var row in statement.ExecuteQuery())
+ {
+ if (string.Equals(name, row.GetString(0), StringComparison.OrdinalIgnoreCase))
{
- using (var statement = PrepareStatement(db, "select DISTINCT tbl_name from sqlite_master"))
- {
- foreach (var row in statement.ExecuteQuery())
- {
- if (string.Equals(name, row.GetString(0), StringComparison.OrdinalIgnoreCase))
- {
- return true;
- }
- }
- }
-
- return false;
- },
- ReadTransactionMode);
+ return true;
+ }
+ }
+
+ return false;
}
- protected List<string> GetColumnNames(IDatabaseConnection connection, string table)
+ protected List<string> GetColumnNames(SqliteConnection connection, string table)
{
var columnNames = new List<string>();
@@ -255,7 +174,7 @@ namespace Emby.Server.Implementations.Data
return columnNames;
}
- protected void AddColumn(IDatabaseConnection connection, string table, string columnName, string type, List<string> existingColumnNames)
+ protected void AddColumn(SqliteConnection connection, string table, string columnName, string type, List<string> existingColumnNames)
{
if (existingColumnNames.Contains(columnName, StringComparison.OrdinalIgnoreCase))
{
@@ -291,12 +210,6 @@ namespace Emby.Server.Implementations.Data
return;
}
- if (dispose)
- {
- WriteConnections.Dispose();
- ReadConnections.Dispose();
- }
-
_disposed = true;
}
}