Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions Npgsql/NpgsqlTypes/ArrayHandling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,15 +282,10 @@ private void WriteBinaryArrayData(NpgsqlNativeTypeInfo TypeInfo, Array nativeDat

private bool WriteEnumeration(NpgsqlNativeTypeInfo TypeInfo, IEnumerable col, MemoryStream array, Boolean forExtendedQuery, NativeToBackendTypeConverterOptions options)
{
// As this prcedure handles both prepared and plain query representations, in order to not keep if's inside the loops
// we simply set a placeholder here for both openElement ( '{' or '[' ) and closeElement ( '}', or ']' )
byte openElement = (byte)(forExtendedQuery ? ASCIIBytes.BraceCurlyLeft : ASCIIBytes.BraceSquareLeft);
byte closeElement = (byte)(forExtendedQuery ? ASCIIBytes.BraceCurlyRight : ASCIIBytes.BraceSquareRight);

bool writtenSomething = false;
bool firstItem = true;

array.WriteByte(openElement);
array.WriteByte((byte)ASCIIBytes.BraceCurlyLeft);

//write each item with a comma between them.
foreach (object item in col)
Expand All @@ -309,7 +304,7 @@ private bool WriteEnumeration(NpgsqlNativeTypeInfo TypeInfo, IEnumerable col, Me

if (writtenSomething)
{
array.WriteByte(closeElement);
array.WriteByte((byte)ASCIIBytes.BraceCurlyRight);

}

Expand Down
15 changes: 15 additions & 0 deletions tests/CommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

using System;
using System.Diagnostics;
using System.Linq;
using Npgsql;
using NUnit.Framework;
using System.Data;
Expand Down Expand Up @@ -3700,5 +3701,19 @@ public void TestCommentInQuery03()
Assert.AreEqual(1, command.ExecuteScalar());
}
}

[Test]
public void TestIEnumerableAsArray()
{
using (var command = new NpgsqlCommand("SELECT :array", Conn))
{
var expected = new[] { 1, 2, 3, 4 };
command.Parameters.AddWithValue("array", expected.Select(x => x));
var res = command.ExecuteScalar() as int[];

Assert.NotNull(res);
CollectionAssert.AreEqual(expected, res);
}
}
}
}