Skip to content

Commit

Permalink
Handle missing metadata (#1399)
Browse files Browse the repository at this point in the history
Create ColumnCountPayload when metadata are missing.

Co-authored-by: Bradley Grainger <[email protected]>
  • Loading branch information
trejjam and bgrainger authored Nov 22, 2023
1 parent 061215a commit 4439754
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/MySqlConnector/Protocol/Payloads/ColumnCountPayload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static ColumnCountPayload Create(ReadOnlySpan<byte> span, bool supportsOp
{
var reader = new ByteArrayReader(span);
var columnCount = (int) reader.ReadLengthEncodedInteger();
var metadataFollows = !supportsOptionalMetadata || reader.ReadByte() == 1;
var metadataFollows = !supportsOptionalMetadata || reader.BytesRemaining == 0 || reader.ReadByte() == 1;
return new ColumnCountPayload(columnCount, metadataFollows);
}
}
21 changes: 21 additions & 0 deletions tests/MySqlConnector.Tests/ColumnCountPayloadTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using MySqlConnector.Protocol.Payloads;

namespace MySqlConnector.Tests;

public class ColumnCountPayloadTests
{
[Theory]
[InlineData(new byte[] { 1 }, false, 1, true)]
[InlineData(new byte[] { 1, 1 }, true, 1, true)]
[InlineData(new byte[] { 1, 0 }, true, 1, false)]
[InlineData(new byte[] { 2 }, false, 2, true)]
[InlineData(new byte[] { 2, 1 }, true, 2, true)]
[InlineData(new byte[] { 2, 0 }, true, 2, false)]
[InlineData(new byte[] { 2 }, true, 2, true)] // this seems like invalid data, but a server may return this
public void ParseResultSetHeader(byte[] span, bool supportsOptionalMetadata, int expectedColumnCount, bool expectedMetadataFollows)
{
var columnCountPayload = ColumnCountPayload.Create(span.AsSpan(), supportsOptionalMetadata);
Assert.Equal(expectedColumnCount, columnCountPayload.ColumnCount);
Assert.Equal(expectedMetadataFollows, columnCountPayload.MetadataFollows);
}
}
2 changes: 1 addition & 1 deletion tests/MySqlConnector.Tests/MySqlConnector.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

<ItemGroup Condition=" '$(Configuration)' == 'MySqlData' ">
<PackageReference Include="MySql.Data" />
<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" />
<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" />
<Compile Remove="Metrics\*.cs" />
<Using Include="MySql.Data.MySqlClient" />
<Using Include="MySql.Data.Types" />
Expand Down

0 comments on commit 4439754

Please sign in to comment.