-
-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathDuckDBNativeObjects.cs
More file actions
252 lines (218 loc) · 5.83 KB
/
DuckDBNativeObjects.cs
File metadata and controls
252 lines (218 loc) · 5.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
namespace DuckDB.NET.Native;
public enum DuckDBState
{
Success = 0,
Error = 1
}
public enum DuckDBType
{
Invalid = 0,
// bool
Boolean = 1,
// int8_t
TinyInt = 2,
// int16_t
SmallInt = 3,
// int32_t
Integer = 4,
// int64_t
BigInt = 5,
// uint8_t
UnsignedTinyInt = 6,
// uint16_t
UnsignedSmallInt = 7,
// uint32_t
UnsignedInteger = 8,
// uint64_t
UnsignedBigInt = 9,
// float
Float = 10,
// double
Double = 11,
// duckdb_timestamp
Timestamp = 12,
// duckdb_date
Date = 13,
// duckdb_time
Time = 14,
// duckdb_interval
Interval = 15,
// duckdb_hugeint
HugeInt = 16,
// duckdb_uhugeint
UnsignedHugeInt = 32,
// const char*
Varchar = 17,
// duckdb_blob
Blob = 18,
//decimal
Decimal = 19,
// duckdb_timestamp, in seconds
TimestampS = 20,
// duckdb_timestamp, in milliseconds
TimestampMs = 21,
// duckdb_timestamp, in nanoseconds
TimestampNs = 22,
// enum type, only useful as logical type
Enum = 23,
// list type, only useful as logical type
List = 24,
// duckdb_array, only useful as logical type
Array = 33,
// struct type, only useful as logical type
Struct = 25,
// map type, only useful as logical type
Map = 26,
// duckdb_hugeint
Uuid = 27,
// union type, only useful as logical type
Union = 28,
// duckdb_bit
Bit = 29,
// duckdb_time_tz
TimeTz = 30,
// duckdb_timestamp
TimestampTz = 31,
// ANY type
Any = 34,
// duckdb_varint
VarInt = 35,
// SQLNULL type
SqlNull = 36,
}
[StructLayout(LayoutKind.Sequential)]
public struct DuckDBResult
{
[Obsolete]
private long ColumnCount;
[Obsolete]
private long RowCount;
[Obsolete]
private long RowsChanged;
[Obsolete]
private IntPtr columns;
[Obsolete]
private IntPtr ErrorMessage;
private IntPtr internal_data;
public void Close()
{
NativeMethods.Query.DuckDBDestroyResult(ref this);
}
}
[StructLayout(LayoutKind.Sequential)]
public struct DuckDBDate
{
/// <summary>
/// Represents DuckDB's positive infinity date value.
/// This is the value used in the DuckDB source code for +infinity dates.
/// </summary>
public static readonly DuckDBDate PositiveInfinity = new() { Days = int.MaxValue };
/// <summary>
/// Represents DuckDB's negative infinity date value.
/// This is the value used in the DuckDB source code for -infinity dates.
/// </summary>
public static readonly DuckDBDate NegativeInfinity = new() { Days = -int.MaxValue };
public int Days { get; set; }
public bool IsInfinity => IsPositiveInfinity || IsNegativeInfinity;
public bool IsPositiveInfinity => Days == int.MaxValue;
public bool IsNegativeInfinity => Days == -int.MaxValue;
}
[StructLayout(LayoutKind.Sequential)]
public struct DuckDBTime
{
public long Micros { get; set; }
}
[StructLayout(LayoutKind.Sequential)]
public struct DuckDBTimeTzStruct
{
public ulong Bits { get; set; }
}
[StructLayout(LayoutKind.Sequential)]
public struct DuckDBTimeTz
{
public DuckDBTimeOnly Time { get; set; }
public int Offset { get; set; }
}
[StructLayout(LayoutKind.Sequential)]
public struct DuckDBTimestampStruct
{
/// <summary>
/// Represents DuckDB's positive infinity timestamp value.
/// This is the value used in the DuckDB source code for +infinity timestamps.
/// </summary>
public static readonly DuckDBTimestampStruct PositiveInfinity = new() { Micros = long.MaxValue };
/// <summary>
/// Represents DuckDB's negative infinity timestamp value.
/// This is the value used in the DuckDB source code for -infinity timestamps.
/// </summary>
public static readonly DuckDBTimestampStruct NegativeInfinity = new() { Micros = -long.MaxValue };
public long Micros { get; set; }
public bool IsInfinity => IsPositiveInfinity || IsNegativeInfinity;
public bool IsPositiveInfinity => Micros == long.MaxValue;
public bool IsNegativeInfinity => Micros == -long.MaxValue;
}
[StructLayout(LayoutKind.Sequential)]
public readonly struct DuckDBBlob : IDisposable
{
public IntPtr Data { get; }
public long Size { get; }
public void Dispose()
{
NativeMethods.Helpers.DuckDBFree(Data);
}
}
[StructLayout(LayoutKind.Sequential)]
public readonly struct DuckDBListEntry(ulong offset, ulong length)
{
public ulong Offset { get; } = offset;
public ulong Length { get; } = length;
}
public struct DuckDBString
{
public _value_e__Union value;
private const int InlineStringMaxLength = 12;
public readonly int Length => (int)value.inlined.length;
public readonly unsafe sbyte* Data
{
get
{
if (Length <= InlineStringMaxLength)
{
fixed (sbyte* pointerToFirst = value.inlined.inlined)
{
return pointerToFirst;
}
}
else
{
return value.pointer.ptr;
}
}
}
[StructLayout(LayoutKind.Explicit)]
public partial struct _value_e__Union
{
[FieldOffset(0)]
public DuckDBStringPointer pointer;
[FieldOffset(0)]
public DuckDBStringInlined inlined;
public unsafe partial struct DuckDBStringPointer
{
public uint length;
public fixed sbyte prefix[4];
public sbyte* ptr;
}
public unsafe partial struct DuckDBStringInlined
{
public uint length;
public fixed sbyte inlined[12];
}
}
}
[StructLayout(LayoutKind.Sequential)]
public struct DuckDBQueryProgress
{
public double Percentage { get; }
public ulong RowsProcessed { get; }
public ulong TotalRowsToProcess { get; }
}