Skip to content

Commit

Permalink
Support reading HugeInt and interval values
Browse files Browse the repository at this point in the history
  • Loading branch information
Giorgi committed Nov 14, 2024
1 parent 54cf196 commit 8b6980c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
11 changes: 4 additions & 7 deletions DuckDB.NET.Bindings/DuckDBWrapperObjects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,15 @@ public T GetValue<T>()
DuckDBType.Decimal => Cast(decimal.Parse(NativeMethods.Value.DuckDBGetVarchar(this))),
DuckDBType.Uuid => Cast(new Guid(NativeMethods.Value.DuckDBGetVarchar(this))),

//DuckDBType.HugeInt => expr,
//DuckDBType.UnsignedHugeInt => expr,
DuckDBType.HugeInt => Cast(NativeMethods.Value.DuckDBGetHugeInt(this).ToBigInteger()),
DuckDBType.UnsignedHugeInt => Cast(NativeMethods.Value.DuckDBGetUHugeInt(this).ToBigInteger()),

DuckDBType.Varchar => Cast(NativeMethods.Value.DuckDBGetVarchar(this)),

//DuckDBType.Date => expr,
//DuckDBType.Time => expr,
//DuckDBType.TimeTz => expr,
//DuckDBType.Interval => expr,
DuckDBType.Interval => Cast((TimeSpan)NativeMethods.Value.DuckDBGetInterval(this)),
DuckDBType.Timestamp => Cast(NativeMethods.DateTimeHelpers.DuckDBFromTimestamp(NativeMethods.Value.DuckDBGetTimestamp(this)).ToDateTime()),
//DuckDBType.TimestampS => expr,
//DuckDBType.TimestampMs => expr,
Expand All @@ -158,9 +158,6 @@ public T GetValue<T>()
_ => throw new NotImplementedException($"Cannot read value of type {typeof(T).FullName}")
};

T Cast<TSource>(TSource value)
{
return Unsafe.As<TSource, T>(ref value);
}
T Cast<TSource>(TSource value) => Unsafe.As<TSource, T>(ref value);
}
}
12 changes: 6 additions & 6 deletions DuckDB.NET.Bindings/NativeMethods/NativeMethods.Value.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,22 +111,22 @@ public static class Value
public static extern double DuckDBGetDouble(DuckDBValue value);

[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_get_date")]
public static extern unsafe DuckDBDate DuckDBGetDate(DuckDBValue value);
public static extern DuckDBDate DuckDBGetDate(DuckDBValue value);

[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_get_time")]
public static extern unsafe DuckDBTime DuckDBGetTime(DuckDBValue value);
public static extern DuckDBTime DuckDBGetTime(DuckDBValue value);

[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_get_time_tz")]
public static extern unsafe DuckDBTimeTzStruct DuckDBGetTimeTz(DuckDBValue value);
public static extern DuckDBTimeTzStruct DuckDBGetTimeTz(DuckDBValue value);

[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_get_timestamp")]
public static extern unsafe DuckDBTimestampStruct DuckDBGetTimestamp(DuckDBValue value);
public static extern DuckDBTimestampStruct DuckDBGetTimestamp(DuckDBValue value);

[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_get_interval")]
public static extern unsafe DuckDBInterval DuckDBGetInterval(DuckDBValue value);
public static extern DuckDBInterval DuckDBGetInterval(DuckDBValue value);

[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_get_value_type")]
public static extern unsafe DuckDBLogicalType DuckDBGetValueType(DuckDBValue value);
public static extern DuckDBLogicalType DuckDBGetValueType(DuckDBValue value);

[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_get_varchar")]
public static extern string DuckDBGetVarchar(DuckDBValue value);
Expand Down

0 comments on commit 8b6980c

Please sign in to comment.