Giorgi / DuckDB.NET

Bindings and ADO.NET Provider for DuckDB
https://duckdb.net
MIT License
411 stars 69 forks source link

added GetSchemaTable to datareader #73

Closed mikeTWC1984 closed 1 year ago

mikeTWC1984 commented 1 year ago

This should allow to load DataTable from Reader. https://github.com/Giorgi/DuckDB.NET/issues/65

Giorgi commented 1 year ago

@mikeTWC1984 Can you add a test that shows what issue this PR solves?

mikeTWC1984 commented 1 year ago

It lets loading reader data into datatable. Possible test is below. Without GetSchemaTable method dt.Load(reader) would throw an exception.


    [Fact]
    public void LoadDataTable()
    {
        using var connection = new DuckDBConnection("DataSource=:memory:");
        connection.Open();

        var duckDbCommand = connection.CreateCommand();
        duckDbCommand.CommandText = "select 1 as num, 'text' as str, now() as tme";
        var reader = duckDbCommand.ExecuteReader();
        var dt = new DataTable()
        dt.Load(reader)
        dt.Rows.Count.Should().Be(1)
    }
Giorgi commented 1 year ago

Can you add that test to the PR?

mikeTWC1984 commented 1 year ago

Just added

mikeTWC1984 commented 1 year ago

just fixed missing semicolon

mikeTWC1984 commented 1 year ago

I see test failing because "now()" returns a timestamp with milliseconds, by some reason reader.GetDateTime method can't handle it. If I use timestamp from literal without ms, (e.g. "TIMESTAMP '1992-09-20 20:38:40'") it works. I can also get string value from "now" ( reader.GetString) and cast it to ts.

Giorgi commented 1 year ago

@mikeTWC1984 Yes, please replace now with some literal and create an issue for milliseconds issue.