Skip to content

Commit 4439754

Browse files
trejjambgrainger
andauthored
Handle missing metadata (#1399)
Create ColumnCountPayload when metadata are missing. Co-authored-by: Bradley Grainger <[email protected]>
1 parent 061215a commit 4439754

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

src/MySqlConnector/Protocol/Payloads/ColumnCountPayload.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static ColumnCountPayload Create(ReadOnlySpan<byte> span, bool supportsOp
2222
{
2323
var reader = new ByteArrayReader(span);
2424
var columnCount = (int) reader.ReadLengthEncodedInteger();
25-
var metadataFollows = !supportsOptionalMetadata || reader.ReadByte() == 1;
25+
var metadataFollows = !supportsOptionalMetadata || reader.BytesRemaining == 0 || reader.ReadByte() == 1;
2626
return new ColumnCountPayload(columnCount, metadataFollows);
2727
}
2828
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using MySqlConnector.Protocol.Payloads;
2+
3+
namespace MySqlConnector.Tests;
4+
5+
public class ColumnCountPayloadTests
6+
{
7+
[Theory]
8+
[InlineData(new byte[] { 1 }, false, 1, true)]
9+
[InlineData(new byte[] { 1, 1 }, true, 1, true)]
10+
[InlineData(new byte[] { 1, 0 }, true, 1, false)]
11+
[InlineData(new byte[] { 2 }, false, 2, true)]
12+
[InlineData(new byte[] { 2, 1 }, true, 2, true)]
13+
[InlineData(new byte[] { 2, 0 }, true, 2, false)]
14+
[InlineData(new byte[] { 2 }, true, 2, true)] // this seems like invalid data, but a server may return this
15+
public void ParseResultSetHeader(byte[] span, bool supportsOptionalMetadata, int expectedColumnCount, bool expectedMetadataFollows)
16+
{
17+
var columnCountPayload = ColumnCountPayload.Create(span.AsSpan(), supportsOptionalMetadata);
18+
Assert.Equal(expectedColumnCount, columnCountPayload.ColumnCount);
19+
Assert.Equal(expectedMetadataFollows, columnCountPayload.MetadataFollows);
20+
}
21+
}

tests/MySqlConnector.Tests/MySqlConnector.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747

4848
<ItemGroup Condition=" '$(Configuration)' == 'MySqlData' ">
4949
<PackageReference Include="MySql.Data" />
50-
<Compile Remove="ByteBufferWriterTests.cs;CachedProcedureTests.cs;CancellationTests.cs;ColumnReaderTests.cs;ConnectionTests.cs;FakeMySqlServer.cs;FakeMySqlServerConnection.cs;LoadBalancerTests.cs;MySqlDecimalTests.cs;MySqlExceptionTests.cs;MySqlParameterCollectionNameToIndexTests.cs;NormalizeTests.cs;ServerVersionTests.cs;StatementPreparerTests.cs;TypeMapperTests.cs;UtilityTests.cs" />
50+
<Compile Remove="ByteBufferWriterTests.cs;CachedProcedureTests.cs;CancellationTests.cs;ColumnCountPayloadTests.cs;ColumnReaderTests.cs;ConnectionTests.cs;FakeMySqlServer.cs;FakeMySqlServerConnection.cs;LoadBalancerTests.cs;MySqlDecimalTests.cs;MySqlExceptionTests.cs;MySqlParameterCollectionNameToIndexTests.cs;NormalizeTests.cs;ServerVersionTests.cs;StatementPreparerTests.cs;TypeMapperTests.cs;UtilityTests.cs" />
5151
<Compile Remove="Metrics\*.cs" />
5252
<Using Include="MySql.Data.MySqlClient" />
5353
<Using Include="MySql.Data.Types" />

0 commit comments

Comments
 (0)