Giorgi / DuckDB.NET

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

GetValue for decimal columns always returns value from first row #141

Closed DanCory closed 9 months ago

DanCory commented 9 months ago

The GetValue function for decimal columns always returns the value from the first row. It works correctly for int columns. I have not exhaustively tested other data types.

using DuckDB.NET.Data;
using DuckDBConnection duckDBConnection = new("Data Source=test.db");
duckDBConnection.Open();
DuckDbCommand command = duckDBConnection.CreateCommand();
command.CommandText = "CREATE TABLE decint(foo DECIMAL(10,2), bar INTEGER);";
command.ExecuteNonQuery();
command.CommandText = "INSERT INTO decint VALUES (3, 4), (5, 6), (7, 8);";
command.ExecuteNonQuery();
command.CommandText = "SELECT foo, bar FROM decint";
DuckDBDataReader reader = command.ExecuteReader();
while (reader.Read())
{
  for (int c = 0; c < reader.FieldCount; c++)
    Console.Write(reader.GetValue(c).ToString() + ",");
  Console.WriteLine();
}
reader.Close();

This should return:

3, 4
5, 6
7, 8

But it returns:

3, 4
3, 6
3, 8
Giorgi commented 9 months ago

Fixed in d73ab1a

Giorgi commented 9 months ago

@DanCory The fix is now live on NuGet.

DanCory commented 9 months ago

Thanks for the quick fix @Giorgi. I verified decimals are now fixed. My code is still having troubles with BIGINT and DATE data types, but it doesn't immediately appear to be the same issue. I will investigate and file separate bugs.