Skip to content

Commit 69f57df

Browse files
committed
Switch to 0-based column ordinals.
This is a breaking change with Connector/NET, but its behaviour doesn't match the MSDN documentation, nor other methods on DbDataReader (which use 0-based column ordinals).
1 parent 8932760 commit 69f57df

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

docs/content/tutorials/migrating-from-connector-net.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ property doesn't reference the active transaction. See [#333](https://github.com
7474

7575
* [#37283](https://bugs.mysql.com/bug.php?id=37283), [#70587](https://bugs.mysql.com/bug.php?id=70587): Distributed transactions are not supported
7676
* [#50773](https://bugs.mysql.com/bug.php?id=50773): Can't use multiple connections within one TransactionScope
77+
* [#61477](https://bugs.mysql.com/bug.php?id=61477): `ColumnOrdinal` in schema table is 1-based
7778
* [#66476](https://bugs.mysql.com/bug.php?id=66476): Connection pool uses queue instead of stack
7879
* [#70111](https://bugs.mysql.com/bug.php?id=70111): `Async` methods execute synchronously
7980
* [#70686](https://bugs.mysql.com/bug.php?id=70686): `TIME(3)` and `TIME(6)` fields serialize milliseconds incorrectly

src/MySqlConnector/MySqlClient/MySqlDataReader.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections;
33
using System.Collections.Generic;
44
using System.Data;
@@ -344,7 +344,7 @@ internal DataTable BuildSchemaTable()
344344
var col = colDefinitions[i];
345345
var schemaRow = schemaTable.NewRow();
346346
schemaRow[columnName] = col.Name;
347-
schemaRow[ordinal] = i + 1; // https://bugs.mysql.com/bug.php?id=61477
347+
schemaRow[ordinal] = i;
348348
schemaRow[dataType] = GetFieldType(i);
349349
schemaRow[size] = (Type)schemaRow[dataType] == typeof(string) || (Type)schemaRow[dataType] == typeof(Guid) ?
350350
col.ColumnLength / SerializationUtility.GetBytesPerCharacter(col.CharacterSet) :

tests/SideBySide/DataTypes.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -619,12 +619,18 @@ public void GetSchemaTable(string column, string table, int columnSize, Type dat
619619
{
620620
using (var command = m_database.Connection.CreateCommand())
621621
{
622-
command.CommandText = $"select 1, `{column}` from `{table}`;";
622+
command.CommandText = $"select `{column}` from `{table}`;";
623623
using (var reader = command.ExecuteReader())
624624
{
625-
var schema = reader.GetSchemaTable().Rows[1];
625+
var schemaTable = reader.GetSchemaTable();
626+
Assert.Single(schemaTable.Rows);
627+
var schema = schemaTable.Rows[0];
626628
Assert.Equal(column, schema["ColumnName"]);
627-
int ordinal = 2; // https://bugs.mysql.com/bug.php?id=61477
629+
#if BASELINE
630+
int ordinal = 1; // https://bugs.mysql.com/bug.php?id=61477
631+
#else
632+
int ordinal = 0;
633+
#endif
628634
Assert.Equal(ordinal, schema["ColumnOrdinal"]);
629635
Assert.Equal(dataType, schema["DataType"]);
630636
Assert.Equal(columnSize, schema["ColumnSize"]);
@@ -644,7 +650,7 @@ public void GetSchemaTable(string column, string table, int columnSize, Type dat
644650
}
645651
#endif
646652

647-
private static byte[] CreateByteArray(int size)
653+
private static byte[] CreateByteArray(int size)
648654
{
649655
var data = new byte[size];
650656
Random random = new Random(size);

0 commit comments

Comments
 (0)