Skip to content

Commit 594baef

Browse files
committed
Implement IsAutoIncrement in GetSchemaTable.
1 parent 65b62c5 commit 594baef

File tree

3 files changed

+57
-77
lines changed

3 files changed

+57
-77
lines changed

src/MySqlConnector/MySqlClient/MySqlDataReader.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -352,25 +352,22 @@ internal DataTable BuildSchemaTable()
352352
col.ColumnLength;
353353
schemaRow[size] = columnSize > int.MaxValue ? int.MaxValue : unchecked((int) columnSize);
354354
schemaRow[providerType] = col.ColumnType;
355-
schemaRow[isLong] = col.ColumnLength > 255 && ((col.ColumnFlags & ColumnFlags.Blob) != 0 || col.ColumnType.IsBlob());
355+
schemaRow[isLong] = col.ColumnLength > 255 && ((col.ColumnFlags & ColumnFlags.Blob) != 0 || col.ColumnType == ColumnType.TinyBlob || col.ColumnType == ColumnType.Blob || col.ColumnType == ColumnType.MediumBlob || col.ColumnType == ColumnType.LongBlob);
356+
schemaRow[isUnique] = false;
356357
schemaRow[isKey] = (col.ColumnFlags & ColumnFlags.PrimaryKey) != 0;
357358
schemaRow[allowDBNull] = (col.ColumnFlags & ColumnFlags.NotNull) == 0;
358359
schemaRow[scale] = col.Decimals;
359-
if (col.ColumnType.IsDecimal())
360-
{
360+
if (col.ColumnType == ColumnType.Decimal || col.ColumnType == ColumnType.NewDecimal)
361361
schemaRow[precision] = col.ColumnLength - 2 + ((col.ColumnFlags & ColumnFlags.Unsigned) != 0 ? 1 : 0);
362-
}
363362

363+
schemaRow[baseCatalogName] = null;
364+
schemaRow[baseColumnName] = col.PhysicalName;
364365
schemaRow[baseSchemaName] = col.SchemaName;
365366
schemaRow[baseTableName] = col.PhysicalTable;
366-
schemaRow[baseColumnName] = col.PhysicalName;
367-
schemaRow[isUnique] = false;
367+
schemaRow[isAutoIncrement] = (col.ColumnFlags & ColumnFlags.AutoIncrement) != 0;
368368
schemaRow[isRowVersion] = false;
369369
schemaRow[isReadOnly] = false;
370370

371-
// To be consist with Orcale MySQL connector, set baseCatelogName to null and do not set isAliased, isExpression, isIdentity, isHidden value.
372-
schemaRow[baseCatalogName] = null;
373-
374371
schemaTable.Rows.Add(schemaRow);
375372
schemaRow.AcceptChanges();
376373
}

src/MySqlConnector/Serialization/ColumnType.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,4 @@ internal enum ColumnType
3636
String = 0xFE,
3737
Geometry = 0xFF,
3838
}
39-
40-
internal static class Extensions
41-
{
42-
public static bool IsBlob(this ColumnType type)
43-
{
44-
return type >= ColumnType.TinyBlob && type <= ColumnType.Blob;
45-
}
46-
47-
public static bool IsString(this ColumnType type)
48-
{
49-
return type == ColumnType.VarChar || type == ColumnType.VarString || type == ColumnType.String;
50-
}
51-
52-
public static bool IsDecimal(this ColumnType type)
53-
{
54-
return type == ColumnType.Decimal || type == ColumnType.NewDecimal;
55-
}
56-
}
5739
}

tests/SideBySide/DataTypes.cs

Lines changed: 51 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -600,55 +600,55 @@ 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)]
613-
[InlineData("rowid", "datatypes_bools", 11, typeof(int), false, true, false, 0, 0)]
614-
[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)]
622-
[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)]
624-
[InlineData("Int16", "datatypes_integers", 6, typeof(short), false, false, true, 0, 0)]
625-
[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)]
634-
[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)]
636-
[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)]
639-
[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)]
644-
[InlineData("guid", "datatypes_strings", 36, typeof(Guid), false, false, true, 0, 0)]
645-
[InlineData("guidbin", "datatypes_strings", 36, typeof(Guid), false, false, true, 0, 0)]
646-
[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)]
649-
[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)]
651-
public void GetSchemaTable(string column, string table, int columnSize, Type dataType, bool isLong, bool isKey, bool allowDbNull, int precision, int scale)
603+
[InlineData("Bit1", "datatypes_bits", 1, typeof(ulong), false, false, false, true, 0, 0)]
604+
[InlineData("Bit32", "datatypes_bits", 32, typeof(ulong), false, false, false, true, 0, 0)]
605+
[InlineData("Bit64", "datatypes_bits", 64, typeof(ulong), false, false, false, true, 0, 0)]
606+
[InlineData("Binary", "datatypes_blobs", 100, typeof(byte[]), false, false, false, true, 0, 0)]
607+
[InlineData("VarBinary", "datatypes_blobs", 100, typeof(byte[]), false, false, false, true, 0, 0)]
608+
[InlineData("TinyBlob", "datatypes_blobs", 255, typeof(byte[]), false, false, false, true, 0, 0)]
609+
[InlineData("Blob", "datatypes_blobs", 65535, typeof(byte[]), false, true, false, true, 0, 0)]
610+
[InlineData("MediumBlob", "datatypes_blobs", 16777215, typeof(byte[]), false, true, false, true, 0, 0)]
611+
[InlineData("LongBlob", "datatypes_blobs", int.MaxValue, typeof(byte[]), false, true, false, true, 0, 0)]
612+
[InlineData("guidbin", "datatypes_blobs", 16, typeof(byte[]), false, false, false, true, 0, 0)]
613+
[InlineData("rowid", "datatypes_bools", 11, typeof(int), true, false, true, false, 0, 0)]
614+
[InlineData("Boolean", "datatypes_bools", 1, typeof(bool), false, false, false, true, 0, 0)]
615+
[InlineData("TinyInt1", "datatypes_bools", 1, typeof(bool), false, false, false, true, 0, 0)]
616+
[InlineData("size", "datatypes_enums", 7, typeof(string), false, false, false, true, 0, 0)]
617+
[InlineData("color", "datatypes_enums", 6, typeof(string), false, false, false, false, 0, 0)]
618+
[InlineData("char38", "datatypes_guids", 38, typeof(string), false, false, false, true, 0, 0)]
619+
[InlineData("char38bin", "datatypes_guids", 38, typeof(string), false, false, false, true, 0, 0)]
620+
[InlineData("text", "datatypes_guids", 65535, typeof(string), false, true, false, true, 0, 0)]
621+
[InlineData("blob", "datatypes_guids", 65535, typeof(byte[]), false, true, false, true, 0, 0)]
622+
[InlineData("SByte", "datatypes_integers", 4, typeof(sbyte), false, false, false, true, 0, 0)]
623+
[InlineData("Byte", "datatypes_integers", 3, typeof(byte), false, false, false, true, 0, 0)]
624+
[InlineData("Int16", "datatypes_integers", 6, typeof(short), false, false, false, true, 0, 0)]
625+
[InlineData("UInt16", "datatypes_integers", 5, typeof(ushort), false, false, false, true, 0, 0)]
626+
[InlineData("Int24", "datatypes_integers", 9, typeof(int), false, false, false, true, 0, 0)]
627+
[InlineData("UInt24", "datatypes_integers", 8, typeof(uint), false, false, false, true, 0, 0)]
628+
[InlineData("Int32", "datatypes_integers", 11, typeof(int), false, false, false, true, 0, 0)]
629+
[InlineData("UInt32", "datatypes_integers", 10, typeof(uint), false, false, false, true, 0, 0)]
630+
[InlineData("Int64", "datatypes_integers", 20, typeof(long), false, false, false, true, 0, 0)]
631+
[InlineData("UInt64", "datatypes_integers", 20, typeof(ulong), false, false, false, true, 0, 0)]
632+
[InlineData("value", "datatypes_json_core", int.MaxValue, typeof(string), false, true, false, true, 0, 0)]
633+
[InlineData("Single", "datatypes_reals", 12, typeof(float), false, false, false, true, 0, 31)]
634+
[InlineData("Double", "datatypes_reals", 22, typeof(double), false, false, false, true, 0, 31)]
635+
[InlineData("SmallDecimal", "datatypes_reals", 7, typeof(decimal), false, false, false, true, 5, 2)]
636+
[InlineData("MediumDecimal", "datatypes_reals", 30, typeof(decimal), false, false, false, true, 28, 8)]
637+
[InlineData("BigDecimal", "datatypes_reals", 52, typeof(decimal), false, false, false, true, 50, 30)]
638+
[InlineData("value", "datatypes_set", 12, typeof(string), false, false, false, true, 0, 0)]
639+
[InlineData("utf8", "datatypes_strings", 300, typeof(string), false, false, false, true, 0, 0)]
640+
[InlineData("utf8bin", "datatypes_strings", 300, typeof(string), false, false, false, true, 0, 0)]
641+
[InlineData("latin1", "datatypes_strings", 300, typeof(string), false, false, false, true, 0, 0)]
642+
[InlineData("latin1bin", "datatypes_strings", 300, typeof(string), false, false, false, true, 0, 0)]
643+
[InlineData("cp1251", "datatypes_strings", 300, typeof(string), false, false, false, true, 0, 0)]
644+
[InlineData("guid", "datatypes_strings", 36, typeof(Guid), false, false, false, true, 0, 0)]
645+
[InlineData("guidbin", "datatypes_strings", 36, typeof(Guid), false, false, false, true, 0, 0)]
646+
[InlineData("Date", "datatypes_times", 10, typeof(DateTime), false, false, false, true, 0, 0)]
647+
[InlineData("DateTime", "datatypes_times", 26, typeof(DateTime), false, false, false, true, 0, 6)]
648+
[InlineData("Timestamp", "datatypes_times", 26, typeof(DateTime), false, false, false, true, 0, 6)]
649+
[InlineData("Time", "datatypes_times", 17, typeof(TimeSpan), false, false, false, true, 0, 6)]
650+
[InlineData("Year", "datatypes_times", 4, typeof(int), false, false, false, true, 0, 0)]
651+
public void GetSchemaTable(string column, string table, int columnSize, Type dataType, bool isAutoIncrement, bool isLong, bool isKey, bool allowDbNull, int precision, int scale)
652652
{
653653
if (table == "datatypes_json_core" && !AppConfig.SupportsJson)
654654
return;
@@ -681,6 +681,7 @@ public void GetSchemaTable(string column, string table, int columnSize, Type dat
681681
#else
682682
Assert.Equal(isLong, schema["IsLong"]);
683683
#endif
684+
Assert.Equal(isAutoIncrement, schema["IsAutoIncrement"]);
684685
Assert.Equal(isKey, schema["IsKey"]);
685686
Assert.Equal(allowDbNull, schema["AllowDBNull"]);
686687
Assert.Equal(precision, schema["NumericPrecision"]);
@@ -696,7 +697,7 @@ public void GetSchemaTable(string column, string table, int columnSize, Type dat
696697
}
697698
#endif
698699

699-
private static byte[] CreateByteArray(int size)
700+
private static byte[] CreateByteArray(int size)
700701
{
701702
var data = new byte[size];
702703
Random random = new Random(size);

0 commit comments

Comments
 (0)