Skip to content

Commit bd53d6e

Browse files
committed
Merge pull request #1421 from daebo01:enum-serialize-fix-pr
Fix packet corruption issue when enum was not 4 bytes. Conflicts: src/MySqlConnector/MySqlParameter.cs
2 parents 2d44a00 + 9352d48 commit bd53d6e

File tree

3 files changed

+77
-2
lines changed

3 files changed

+77
-2
lines changed

tests/MySqlConnector.Tests/DummyEnum.cs

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,52 @@ internal enum DummyEnum
44
{
55
FirstValue,
66
SecondValue
7-
}
7+
}
8+
9+
internal enum DummyByteEnum : byte
10+
{
11+
FirstValue,
12+
SecondValue = 0x11,
13+
}
14+
15+
internal enum DummySByteEnum : sbyte
16+
{
17+
FirstValue,
18+
SecondValue = 0x11,
19+
}
20+
21+
internal enum DummyShortEnum : short
22+
{
23+
FirstValue,
24+
SecondValue = 0x1122,
25+
}
26+
27+
internal enum DummyUShortEnum : ushort
28+
{
29+
FirstValue,
30+
SecondValue = 0x1122,
31+
}
32+
33+
internal enum DummyIntEnum : int
34+
{
35+
FirstValue,
36+
SecondValue = 0x11223344,
37+
}
38+
39+
internal enum DummyUIntEnum : uint
40+
{
41+
FirstValue,
42+
SecondValue = 0x11223344,
43+
}
44+
45+
internal enum DummyLongEnum : long
46+
{
47+
FirstValue,
48+
SecondValue = 0x11223344_55667788,
49+
}
50+
51+
internal enum DummyULongEnum : ulong
52+
{
53+
FirstValue,
54+
SecondValue = 0x11223344_55667788,
55+
}

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;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" />
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;MySqlParameterAppendBinaryTests.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" />
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using MySqlConnector.Protocol.Serialization;
2+
3+
namespace MySqlConnector.Tests;
4+
5+
public class MySqlParameterAppendBinaryTests
6+
{
7+
[Theory]
8+
[InlineData(DummySByteEnum.SecondValue, MySqlDbType.Byte, new byte[] { 0x11 })]
9+
[InlineData(DummyByteEnum.SecondValue, MySqlDbType.UByte, new byte[] { 0x11 })]
10+
[InlineData(DummyShortEnum.SecondValue, MySqlDbType.Int16, new byte[] { 0x22, 0x11 })]
11+
[InlineData(DummyUShortEnum.SecondValue, MySqlDbType.UInt16, new byte[] { 0x22, 0x11 })]
12+
[InlineData(DummyIntEnum.SecondValue, MySqlDbType.Int32, new byte[] { 0x44, 0x33, 0x22, 0x11 })]
13+
[InlineData(DummyUIntEnum.SecondValue, MySqlDbType.UInt32, new byte[] { 0x44, 0x33, 0x22, 0x11 })]
14+
[InlineData(DummyEnum.SecondValue, MySqlDbType.Int32, new byte[] { 0x01, 0x00, 0x00, 0x00 })]
15+
[InlineData(DummyLongEnum.SecondValue, MySqlDbType.Int64, new byte[] { 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11 })]
16+
[InlineData(DummyULongEnum.SecondValue, MySqlDbType.UInt64, new byte[] { 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11 })]
17+
public void WriteBinaryEnumType(object value, MySqlDbType expectedMySqlDbType, byte[] expectedBinary)
18+
{
19+
var parameter = new MySqlParameter { Value = value };
20+
var writer = new ByteBufferWriter();
21+
parameter.AppendBinary(writer, StatementPreparerOptions.None);
22+
23+
Assert.Equal(parameter.MySqlDbType, expectedMySqlDbType);
24+
Assert.Equal(writer.Position, expectedBinary.Length);
25+
Assert.Equal(writer.ArraySegment, expectedBinary);
26+
}
27+
}

0 commit comments

Comments
 (0)