Skip to content

Commit 65b62c5

Browse files
committed
Test all data types with GetSchemaTable.
* Use unit to represent column length internally; clamp to int.MaxValue. * Fix `IsLong` for columns > 2GB. * Work around Connector/NET bugs in tests.
1 parent fea73f0 commit 65b62c5

File tree

3 files changed

+50
-6
lines changed

3 files changed

+50
-6
lines changed

src/MySqlConnector/MySqlClient/MySqlDataReader.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,12 @@ internal DataTable BuildSchemaTable()
345345
var schemaRow = schemaTable.NewRow();
346346
schemaRow[columnName] = col.Name;
347347
schemaRow[ordinal] = i;
348-
schemaRow[dataType] = GetFieldType(i);
349-
schemaRow[size] = (Type)schemaRow[dataType] == typeof(string) || (Type)schemaRow[dataType] == typeof(Guid) ?
348+
var fieldType = GetFieldType(i);
349+
schemaRow[dataType] = fieldType;
350+
var columnSize = fieldType == typeof(string) || fieldType == typeof(Guid) ?
350351
col.ColumnLength / SerializationUtility.GetBytesPerCharacter(col.CharacterSet) :
351352
col.ColumnLength;
353+
schemaRow[size] = columnSize > int.MaxValue ? int.MaxValue : unchecked((int) columnSize);
352354
schemaRow[providerType] = col.ColumnType;
353355
schemaRow[isLong] = col.ColumnLength > 255 && ((col.ColumnFlags & ColumnFlags.Blob) != 0 || col.ColumnType.IsBlob());
354356
schemaRow[isKey] = (col.ColumnFlags & ColumnFlags.PrimaryKey) != 0;

src/MySqlConnector/Serialization/ColumnDefinitionPayload.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ internal class ColumnDefinitionPayload
99

1010
public CharacterSet CharacterSet { get; private set; }
1111

12-
public int ColumnLength { get; private set; }
12+
public uint ColumnLength { get; private set; }
1313

1414
public ColumnType ColumnType { get; private set; }
1515

@@ -38,7 +38,7 @@ public static ColumnDefinitionPayload Create(PayloadData payload)
3838
var physicalName = Encoding.UTF8.GetString(reader.ReadLengthEncodedByteString());
3939
reader.ReadByte(0x0C); // length of fixed-length fields, always 0x0C
4040
var characterSet = (CharacterSet) reader.ReadUInt16();
41-
var columnLength = (int) reader.ReadUInt32();
41+
var columnLength = reader.ReadUInt32();
4242
var columnType = (ColumnType) reader.ReadByte();
4343
var columnFlags = (ColumnFlags) reader.ReadUInt16();
4444
var decimals = reader.ReadByte(); // 0x00 for integers and static strings, 0x1f for dynamic strings, double, float, 0x00 to 0x51 for decimals

tests/SideBySide/DataTypes.cs

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,21 +600,59 @@ public void InsertLargeBlobSync(string column, int size)
600600

601601
#if !NETCOREAPP1_1_2
602602
[Theory]
603+
[InlineData("Bit1", "datatypes_bits", 1, typeof(ulong), false, false, true, 0, 0)]
604+
[InlineData("Bit32", "datatypes_bits", 32, typeof(ulong), false, false, true, 0, 0)]
605+
[InlineData("Bit64", "datatypes_bits", 64, typeof(ulong), false, false, true, 0, 0)]
606+
[InlineData("Binary", "datatypes_blobs", 100, typeof(byte[]), false, false, true, 0, 0)]
607+
[InlineData("VarBinary", "datatypes_blobs", 100, typeof(byte[]), false, false, true, 0, 0)]
608+
[InlineData("TinyBlob", "datatypes_blobs", 255, typeof(byte[]), false, false, true, 0, 0)]
609+
[InlineData("Blob", "datatypes_blobs", 65535, typeof(byte[]), true, false, true, 0, 0)]
610+
[InlineData("MediumBlob", "datatypes_blobs", 16777215, typeof(byte[]), true, false, true, 0, 0)]
611+
[InlineData("LongBlob", "datatypes_blobs", int.MaxValue, typeof(byte[]), true, false, true, 0, 0)]
612+
[InlineData("guidbin", "datatypes_blobs", 16, typeof(byte[]), false, false, true, 0, 0)]
603613
[InlineData("rowid", "datatypes_bools", 11, typeof(int), false, true, false, 0, 0)]
604614
[InlineData("Boolean", "datatypes_bools", 1, typeof(bool), false, false, true, 0, 0)]
615+
[InlineData("TinyInt1", "datatypes_bools", 1, typeof(bool), false, false, true, 0, 0)]
616+
[InlineData("size", "datatypes_enums", 7, typeof(string), false, false, true, 0, 0)]
617+
[InlineData("color", "datatypes_enums", 6, typeof(string), false, false, false, 0, 0)]
618+
[InlineData("char38", "datatypes_guids", 38, typeof(string), false, false, true, 0, 0)]
619+
[InlineData("char38bin", "datatypes_guids", 38, typeof(string), false, false, true, 0, 0)]
620+
[InlineData("text", "datatypes_guids", 65535, typeof(string), true, false, true, 0, 0)]
621+
[InlineData("blob", "datatypes_guids", 65535, typeof(byte[]), true, false, true, 0, 0)]
605622
[InlineData("SByte", "datatypes_integers", 4, typeof(sbyte), false, false, true, 0, 0)]
623+
[InlineData("Byte", "datatypes_integers", 3, typeof(byte), false, false, true, 0, 0)]
606624
[InlineData("Int16", "datatypes_integers", 6, typeof(short), false, false, true, 0, 0)]
607625
[InlineData("UInt16", "datatypes_integers", 5, typeof(ushort), false, false, true, 0, 0)]
626+
[InlineData("Int24", "datatypes_integers", 9, typeof(int), false, false, true, 0, 0)]
627+
[InlineData("UInt24", "datatypes_integers", 8, typeof(uint), false, false, true, 0, 0)]
628+
[InlineData("Int32", "datatypes_integers", 11, typeof(int), false, false, true, 0, 0)]
629+
[InlineData("UInt32", "datatypes_integers", 10, typeof(uint), false, false, true, 0, 0)]
630+
[InlineData("Int64", "datatypes_integers", 20, typeof(long), false, false, true, 0, 0)]
631+
[InlineData("UInt64", "datatypes_integers", 20, typeof(ulong), false, false, true, 0, 0)]
632+
[InlineData("value", "datatypes_json_core", int.MaxValue, typeof(string), true, false, true, 0, 0)]
633+
[InlineData("Single", "datatypes_reals", 12, typeof(float), false, false, true, 0, 31)]
608634
[InlineData("Double", "datatypes_reals", 22, typeof(double), false, false, true, 0, 31)]
635+
[InlineData("SmallDecimal", "datatypes_reals", 7, typeof(decimal), false, false, true, 5, 2)]
609636
[InlineData("MediumDecimal", "datatypes_reals", 30, typeof(decimal), false, false, true, 28, 8)]
637+
[InlineData("BigDecimal", "datatypes_reals", 52, typeof(decimal), false, false, true, 50, 30)]
638+
[InlineData("value", "datatypes_set", 12, typeof(string), false, false, true, 0, 0)]
610639
[InlineData("utf8", "datatypes_strings", 300, typeof(string), false, false, true, 0, 0)]
640+
[InlineData("utf8bin", "datatypes_strings", 300, typeof(string), false, false, true, 0, 0)]
641+
[InlineData("latin1", "datatypes_strings", 300, typeof(string), false, false, true, 0, 0)]
642+
[InlineData("latin1bin", "datatypes_strings", 300, typeof(string), false, false, true, 0, 0)]
643+
[InlineData("cp1251", "datatypes_strings", 300, typeof(string), false, false, true, 0, 0)]
611644
[InlineData("guid", "datatypes_strings", 36, typeof(Guid), false, false, true, 0, 0)]
612645
[InlineData("guidbin", "datatypes_strings", 36, typeof(Guid), false, false, true, 0, 0)]
613-
[InlineData("Blob", "datatypes_blobs", 65535, typeof(byte[]), true, false, true, 0, 0)]
614646
[InlineData("Date", "datatypes_times", 10, typeof(DateTime), false, false, true, 0, 0)]
647+
[InlineData("DateTime", "datatypes_times", 26, typeof(DateTime), false, false, true, 0, 6)]
648+
[InlineData("Timestamp", "datatypes_times", 26, typeof(DateTime), false, false, true, 0, 6)]
615649
[InlineData("Time", "datatypes_times", 17, typeof(TimeSpan), false, false, true, 0, 6)]
650+
[InlineData("Year", "datatypes_times", 4, typeof(int), false, false, true, 0, 0)]
616651
public void GetSchemaTable(string column, string table, int columnSize, Type dataType, bool isLong, bool isKey, bool allowDbNull, int precision, int scale)
617652
{
653+
if (table == "datatypes_json_core" && !AppConfig.SupportsJson)
654+
return;
655+
618656
using (var command = m_database.Connection.CreateCommand())
619657
{
620658
command.CommandText = $"select `{column}` from `{table}`;";
@@ -633,12 +671,16 @@ public void GetSchemaTable(string column, string table, int columnSize, Type dat
633671
Assert.Equal(dataType, schema["DataType"]);
634672
#if BASELINE
635673
// https://bugs.mysql.com/bug.php?id=87868
636-
if (dataType != typeof(byte[]) && dataType != typeof(Guid))
674+
if (!column.EndsWith("blob", StringComparison.OrdinalIgnoreCase) && column != "text" && dataType != typeof(Guid) && columnSize != int.MaxValue)
637675
Assert.Equal(columnSize, schema["ColumnSize"]);
638676
#else
639677
Assert.Equal(columnSize, schema["ColumnSize"]);
640678
#endif
679+
#if BASELINE
680+
Assert.Equal(isLong && columnSize != int.MaxValue, schema["IsLong"]);
681+
#else
641682
Assert.Equal(isLong, schema["IsLong"]);
683+
#endif
642684
Assert.Equal(isKey, schema["IsKey"]);
643685
Assert.Equal(allowDbNull, schema["AllowDBNull"]);
644686
Assert.Equal(precision, schema["NumericPrecision"]);

0 commit comments

Comments
 (0)