Skip to content

Commit 8b6980c

Browse files
committed
Support reading HugeInt and interval values
1 parent 54cf196 commit 8b6980c

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

DuckDB.NET.Bindings/DuckDBWrapperObjects.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,15 @@ public T GetValue<T>()
141141
DuckDBType.Decimal => Cast(decimal.Parse(NativeMethods.Value.DuckDBGetVarchar(this))),
142142
DuckDBType.Uuid => Cast(new Guid(NativeMethods.Value.DuckDBGetVarchar(this))),
143143

144-
//DuckDBType.HugeInt => expr,
145-
//DuckDBType.UnsignedHugeInt => expr,
144+
DuckDBType.HugeInt => Cast(NativeMethods.Value.DuckDBGetHugeInt(this).ToBigInteger()),
145+
DuckDBType.UnsignedHugeInt => Cast(NativeMethods.Value.DuckDBGetUHugeInt(this).ToBigInteger()),
146146

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

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

161-
T Cast<TSource>(TSource value)
162-
{
163-
return Unsafe.As<TSource, T>(ref value);
164-
}
161+
T Cast<TSource>(TSource value) => Unsafe.As<TSource, T>(ref value);
165162
}
166163
}

DuckDB.NET.Bindings/NativeMethods/NativeMethods.Value.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,22 +111,22 @@ public static class Value
111111
public static extern double DuckDBGetDouble(DuckDBValue value);
112112

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)