mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
simplify extension methods
This commit is contained in:
parent
fb511dbae2
commit
cf04b43fa4
@ -134,6 +134,7 @@ namespace Emby.Server.Implementations.Data
|
||||
|
||||
connection.Execute("PRAGMA temp_store=" + (int)TempStore);
|
||||
|
||||
connection.Open();
|
||||
return connection;
|
||||
}
|
||||
|
||||
|
@ -53,14 +53,6 @@ namespace Emby.Server.Implementations.Data
|
||||
"yy-MM-dd"
|
||||
};
|
||||
|
||||
private static void EnsureOpen(this SqliteConnection sqliteConnection)
|
||||
{
|
||||
if (sqliteConnection.State == ConnectionState.Closed)
|
||||
{
|
||||
sqliteConnection.Open();
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<SqliteDataReader> Query(this SqliteConnection sqliteConnection, string commandText)
|
||||
{
|
||||
if (sqliteConnection.State != ConnectionState.Open)
|
||||
@ -81,29 +73,11 @@ namespace Emby.Server.Implementations.Data
|
||||
|
||||
public static void Execute(this SqliteConnection sqliteConnection, string commandText)
|
||||
{
|
||||
sqliteConnection.EnsureOpen();
|
||||
using var command = sqliteConnection.CreateCommand();
|
||||
command.CommandText = commandText;
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
public static void ExecuteAll(this SqliteConnection sqliteConnection, string commandText)
|
||||
{
|
||||
sqliteConnection.EnsureOpen();
|
||||
|
||||
using var command = sqliteConnection.CreateCommand();
|
||||
command.CommandText = commandText;
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
public static void RunQueries(this SqliteConnection connection, string[] queries)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(queries);
|
||||
using var transaction = connection.BeginTransaction();
|
||||
connection.ExecuteAll(string.Join(';', queries));
|
||||
transaction.Commit();
|
||||
}
|
||||
|
||||
public static string ToDateTimeParamValue(this DateTime dateValue)
|
||||
{
|
||||
var kind = DateTimeKind.Utc;
|
||||
@ -239,6 +213,7 @@ namespace Emby.Server.Implementations.Data
|
||||
}
|
||||
else
|
||||
{
|
||||
// Blobs aren't always detected automatically
|
||||
if (isBlob)
|
||||
{
|
||||
statement.Parameters.Add(new SqliteParameter(name, SqliteType.Blob) { Value = value });
|
||||
@ -250,18 +225,6 @@ namespace Emby.Server.Implementations.Data
|
||||
}
|
||||
}
|
||||
|
||||
public static void TryBind(this SqliteCommand statement, string name, byte[] value)
|
||||
{
|
||||
if (statement.Parameters.Contains(name))
|
||||
{
|
||||
statement.Parameters[name].Value = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
statement.Parameters.Add(new SqliteParameter(name, SqliteType.Blob, value.Length) { Value = value });
|
||||
}
|
||||
}
|
||||
|
||||
public static void TryBindNull(this SqliteCommand statement, string name)
|
||||
{
|
||||
statement.TryBind(name, DBNull.Value);
|
||||
@ -286,7 +249,6 @@ namespace Emby.Server.Implementations.Data
|
||||
|
||||
public static SqliteCommand PrepareStatement(this SqliteConnection sqliteConnection, string sql)
|
||||
{
|
||||
sqliteConnection.EnsureOpen();
|
||||
var command = sqliteConnection.CreateCommand();
|
||||
command.CommandText = sql;
|
||||
return command;
|
||||
|
@ -437,11 +437,10 @@ namespace Emby.Server.Implementations.Data
|
||||
};
|
||||
|
||||
using (var connection = GetConnection())
|
||||
{
|
||||
connection.RunQueries(queries);
|
||||
|
||||
using (var transaction = connection.BeginTransaction())
|
||||
{
|
||||
connection.Execute(string.Join(';', queries));
|
||||
|
||||
var existingColumnNames = GetColumnNames(connection, "AncestorIds");
|
||||
AddColumn(connection, "AncestorIds", "AncestorIdText", "Text", existingColumnNames);
|
||||
|
||||
@ -555,10 +554,9 @@ namespace Emby.Server.Implementations.Data
|
||||
|
||||
AddColumn(connection, "MediaStreams", "IsHearingImpaired", "BIT", existingColumnNames);
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
connection.Execute(string.Join(';', postQueries));
|
||||
|
||||
connection.RunQueries(postQueries);
|
||||
transaction.Commit();
|
||||
}
|
||||
}
|
||||
|
||||
@ -674,7 +672,7 @@ namespace Emby.Server.Implementations.Data
|
||||
|
||||
if (TypeRequiresDeserialization(type))
|
||||
{
|
||||
saveItemStatement.TryBind("@data", JsonSerializer.SerializeToUtf8Bytes(item, type, _jsonOptions));
|
||||
saveItemStatement.TryBind("@data", JsonSerializer.SerializeToUtf8Bytes(item, type, _jsonOptions), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -4656,7 +4654,7 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
|
||||
""";
|
||||
using var connection = GetConnection();
|
||||
using var transaction = connection.BeginTransaction();
|
||||
connection.ExecuteAll(Statements);
|
||||
connection.Execute(Statements);
|
||||
transaction.Commit();
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ namespace Emby.Server.Implementations.Data
|
||||
|
||||
var users = userDatasTableExists ? null : _userManager.Users;
|
||||
using var transaction = connection.BeginTransaction();
|
||||
connection.ExecuteAll(string.Join(';', new[]
|
||||
connection.Execute(string.Join(';', new[]
|
||||
{
|
||||
"create table if not exists UserDatas (key nvarchar not null, userId INT not null, rating float null, played bit not null, playCount int not null, isFavorite bit not null, playbackPositionTicks bigint not null, lastPlayedDate datetime null, AudioStreamIndex INT, SubtitleStreamIndex INT)",
|
||||
|
||||
@ -80,7 +80,7 @@ namespace Emby.Server.Implementations.Data
|
||||
|
||||
ImportUserIds(connection, users);
|
||||
|
||||
connection.ExecuteAll("INSERT INTO UserDatas (key, userId, rating, played, playCount, isFavorite, playbackPositionTicks, lastPlayedDate, AudioStreamIndex, SubtitleStreamIndex) SELECT key, InternalUserId, rating, played, playCount, isFavorite, playbackPositionTicks, lastPlayedDate, AudioStreamIndex, SubtitleStreamIndex from userdata where InternalUserId not null");
|
||||
connection.Execute("INSERT INTO UserDatas (key, userId, rating, played, playCount, isFavorite, playbackPositionTicks, lastPlayedDate, AudioStreamIndex, SubtitleStreamIndex) SELECT key, InternalUserId, rating, played, playCount, isFavorite, playbackPositionTicks, lastPlayedDate, AudioStreamIndex, SubtitleStreamIndex from userdata where InternalUserId not null");
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user