Skip to content

Commit

Permalink
Fixed issue with datatable.Fill with nullable columns #539
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkWanderer committed Nov 7, 2024
1 parent f182d77 commit be8bca2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
24 changes: 23 additions & 1 deletion ClickHouse.Client.Tests/SqlSchemaTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
using System.Data.Common;
using System.Data;
using System;
using System.Data.Common;
using System.Reflection.PortableExecutable;
using System.Threading.Tasks;
using ClickHouse.Client.Utility;
using NUnit.Framework;
using System.Linq;

namespace ClickHouse.Client.Tests;

Expand All @@ -24,4 +28,22 @@ public async Task ShouldGetReaderSchemaTable()
var schema = reader.GetSchemaTable();
Assert.AreEqual(2, schema.Rows.Count);
}

[Test]
public void ShouldGetSchemaTableAsDataTable()
{
using var command = connection.CreateCommand();
command.CommandText = "SELECT name, total_rows from system.tables";
using var reader = command.ExecuteReader();
var table = new DataTable();
try {
table.Load(reader);
}
catch
{

}
var errors = table.GetErrors().Select(e => e.RowError).ToList();
CollectionAssert.IsEmpty(errors);
}
}
3 changes: 2 additions & 1 deletion ClickHouse.Client/Utility/SchemaDescriber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public static DataTable DescribeSchema(this ClickHouseDataReader reader)
var row = table.NewRow();
row["ColumnName"] = reader.GetName(ordinal);
row["ColumnOrdinal"] = ordinal;
row["DataType"] = chType.FrameworkType;
row["ColumnSize"] = -1;
row["DataType"] = chType is NullableType nt ? nt.UnderlyingType.FrameworkType : chType.FrameworkType;
row["ProviderType"] = chType;
row["IsLong"] = chType is StringType;
row["AllowDBNull"] = chType is NullableType;
Expand Down

0 comments on commit be8bca2

Please sign in to comment.