Skip to content

Commit

Permalink
Do not release logical type
Browse files Browse the repository at this point in the history
  • Loading branch information
Giorgi committed Nov 4, 2024
1 parent 5c49b25 commit 5faf28b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions DuckDB.NET.Bindings/DuckDBWrapperObjects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,13 @@ internal void SetChildValues(DuckDBValue[] values)

public T GetValue<T>()
{
return (T)(object)NativeMethods.Value.DuckDBGetInt32(this);
var type = typeof(T);
var logicalType = NativeMethods.Value.DuckDBGetValueType(this);

//Logical type is part of the duckdb_value object and it shouldn't be released separately
//It will get released when the duckdb_value object is destroyed below.
var add = false;
logicalType.DangerousAddRef(ref add);

var duckDBType = NativeMethods.LogicalType.DuckDBGetTypeId(logicalType);

return duckDBType switch
Expand Down Expand Up @@ -145,7 +149,7 @@ public T GetValue<T>()
DuckDBType.Varchar => ReadValue<string>(NativeMethods.Value.DuckDBGetVarchar(this)),
//DuckDBType.Decimal => ReadValue<T>(),
//DuckDBType.Uuid => expr,
_ => throw new NotImplementedException($"Cannot read value of type {type.FullName}")
_ => throw new NotImplementedException($"Cannot read value of type {typeof(T).FullName}")
};

T ReadValue<TSource>(TSource value)
Expand Down

0 comments on commit 5faf28b

Please sign in to comment.