Giorgi / DuckDB.NET

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

GetDateTime reads a DBDateOnly column incorrectly #143

Closed DanCory closed 9 months ago

DanCory commented 9 months ago

Similar to my previous bug:

using DuckDB.NET.Data;
using DuckDB.NET;
using DuckDBConnection duckDBConnection = new("Data Source=test.db");
duckDBConnection.Open();
DuckDbCommand command = duckDBConnection.CreateCommand();
command.CommandText = "DROP TABLE IF EXISTS intdate;";
command.ExecuteNonQuery();
command.CommandText = "CREATE TABLE intdate(foo INTEGER, bar DATE);";
command.ExecuteNonQuery();
command.CommandText = "INSERT INTO intdate VALUES (3, date '2001-02-03'), (5, date '2004-05-06'), (7, date '2007-08-09');";
command.ExecuteNonQuery();
command.CommandText = "SELECT bar FROM intdate";
DuckDBDataReader reader = command.ExecuteReader();
while (reader.Read())
{
  for (int c = 0; c < reader.FieldCount; c++)
  {
    Console.Write(reader.GetDateTime(c));
  }
  Console.WriteLine();
}
reader.Close();

returns

9/16/1971 1:34:29 PM

then throws an exception on the next record

should return

2/3/2001
5/6/2004
8/9/2007

Replacing reader.GetDateTime(c) with ((DuckDBDateOnly)reader.GetValue(c)).ToDateTime() works.

Giorgi commented 9 months ago

Fixed in 23a444e123ad52d98825786d71f97dca5b2d4c0a

Giorgi commented 8 months ago

The fix is now live in 0.9.1 release