mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
fix guid blobs
This commit is contained in:
parent
613f4296e3
commit
493229cc15
@ -264,17 +264,10 @@ namespace Emby.Server.Implementations.Data
|
|||||||
|
|
||||||
public static void TryBind(this SqliteCommand statement, string name, Guid value)
|
public static void TryBind(this SqliteCommand statement, string name, Guid value)
|
||||||
{
|
{
|
||||||
if (statement.Parameters.Contains(name))
|
statement.TryBind(name, value, true);
|
||||||
{
|
|
||||||
statement.Parameters[name].Value = value;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
statement.Parameters.Add(new SqliteParameter(name, SqliteType.Blob) { Value = value });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void TryBind(this SqliteCommand statement, string name, object? value)
|
public static void TryBind(this SqliteCommand statement, string name, object? value, bool isBlob = false)
|
||||||
{
|
{
|
||||||
var preparedValue = value ?? DBNull.Value;
|
var preparedValue = value ?? DBNull.Value;
|
||||||
if (statement.Parameters.Contains(name))
|
if (statement.Parameters.Contains(name))
|
||||||
@ -282,10 +275,17 @@ namespace Emby.Server.Implementations.Data
|
|||||||
statement.Parameters[name].Value = preparedValue;
|
statement.Parameters[name].Value = preparedValue;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
if (isBlob)
|
||||||
|
{
|
||||||
|
statement.Parameters.Add(new SqliteParameter(name, SqliteType.Blob) { Value = value });
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
statement.Parameters.AddWithValue(name, preparedValue);
|
statement.Parameters.AddWithValue(name, preparedValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void TryBind(this SqliteCommand statement, string name, byte[] value)
|
public static void TryBind(this SqliteCommand statement, string name, byte[] value)
|
||||||
{
|
{
|
||||||
|
@ -4891,11 +4891,6 @@ AND Type = @InternalPersonType)");
|
|||||||
|
|
||||||
CheckDisposed();
|
CheckDisposed();
|
||||||
|
|
||||||
// TODO how to handle span?
|
|
||||||
Span<byte> itemIdBlob2 = stackalloc byte[16];
|
|
||||||
itemId.TryWriteBytes(itemIdBlob2);
|
|
||||||
var itemIdBlob = Encoding.ASCII.GetBytes(itemId.ToString());
|
|
||||||
|
|
||||||
// First delete
|
// First delete
|
||||||
// TODO deleteAncestorsStatement.Parameters.Clear();
|
// TODO deleteAncestorsStatement.Parameters.Clear();
|
||||||
deleteAncestorsStatement.TryBind("@ItemId", itemId);
|
deleteAncestorsStatement.TryBind("@ItemId", itemId);
|
||||||
@ -4921,14 +4916,13 @@ AND Type = @InternalPersonType)");
|
|||||||
|
|
||||||
using (var statement = PrepareStatement(db, insertText.ToString()))
|
using (var statement = PrepareStatement(db, insertText.ToString()))
|
||||||
{
|
{
|
||||||
statement.TryBind("@ItemId", itemIdBlob);
|
statement.TryBind("@ItemId", itemId);
|
||||||
|
|
||||||
for (var i = 0; i < ancestorIds.Count; i++)
|
for (var i = 0; i < ancestorIds.Count; i++)
|
||||||
{
|
{
|
||||||
var index = i.ToString(CultureInfo.InvariantCulture);
|
var index = i.ToString(CultureInfo.InvariantCulture);
|
||||||
|
|
||||||
var ancestorId = ancestorIds[i];
|
var ancestorId = ancestorIds[i];
|
||||||
itemIdBlob = Encoding.ASCII.GetBytes(itemId.ToString());
|
|
||||||
|
|
||||||
statement.TryBind("@AncestorId" + index, ancestorId);
|
statement.TryBind("@AncestorId" + index, ancestorId);
|
||||||
statement.TryBind("@AncestorIdText" + index, ancestorId.ToString("N", CultureInfo.InvariantCulture));
|
statement.TryBind("@AncestorIdText" + index, ancestorId.ToString("N", CultureInfo.InvariantCulture));
|
||||||
@ -5416,17 +5410,15 @@ AND Type = @InternalPersonType)");
|
|||||||
|
|
||||||
CheckDisposed();
|
CheckDisposed();
|
||||||
|
|
||||||
var guidBlob = itemId.ToByteArray();
|
|
||||||
|
|
||||||
// First delete
|
// First delete
|
||||||
using var command = db.PrepareStatement("delete from ItemValues where ItemId=@Id");
|
using var command = db.PrepareStatement("delete from ItemValues where ItemId=@Id");
|
||||||
command.TryBind("@Id", guidBlob);
|
command.TryBind("@Id", itemId);
|
||||||
command.ExecuteNonQuery();
|
command.ExecuteNonQuery();
|
||||||
|
|
||||||
InsertItemValues(guidBlob, values, db);
|
InsertItemValues(itemId, values, db);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InsertItemValues(byte[] idBlob, List<(int MagicNumber, string Value)> values, SqliteConnection db)
|
private void InsertItemValues(Guid id, List<(int MagicNumber, string Value)> values, SqliteConnection db)
|
||||||
{
|
{
|
||||||
const int Limit = 100;
|
const int Limit = 100;
|
||||||
var startIndex = 0;
|
var startIndex = 0;
|
||||||
@ -5450,7 +5442,7 @@ AND Type = @InternalPersonType)");
|
|||||||
|
|
||||||
using (var statement = PrepareStatement(db, insertText.ToString()))
|
using (var statement = PrepareStatement(db, insertText.ToString()))
|
||||||
{
|
{
|
||||||
statement.TryBind("@ItemId", idBlob);
|
statement.TryBind("@ItemId", id);
|
||||||
|
|
||||||
for (var i = startIndex; i < endIndex; i++)
|
for (var i = startIndex; i < endIndex; i++)
|
||||||
{
|
{
|
||||||
@ -5496,20 +5488,18 @@ AND Type = @InternalPersonType)");
|
|||||||
connection.RunInTransaction(
|
connection.RunInTransaction(
|
||||||
db =>
|
db =>
|
||||||
{
|
{
|
||||||
var itemIdBlob = itemId.ToByteArray();
|
|
||||||
|
|
||||||
// First delete chapters
|
// First delete chapters
|
||||||
using var command = db.CreateCommand();
|
using var command = db.CreateCommand();
|
||||||
command.CommandText = "delete from People where ItemId=@ItemId";
|
command.CommandText = "delete from People where ItemId=@ItemId";
|
||||||
command.TryBind("@ItemId", itemIdBlob);
|
command.TryBind("@ItemId", itemId);
|
||||||
command.ExecuteNonQuery();
|
command.ExecuteNonQuery();
|
||||||
|
|
||||||
InsertPeople(itemIdBlob, people, db);
|
InsertPeople(itemId, people, db);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InsertPeople(byte[] idBlob, List<PersonInfo> people, SqliteConnection db)
|
private void InsertPeople(Guid id, List<PersonInfo> people, SqliteConnection db)
|
||||||
{
|
{
|
||||||
const int Limit = 100;
|
const int Limit = 100;
|
||||||
var startIndex = 0;
|
var startIndex = 0;
|
||||||
@ -5533,7 +5523,7 @@ AND Type = @InternalPersonType)");
|
|||||||
|
|
||||||
using (var statement = PrepareStatement(db, insertText.ToString()))
|
using (var statement = PrepareStatement(db, insertText.ToString()))
|
||||||
{
|
{
|
||||||
statement.TryBind("@ItemId", idBlob);
|
statement.TryBind("@ItemId", id);
|
||||||
|
|
||||||
for (var i = startIndex; i < endIndex; i++)
|
for (var i = startIndex; i < endIndex; i++)
|
||||||
{
|
{
|
||||||
@ -5651,19 +5641,17 @@ AND Type = @InternalPersonType)");
|
|||||||
connection.RunInTransaction(
|
connection.RunInTransaction(
|
||||||
db =>
|
db =>
|
||||||
{
|
{
|
||||||
var itemIdBlob = id.ToByteArray();
|
|
||||||
|
|
||||||
// Delete existing mediastreams
|
// Delete existing mediastreams
|
||||||
using var command = db.PrepareStatement("delete from mediastreams where ItemId=@ItemId");
|
using var command = db.PrepareStatement("delete from mediastreams where ItemId=@ItemId");
|
||||||
command.TryBind("@ItemId", itemIdBlob);
|
command.TryBind("@ItemId", id);
|
||||||
command.ExecuteNonQuery();
|
command.ExecuteNonQuery();
|
||||||
|
|
||||||
InsertMediaStreams(itemIdBlob, streams, db);
|
InsertMediaStreams(id, streams, db);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InsertMediaStreams(byte[] idBlob, IReadOnlyList<MediaStream> streams, SqliteConnection db)
|
private void InsertMediaStreams(Guid id, IReadOnlyList<MediaStream> streams, SqliteConnection db)
|
||||||
{
|
{
|
||||||
const int Limit = 10;
|
const int Limit = 10;
|
||||||
var startIndex = 0;
|
var startIndex = 0;
|
||||||
@ -5695,7 +5683,7 @@ AND Type = @InternalPersonType)");
|
|||||||
|
|
||||||
using (var statement = PrepareStatement(db, insertText.ToString()))
|
using (var statement = PrepareStatement(db, insertText.ToString()))
|
||||||
{
|
{
|
||||||
statement.TryBind("@ItemId", idBlob);
|
statement.TryBind("@ItemId", id);
|
||||||
|
|
||||||
for (var i = startIndex; i < endIndex; i++)
|
for (var i = startIndex; i < endIndex; i++)
|
||||||
{
|
{
|
||||||
@ -5731,6 +5719,7 @@ AND Type = @InternalPersonType)");
|
|||||||
|
|
||||||
statement.TryBind("@PixelFormat" + index, stream.PixelFormat);
|
statement.TryBind("@PixelFormat" + index, stream.PixelFormat);
|
||||||
statement.TryBind("@BitDepth" + index, stream.BitDepth);
|
statement.TryBind("@BitDepth" + index, stream.BitDepth);
|
||||||
|
statement.TryBind("@IsAnamorphic" + index, stream.IsAnamorphic);
|
||||||
statement.TryBind("@IsExternal" + index, stream.IsExternal);
|
statement.TryBind("@IsExternal" + index, stream.IsExternal);
|
||||||
statement.TryBind("@RefFrames" + index, stream.RefFrames);
|
statement.TryBind("@RefFrames" + index, stream.RefFrames);
|
||||||
|
|
||||||
@ -6000,7 +5989,7 @@ AND Type = @InternalPersonType)");
|
|||||||
using (var connection = GetConnection(true))
|
using (var connection = GetConnection(true))
|
||||||
using (var statement = PrepareStatement(connection, cmdText))
|
using (var statement = PrepareStatement(connection, cmdText))
|
||||||
{
|
{
|
||||||
statement.TryBind("@ItemId", query.ItemId.ToByteArray());
|
statement.TryBind("@ItemId", query.ItemId);
|
||||||
|
|
||||||
if (query.Index.HasValue)
|
if (query.Index.HasValue)
|
||||||
{
|
{
|
||||||
@ -6036,19 +6025,17 @@ AND Type = @InternalPersonType)");
|
|||||||
connection.RunInTransaction(
|
connection.RunInTransaction(
|
||||||
db =>
|
db =>
|
||||||
{
|
{
|
||||||
var itemIdBlob = id.ToByteArray();
|
|
||||||
|
|
||||||
using var command = db.PrepareStatement("delete from mediaattachments where ItemId=@ItemId");
|
using var command = db.PrepareStatement("delete from mediaattachments where ItemId=@ItemId");
|
||||||
command.TryBind("@ItemId", itemIdBlob);
|
command.TryBind("@ItemId", id);
|
||||||
command.ExecuteNonQuery();
|
command.ExecuteNonQuery();
|
||||||
|
|
||||||
InsertMediaAttachments(itemIdBlob, attachments, db, cancellationToken);
|
InsertMediaAttachments(id, attachments, db, cancellationToken);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InsertMediaAttachments(
|
private void InsertMediaAttachments(
|
||||||
byte[] idBlob,
|
Guid id,
|
||||||
IReadOnlyList<MediaAttachment> attachments,
|
IReadOnlyList<MediaAttachment> attachments,
|
||||||
SqliteConnection db,
|
SqliteConnection db,
|
||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
@ -6084,7 +6071,7 @@ AND Type = @InternalPersonType)");
|
|||||||
|
|
||||||
using (var statement = PrepareStatement(db, insertText.ToString()))
|
using (var statement = PrepareStatement(db, insertText.ToString()))
|
||||||
{
|
{
|
||||||
statement.TryBind("@ItemId", idBlob);
|
statement.TryBind("@ItemId", id);
|
||||||
|
|
||||||
for (var i = startIndex; i < endIndex; i++)
|
for (var i = startIndex; i < endIndex; i++)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user