Skip to content
Permalink
Browse files

Fixed handling of array segments without arrays

  • Loading branch information...
YohDeadfall committed Aug 7, 2019
1 parent b7bc6ba commit b559c8ed627db6940336ba9178c64fec911f287d
Showing with 4 additions and 4 deletions.
  1. +1 −1 src/Npgsql/TypeHandlers/ByteaHandler.cs
  2. +3 −3 src/Npgsql/TypeHandlers/TextHandler.cs
@@ -76,7 +76,7 @@ public override Task Write(byte[] value, NpgsqlWriteBuffer buf, NpgsqlLengthCach

/// <inheritdoc />
public Task Write(ArraySegment<byte> value, NpgsqlWriteBuffer buf, NpgsqlLengthCache? lengthCache, NpgsqlParameter? parameter, bool async)
=> Write(value.Array, buf, value.Offset, ValidateAndGetLength(value.Count, parameter), async);
=> value.Array is null ? Task.CompletedTask : Write(value.Array, buf, value.Offset, ValidateAndGetLength(value.Count, parameter), async);

async Task Write(byte[] value, NpgsqlWriteBuffer buf, int offset, int count, bool async)
{
@@ -231,7 +231,7 @@ public virtual int ValidateAndGetLength(ArraySegment<char> value, ref NpgsqlLeng
if (parameter?.Size > 0)
throw new ArgumentException($"Parameter {parameter.ParameterName} is of type ArraySegment<char> and should not have its Size set", parameter.ParameterName);

return lengthCache.Set(_encoding.GetByteCount(value.Array, value.Offset, value.Count));
return lengthCache.Set(value.Array is null ? 0 : _encoding.GetByteCount(value.Array, value.Offset, value.Count));
}

public int ValidateAndGetLength(char value, ref NpgsqlLengthCache? lengthCache, NpgsqlParameter? parameter)
@@ -254,8 +254,8 @@ public virtual Task Write(char[] value, NpgsqlWriteBuffer buf, NpgsqlLengthCache
return buf.WriteChars(value, 0, charLen, lengthCache!.GetLast(), async);
}

public virtual Task Write(ArraySegment<char> value, NpgsqlWriteBuffer buf, NpgsqlLengthCache? lengthCache, NpgsqlParameter? parameter, bool async) =>
buf.WriteChars(value.Array, value.Offset, value.Count, lengthCache!.GetLast(), async);
public virtual Task Write(ArraySegment<char> value, NpgsqlWriteBuffer buf, NpgsqlLengthCache? lengthCache, NpgsqlParameter? parameter, bool async)
=> value.Array is null ? Task.CompletedTask : buf.WriteChars(value.Array, value.Offset, value.Count, lengthCache!.GetLast(), async);

Task WriteString(string str, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter? parameter, bool async)
{

0 comments on commit b559c8e

Please sign in to comment.
You can’t perform that action at this time.