Skip to content

Commit a062191

Browse files
committed
fix(mssql): implement GetSchemaTable in DataReader for DataTable.Load support
1 parent 3bf8dd0 commit a062191

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
<Authors>vkuttyp</Authors>
88
<PackageLicenseExpression>MIT</PackageLicenseExpression>
99
<RepositoryUrl>https://github.com/vkuttyp/CosmoSQLClient-Dotnet</RepositoryUrl>
10-
<Version>1.5.4</Version>
10+
<Version>1.5.5</Version>
1111
</PropertyGroup>
1212
</Project>

src/CosmoSQLClient.MsSql/MsSqlDataReader.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,33 @@ public override Type GetFieldType(int ordinal)
101101
};
102102
}
103103

104+
public override DataTable GetSchemaTable()
105+
{
106+
var dt = new DataTable("SchemaTable");
107+
dt.Columns.Add("ColumnName", typeof(string));
108+
dt.Columns.Add("ColumnOrdinal", typeof(int));
109+
dt.Columns.Add("ColumnSize", typeof(int));
110+
dt.Columns.Add("NumericPrecision", typeof(short));
111+
dt.Columns.Add("NumericScale", typeof(short));
112+
dt.Columns.Add("DataType", typeof(Type));
113+
dt.Columns.Add("AllowDBNull", typeof(bool));
114+
115+
var cols = CurrentSetColumns;
116+
if (cols != null)
117+
{
118+
for (int i = 0; i < cols.Count; i++)
119+
{
120+
var row = dt.NewRow();
121+
row["ColumnName"] = cols[i].Name;
122+
row["ColumnOrdinal"] = i;
123+
row["DataType"] = GetFieldType(i);
124+
row["AllowDBNull"] = cols[i].IsNullable;
125+
dt.Rows.Add(row);
126+
}
127+
}
128+
return dt;
129+
}
130+
104131
// ── Value accessors ───────────────────────────────────────────────────────
105132

106133
public override bool IsDBNull(int ordinal) => Get(ordinal) is SqlValue.Null;

0 commit comments

Comments
 (0)