Skip to content

Commit c47d46e

Browse files
committed
Fix schema table column ordering.
1 parent 408fe30 commit c47d46e

File tree

2 files changed

+23
-32
lines changed

2 files changed

+23
-32
lines changed

DuckDB.NET.Data/DuckDBDataReader.cs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -290,35 +290,34 @@ public override DataTable GetSchemaTable()
290290
{
291291
Columns =
292292
{
293-
{ "ColumnOrdinal", typeof(int) },
294-
{ "ColumnName", typeof(string) },
295-
{ "DataType", typeof(Type) },
296-
{ "ColumnSize", typeof(int) },
297-
{ "AllowDBNull", typeof(bool) },
298-
{ "NumericScale", typeof(byte) },
299-
{ "NumericPrecision", typeof(byte) }
293+
{ SchemaTableColumn.ColumnName, typeof(string) },
294+
{ SchemaTableColumn.ColumnOrdinal, typeof(int) },
295+
{ SchemaTableColumn.ColumnSize, typeof(int) },
296+
{ SchemaTableColumn.NumericPrecision, typeof(byte)},
297+
{ SchemaTableColumn.NumericScale, typeof(byte) },
298+
{ SchemaTableColumn.DataType, typeof(Type) },
299+
{ SchemaTableColumn.AllowDBNull, typeof(bool) }
300300
}
301301
};
302302

303303
var rowData = new object[7];
304304

305305
for (var i = 0; i < FieldCount; i++)
306306
{
307-
rowData[0] = i;
308-
rowData[1] = GetName(i);
309-
rowData[2] = GetFieldType(i);
310-
rowData[3] = -1;
311-
rowData[4] = true;
307+
rowData[0] = GetName(i);
308+
rowData[1] = i;
309+
rowData[2] = -1;
310+
rowData[5] = GetFieldType(i);
311+
rowData[6] = true;
312312

313-
if (vectorReaders[i] is DecimalVectorDataReader decimalVectorDataReader)
313+
if (vectorReaders[i] is DecimalVectorDataReader decimalVectorDataReader)
314314
{
315-
rowData[5] = decimalVectorDataReader.Scale;
316-
rowData[6] = decimalVectorDataReader.Precision;
317-
}
318-
else
315+
rowData[4] = decimalVectorDataReader.Scale;
316+
rowData[3] = decimalVectorDataReader.Precision;
317+
}
318+
else
319319
{
320-
rowData[5] = DBNull.Value;
321-
rowData[6] = DBNull.Value;
320+
rowData[3] = rowData[4] = DBNull.Value;
322321
}
323322

324323
table.Rows.Add(rowData);

DuckDB.NET.Data/Internal/Reader/DecimalVectorDataReader.cs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,19 @@ namespace DuckDB.NET.Data.Internal.Reader;
66

77
internal sealed class DecimalVectorDataReader : NumericVectorDataReader
88
{
9-
private readonly byte scale;
10-
private readonly byte precision;
119
private readonly DuckDBType decimalType;
1210

1311
internal unsafe DecimalVectorDataReader(IntPtr vector, void* dataPointer, ulong* validityMaskPointer, DuckDBType columnType, string columnName) : base(dataPointer, validityMaskPointer, columnType, columnName)
1412
{
1513
using var logicalType = NativeMethods.Vectors.DuckDBVectorGetColumnType(vector);
16-
scale = NativeMethods.LogicalType.DuckDBDecimalScale(logicalType);
17-
precision = NativeMethods.LogicalType.DuckDBDecimalWidth(logicalType);
14+
Scale = NativeMethods.LogicalType.DuckDBDecimalScale(logicalType);
15+
Precision = NativeMethods.LogicalType.DuckDBDecimalWidth(logicalType);
1816
decimalType = NativeMethods.LogicalType.DuckDBDecimalInternalType(logicalType);
1917
}
2018

21-
internal byte Scale
22-
{
23-
get => scale;
24-
}
19+
internal byte Scale { get; }
2520

26-
internal byte Precision
27-
{
28-
get => precision;
29-
}
21+
internal byte Precision { get; }
3022

3123
protected override T GetValidValue<T>(ulong offset, Type targetType)
3224
{
@@ -51,7 +43,7 @@ internal override object GetValue(ulong offset, Type targetType)
5143

5244
private decimal GetDecimal(ulong offset)
5345
{
54-
var pow = (decimal)Math.Pow(10, scale);
46+
var pow = (decimal)Math.Pow(10, Scale);
5547
switch (decimalType)
5648
{
5749
case DuckDBType.SmallInt:

0 commit comments

Comments
 (0)