-
Notifications
You must be signed in to change notification settings - Fork 108
/
duckdb.h
4162 lines (3228 loc) · 148 KB
/
duckdb.h
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//===----------------------------------------------------------------------===//
//
// DuckDB
//
// duckdb.h
//
//
//===----------------------------------------------------------------------===//
//
// !!!!!!!
// WARNING: this file is autogenerated by scripts/generate_c_api.py, manual changes will be overwritten
// !!!!!!!
#pragma once
//! duplicate of duckdb/main/winapi.hpp
#ifndef DUCKDB_API
#ifdef _WIN32
#ifdef DUCKDB_STATIC_BUILD
#define DUCKDB_API
#else
#if defined(DUCKDB_BUILD_LIBRARY) && !defined(DUCKDB_BUILD_LOADABLE_EXTENSION)
#define DUCKDB_API __declspec(dllexport)
#else
#define DUCKDB_API __declspec(dllimport)
#endif
#endif
#else
#define DUCKDB_API
#endif
#endif
//! duplicate of duckdb/main/winapi.hpp
#ifndef DUCKDB_EXTENSION_API
#ifdef _WIN32
#ifdef DUCKDB_STATIC_BUILD
#define DUCKDB_EXTENSION_API
#else
#ifdef DUCKDB_BUILD_LOADABLE_EXTENSION
#define DUCKDB_EXTENSION_API __declspec(dllexport)
#else
#define DUCKDB_EXTENSION_API
#endif
#endif
#else
#define DUCKDB_EXTENSION_API __attribute__((visibility("default")))
#endif
#endif
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
//===--------------------------------------------------------------------===//
// Enums
//===--------------------------------------------------------------------===//
// WARNING: the numbers of these enums should not be changed, as changing the numbers breaks ABI compatibility
// Always add enums at the END of the enum
//! An enum over DuckDB's internal types.
typedef enum DUCKDB_TYPE {
DUCKDB_TYPE_INVALID = 0,
// bool
DUCKDB_TYPE_BOOLEAN = 1,
// int8_t
DUCKDB_TYPE_TINYINT = 2,
// int16_t
DUCKDB_TYPE_SMALLINT = 3,
// int32_t
DUCKDB_TYPE_INTEGER = 4,
// int64_t
DUCKDB_TYPE_BIGINT = 5,
// uint8_t
DUCKDB_TYPE_UTINYINT = 6,
// uint16_t
DUCKDB_TYPE_USMALLINT = 7,
// uint32_t
DUCKDB_TYPE_UINTEGER = 8,
// uint64_t
DUCKDB_TYPE_UBIGINT = 9,
// float
DUCKDB_TYPE_FLOAT = 10,
// double
DUCKDB_TYPE_DOUBLE = 11,
// duckdb_timestamp, in microseconds
DUCKDB_TYPE_TIMESTAMP = 12,
// duckdb_date
DUCKDB_TYPE_DATE = 13,
// duckdb_time
DUCKDB_TYPE_TIME = 14,
// duckdb_interval
DUCKDB_TYPE_INTERVAL = 15,
// duckdb_hugeint
DUCKDB_TYPE_HUGEINT = 16,
// duckdb_uhugeint
DUCKDB_TYPE_UHUGEINT = 32,
// const char*
DUCKDB_TYPE_VARCHAR = 17,
// duckdb_blob
DUCKDB_TYPE_BLOB = 18,
// decimal
DUCKDB_TYPE_DECIMAL = 19,
// duckdb_timestamp, in seconds
DUCKDB_TYPE_TIMESTAMP_S = 20,
// duckdb_timestamp, in milliseconds
DUCKDB_TYPE_TIMESTAMP_MS = 21,
// duckdb_timestamp, in nanoseconds
DUCKDB_TYPE_TIMESTAMP_NS = 22,
// enum type, only useful as logical type
DUCKDB_TYPE_ENUM = 23,
// list type, only useful as logical type
DUCKDB_TYPE_LIST = 24,
// struct type, only useful as logical type
DUCKDB_TYPE_STRUCT = 25,
// map type, only useful as logical type
DUCKDB_TYPE_MAP = 26,
// duckdb_array, only useful as logical type
DUCKDB_TYPE_ARRAY = 33,
// duckdb_hugeint
DUCKDB_TYPE_UUID = 27,
// union type, only useful as logical type
DUCKDB_TYPE_UNION = 28,
// duckdb_bit
DUCKDB_TYPE_BIT = 29,
// duckdb_time_tz
DUCKDB_TYPE_TIME_TZ = 30,
// duckdb_timestamp
DUCKDB_TYPE_TIMESTAMP_TZ = 31,
// ANY type
DUCKDB_TYPE_ANY = 34,
// duckdb_varint
DUCKDB_TYPE_VARINT = 35,
// SQLNULL type
DUCKDB_TYPE_SQLNULL = 36,
} duckdb_type;
//! An enum over the returned state of different functions.
typedef enum duckdb_state { DuckDBSuccess = 0, DuckDBError = 1 } duckdb_state;
//! An enum over the pending state of a pending query result.
typedef enum duckdb_pending_state {
DUCKDB_PENDING_RESULT_READY = 0,
DUCKDB_PENDING_RESULT_NOT_READY = 1,
DUCKDB_PENDING_ERROR = 2,
DUCKDB_PENDING_NO_TASKS_AVAILABLE = 3
} duckdb_pending_state;
//! An enum over DuckDB's different result types.
typedef enum duckdb_result_type {
DUCKDB_RESULT_TYPE_INVALID = 0,
DUCKDB_RESULT_TYPE_CHANGED_ROWS = 1,
DUCKDB_RESULT_TYPE_NOTHING = 2,
DUCKDB_RESULT_TYPE_QUERY_RESULT = 3,
} duckdb_result_type;
//! An enum over DuckDB's different statement types.
typedef enum duckdb_statement_type {
DUCKDB_STATEMENT_TYPE_INVALID = 0,
DUCKDB_STATEMENT_TYPE_SELECT = 1,
DUCKDB_STATEMENT_TYPE_INSERT = 2,
DUCKDB_STATEMENT_TYPE_UPDATE = 3,
DUCKDB_STATEMENT_TYPE_EXPLAIN = 4,
DUCKDB_STATEMENT_TYPE_DELETE = 5,
DUCKDB_STATEMENT_TYPE_PREPARE = 6,
DUCKDB_STATEMENT_TYPE_CREATE = 7,
DUCKDB_STATEMENT_TYPE_EXECUTE = 8,
DUCKDB_STATEMENT_TYPE_ALTER = 9,
DUCKDB_STATEMENT_TYPE_TRANSACTION = 10,
DUCKDB_STATEMENT_TYPE_COPY = 11,
DUCKDB_STATEMENT_TYPE_ANALYZE = 12,
DUCKDB_STATEMENT_TYPE_VARIABLE_SET = 13,
DUCKDB_STATEMENT_TYPE_CREATE_FUNC = 14,
DUCKDB_STATEMENT_TYPE_DROP = 15,
DUCKDB_STATEMENT_TYPE_EXPORT = 16,
DUCKDB_STATEMENT_TYPE_PRAGMA = 17,
DUCKDB_STATEMENT_TYPE_VACUUM = 18,
DUCKDB_STATEMENT_TYPE_CALL = 19,
DUCKDB_STATEMENT_TYPE_SET = 20,
DUCKDB_STATEMENT_TYPE_LOAD = 21,
DUCKDB_STATEMENT_TYPE_RELATION = 22,
DUCKDB_STATEMENT_TYPE_EXTENSION = 23,
DUCKDB_STATEMENT_TYPE_LOGICAL_PLAN = 24,
DUCKDB_STATEMENT_TYPE_ATTACH = 25,
DUCKDB_STATEMENT_TYPE_DETACH = 26,
DUCKDB_STATEMENT_TYPE_MULTI = 27,
} duckdb_statement_type;
//! An enum over DuckDB's different result types.
typedef enum duckdb_error_type {
DUCKDB_ERROR_INVALID = 0,
DUCKDB_ERROR_OUT_OF_RANGE = 1,
DUCKDB_ERROR_CONVERSION = 2,
DUCKDB_ERROR_UNKNOWN_TYPE = 3,
DUCKDB_ERROR_DECIMAL = 4,
DUCKDB_ERROR_MISMATCH_TYPE = 5,
DUCKDB_ERROR_DIVIDE_BY_ZERO = 6,
DUCKDB_ERROR_OBJECT_SIZE = 7,
DUCKDB_ERROR_INVALID_TYPE = 8,
DUCKDB_ERROR_SERIALIZATION = 9,
DUCKDB_ERROR_TRANSACTION = 10,
DUCKDB_ERROR_NOT_IMPLEMENTED = 11,
DUCKDB_ERROR_EXPRESSION = 12,
DUCKDB_ERROR_CATALOG = 13,
DUCKDB_ERROR_PARSER = 14,
DUCKDB_ERROR_PLANNER = 15,
DUCKDB_ERROR_SCHEDULER = 16,
DUCKDB_ERROR_EXECUTOR = 17,
DUCKDB_ERROR_CONSTRAINT = 18,
DUCKDB_ERROR_INDEX = 19,
DUCKDB_ERROR_STAT = 20,
DUCKDB_ERROR_CONNECTION = 21,
DUCKDB_ERROR_SYNTAX = 22,
DUCKDB_ERROR_SETTINGS = 23,
DUCKDB_ERROR_BINDER = 24,
DUCKDB_ERROR_NETWORK = 25,
DUCKDB_ERROR_OPTIMIZER = 26,
DUCKDB_ERROR_NULL_POINTER = 27,
DUCKDB_ERROR_IO = 28,
DUCKDB_ERROR_INTERRUPT = 29,
DUCKDB_ERROR_FATAL = 30,
DUCKDB_ERROR_INTERNAL = 31,
DUCKDB_ERROR_INVALID_INPUT = 32,
DUCKDB_ERROR_OUT_OF_MEMORY = 33,
DUCKDB_ERROR_PERMISSION = 34,
DUCKDB_ERROR_PARAMETER_NOT_RESOLVED = 35,
DUCKDB_ERROR_PARAMETER_NOT_ALLOWED = 36,
DUCKDB_ERROR_DEPENDENCY = 37,
DUCKDB_ERROR_HTTP = 38,
DUCKDB_ERROR_MISSING_EXTENSION = 39,
DUCKDB_ERROR_AUTOLOAD = 40,
DUCKDB_ERROR_SEQUENCE = 41,
DUCKDB_INVALID_CONFIGURATION = 42
} duckdb_error_type;
//! An enum over DuckDB's different cast modes.
typedef enum duckdb_cast_mode { DUCKDB_CAST_NORMAL = 0, DUCKDB_CAST_TRY = 1 } duckdb_cast_mode;
//===--------------------------------------------------------------------===//
// General type definitions
//===--------------------------------------------------------------------===//
//! DuckDB's index type.
typedef uint64_t idx_t;
//! The callback that will be called to destroy data, e.g.,
//! bind data (if any), init data (if any), extra data for replacement scans (if any)
typedef void (*duckdb_delete_callback_t)(void *data);
//! Used for threading, contains a task state. Must be destroyed with `duckdb_destroy_state`.
typedef void *duckdb_task_state;
//===--------------------------------------------------------------------===//
// Types (no explicit freeing)
//===--------------------------------------------------------------------===//
//! Days are stored as days since 1970-01-01
//! Use the duckdb_from_date/duckdb_to_date function to extract individual information
typedef struct {
int32_t days;
} duckdb_date;
typedef struct {
int32_t year;
int8_t month;
int8_t day;
} duckdb_date_struct;
//! Time is stored as microseconds since 00:00:00
//! Use the duckdb_from_time/duckdb_to_time function to extract individual information
typedef struct {
int64_t micros;
} duckdb_time;
typedef struct {
int8_t hour;
int8_t min;
int8_t sec;
int32_t micros;
} duckdb_time_struct;
//! TIME_TZ is stored as 40 bits for int64_t micros, and 24 bits for int32_t offset
typedef struct {
uint64_t bits;
} duckdb_time_tz;
typedef struct {
duckdb_time_struct time;
int32_t offset;
} duckdb_time_tz_struct;
//! Timestamps are stored as microseconds since 1970-01-01
//! Use the duckdb_from_timestamp/duckdb_to_timestamp function to extract individual information
typedef struct {
int64_t micros;
} duckdb_timestamp;
typedef struct {
duckdb_date_struct date;
duckdb_time_struct time;
} duckdb_timestamp_struct;
typedef struct {
int32_t months;
int32_t days;
int64_t micros;
} duckdb_interval;
//! Hugeints are composed of a (lower, upper) component
//! The value of the hugeint is upper * 2^64 + lower
//! For easy usage, the functions duckdb_hugeint_to_double/duckdb_double_to_hugeint are recommended
typedef struct {
uint64_t lower;
int64_t upper;
} duckdb_hugeint;
typedef struct {
uint64_t lower;
uint64_t upper;
} duckdb_uhugeint;
//! Decimals are composed of a width and a scale, and are stored in a hugeint
typedef struct {
uint8_t width;
uint8_t scale;
duckdb_hugeint value;
} duckdb_decimal;
//! A type holding information about the query execution progress
typedef struct {
double percentage;
uint64_t rows_processed;
uint64_t total_rows_to_process;
} duckdb_query_progress_type;
//! The internal representation of a VARCHAR (string_t). If the VARCHAR does not
//! exceed 12 characters, then we inline it. Otherwise, we inline a prefix for faster
//! string comparisons and store a pointer to the remaining characters. This is a non-
//! owning structure, i.e., it does not have to be freed.
typedef struct {
union {
struct {
uint32_t length;
char prefix[4];
char *ptr;
} pointer;
struct {
uint32_t length;
char inlined[12];
} inlined;
} value;
} duckdb_string_t;
//! The internal representation of a list metadata entry contains the list's offset in
//! the child vector, and its length. The parent vector holds these metadata entries,
//! whereas the child vector holds the data
typedef struct {
uint64_t offset;
uint64_t length;
} duckdb_list_entry;
//! A column consists of a pointer to its internal data. Don't operate on this type directly.
//! Instead, use functions such as duckdb_column_data, duckdb_nullmask_data,
//! duckdb_column_type, and duckdb_column_name, which take the result and the column index
//! as their parameters
typedef struct {
// deprecated, use duckdb_column_data
void *deprecated_data;
// deprecated, use duckdb_nullmask_data
bool *deprecated_nullmask;
// deprecated, use duckdb_column_type
duckdb_type deprecated_type;
// deprecated, use duckdb_column_name
char *deprecated_name;
void *internal_data;
} duckdb_column;
//! A vector to a specified column in a data chunk. Lives as long as the
//! data chunk lives, i.e., must not be destroyed.
typedef struct _duckdb_vector {
void *internal_ptr;
} * duckdb_vector;
//===--------------------------------------------------------------------===//
// Types (explicit freeing/destroying)
//===--------------------------------------------------------------------===//
//! Strings are composed of a char pointer and a size. You must free string.data
//! with `duckdb_free`.
typedef struct {
char *data;
idx_t size;
} duckdb_string;
//! BLOBs are composed of a byte pointer and a size. You must free blob.data
//! with `duckdb_free`.
typedef struct {
void *data;
idx_t size;
} duckdb_blob;
//! A query result consists of a pointer to its internal data.
//! Must be freed with 'duckdb_destroy_result'.
typedef struct {
// deprecated, use duckdb_column_count
idx_t deprecated_column_count;
// deprecated, use duckdb_row_count
idx_t deprecated_row_count;
// deprecated, use duckdb_rows_changed
idx_t deprecated_rows_changed;
// deprecated, use duckdb_column_*-family of functions
duckdb_column *deprecated_columns;
// deprecated, use duckdb_result_error
char *deprecated_error_message;
void *internal_data;
} duckdb_result;
//! A database object. Should be closed with `duckdb_close`.
typedef struct _duckdb_database {
void *internal_ptr;
} * duckdb_database;
//! A connection to a duckdb database. Must be closed with `duckdb_disconnect`.
typedef struct _duckdb_connection {
void *internal_ptr;
} * duckdb_connection;
//! A prepared statement is a parameterized query that allows you to bind parameters to it.
//! Must be destroyed with `duckdb_destroy_prepare`.
typedef struct _duckdb_prepared_statement {
void *internal_ptr;
} * duckdb_prepared_statement;
//! Extracted statements. Must be destroyed with `duckdb_destroy_extracted`.
typedef struct _duckdb_extracted_statements {
void *internal_ptr;
} * duckdb_extracted_statements;
//! The pending result represents an intermediate structure for a query that is not yet fully executed.
//! Must be destroyed with `duckdb_destroy_pending`.
typedef struct _duckdb_pending_result {
void *internal_ptr;
} * duckdb_pending_result;
//! The appender enables fast data loading into DuckDB.
//! Must be destroyed with `duckdb_appender_destroy`.
typedef struct _duckdb_appender {
void *internal_ptr;
} * duckdb_appender;
//! The table description allows querying info about the table.
//! Must be destroyed with `duckdb_table_description_destroy`.
typedef struct _duckdb_table_description {
void *internal_ptr;
} * duckdb_table_description;
//! Can be used to provide start-up options for the DuckDB instance.
//! Must be destroyed with `duckdb_destroy_config`.
typedef struct _duckdb_config {
void *internal_ptr;
} * duckdb_config;
//! Holds an internal logical type.
//! Must be destroyed with `duckdb_destroy_logical_type`.
typedef struct _duckdb_logical_type {
void *internal_ptr;
} * duckdb_logical_type;
//! Holds extra information used when registering a custom logical type.
//! Reserved for future use.
typedef struct _duckdb_create_type_info {
void *internal_ptr;
} * duckdb_create_type_info;
//! Contains a data chunk from a duckdb_result.
//! Must be destroyed with `duckdb_destroy_data_chunk`.
typedef struct _duckdb_data_chunk {
void *internal_ptr;
} * duckdb_data_chunk;
//! Holds a DuckDB value, which wraps a type.
//! Must be destroyed with `duckdb_destroy_value`.
typedef struct _duckdb_value {
void *internal_ptr;
} * duckdb_value;
//! Holds a recursive tree that matches the query plan.
typedef struct _duckdb_profiling_info {
void *internal_ptr;
} * duckdb_profiling_info;
//===--------------------------------------------------------------------===//
// C API Extension info
//===--------------------------------------------------------------------===//
//! Holds state during the C API extension intialization process
typedef struct _duckdb_extension_info {
void *internal_ptr;
} * duckdb_extension_info;
//===--------------------------------------------------------------------===//
// Function types
//===--------------------------------------------------------------------===//
//! Additional function info. When setting this info, it is necessary to pass a destroy-callback function.
typedef struct _duckdb_function_info {
void *internal_ptr;
} * duckdb_function_info;
//===--------------------------------------------------------------------===//
// Scalar function types
//===--------------------------------------------------------------------===//
//! A scalar function. Must be destroyed with `duckdb_destroy_scalar_function`.
typedef struct _duckdb_scalar_function {
void *internal_ptr;
} * duckdb_scalar_function;
//! A scalar function set. Must be destroyed with `duckdb_destroy_scalar_function_set`.
typedef struct _duckdb_scalar_function_set {
void *internal_ptr;
} * duckdb_scalar_function_set;
//! The main function of the scalar function.
typedef void (*duckdb_scalar_function_t)(duckdb_function_info info, duckdb_data_chunk input, duckdb_vector output);
//===--------------------------------------------------------------------===//
// Aggregate function types
//===--------------------------------------------------------------------===//
//! An aggregate function. Must be destroyed with `duckdb_destroy_aggregate_function`.
typedef struct _duckdb_aggregate_function {
void *internal_ptr;
} * duckdb_aggregate_function;
//! A aggregate function set. Must be destroyed with `duckdb_destroy_aggregate_function_set`.
typedef struct _duckdb_aggregate_function_set {
void *internal_ptr;
} * duckdb_aggregate_function_set;
//! Aggregate state
typedef struct _duckdb_aggregate_state {
void *internal_ptr;
} * duckdb_aggregate_state;
//! Returns the aggregate state size
typedef idx_t (*duckdb_aggregate_state_size)(duckdb_function_info info);
//! Initialize the aggregate state
typedef void (*duckdb_aggregate_init_t)(duckdb_function_info info, duckdb_aggregate_state state);
//! Destroy aggregate state (optional)
typedef void (*duckdb_aggregate_destroy_t)(duckdb_aggregate_state *states, idx_t count);
//! Update a set of aggregate states with new values
typedef void (*duckdb_aggregate_update_t)(duckdb_function_info info, duckdb_data_chunk input,
duckdb_aggregate_state *states);
//! Combine aggregate states
typedef void (*duckdb_aggregate_combine_t)(duckdb_function_info info, duckdb_aggregate_state *source,
duckdb_aggregate_state *target, idx_t count);
//! Finalize aggregate states into a result vector
typedef void (*duckdb_aggregate_finalize_t)(duckdb_function_info info, duckdb_aggregate_state *source,
duckdb_vector result, idx_t count, idx_t offset);
//===--------------------------------------------------------------------===//
// Table function types
//===--------------------------------------------------------------------===//
//! A table function. Must be destroyed with `duckdb_destroy_table_function`.
typedef struct _duckdb_table_function {
void *internal_ptr;
} * duckdb_table_function;
//! The bind info of the function. When setting this info, it is necessary to pass a destroy-callback function.
typedef struct _duckdb_bind_info {
void *internal_ptr;
} * duckdb_bind_info;
//! Additional function init info. When setting this info, it is necessary to pass a destroy-callback function.
typedef struct _duckdb_init_info {
void *internal_ptr;
} * duckdb_init_info;
//! The bind function of the table function.
typedef void (*duckdb_table_function_bind_t)(duckdb_bind_info info);
//! The (possibly thread-local) init function of the table function.
typedef void (*duckdb_table_function_init_t)(duckdb_init_info info);
//! The main function of the table function.
typedef void (*duckdb_table_function_t)(duckdb_function_info info, duckdb_data_chunk output);
//===--------------------------------------------------------------------===//
// Cast types
//===--------------------------------------------------------------------===//
//! A cast function. Must be destroyed with `duckdb_destroy_cast_function`.
typedef struct _duckdb_cast_function {
void *internal_ptr;
} * duckdb_cast_function;
typedef bool (*duckdb_cast_function_t)(duckdb_function_info info, idx_t count, duckdb_vector input,
duckdb_vector output);
//===--------------------------------------------------------------------===//
// Replacement scan types
//===--------------------------------------------------------------------===//
//! Additional replacement scan info. When setting this info, it is necessary to pass a destroy-callback function.
typedef struct _duckdb_replacement_scan_info {
void *internal_ptr;
} * duckdb_replacement_scan_info;
//! A replacement scan function that can be added to a database.
typedef void (*duckdb_replacement_callback_t)(duckdb_replacement_scan_info info, const char *table_name, void *data);
//===--------------------------------------------------------------------===//
// Arrow-related types
//===--------------------------------------------------------------------===//
//! Holds an arrow query result. Must be destroyed with `duckdb_destroy_arrow`.
typedef struct _duckdb_arrow {
void *internal_ptr;
} * duckdb_arrow;
//! Holds an arrow array stream. Must be destroyed with `duckdb_destroy_arrow_stream`.
typedef struct _duckdb_arrow_stream {
void *internal_ptr;
} * duckdb_arrow_stream;
//! Holds an arrow schema. Remember to release the respective ArrowSchema object.
typedef struct _duckdb_arrow_schema {
void *internal_ptr;
} * duckdb_arrow_schema;
//! Holds an arrow array. Remember to release the respective ArrowArray object.
typedef struct _duckdb_arrow_array {
void *internal_ptr;
} * duckdb_arrow_array;
//===--------------------------------------------------------------------===//
// DuckDB extension access
//===--------------------------------------------------------------------===//
//! Passed to C API extension as parameter to the entrypoint
struct duckdb_extension_access {
//! Indicate that an error has occurred
void (*set_error)(duckdb_extension_info info, const char *error);
//! Fetch the database from duckdb to register extensions to
duckdb_database *(*get_database)(duckdb_extension_info info);
//! Fetch the API
const void *(*get_api)(duckdb_extension_info info, const char *version);
};
//===--------------------------------------------------------------------===//
// Functions
//===--------------------------------------------------------------------===//
//===--------------------------------------------------------------------===//
// Open Connect
//===--------------------------------------------------------------------===//
/*!
Creates a new database or opens an existing database file stored at the given path.
If no path is given a new in-memory database is created instead.
The instantiated database should be closed with 'duckdb_close'.
* @param path Path to the database file on disk, or `nullptr` or `:memory:` to open an in-memory database.
* @param out_database The result database object.
* @return `DuckDBSuccess` on success or `DuckDBError` on failure.
*/
DUCKDB_API duckdb_state duckdb_open(const char *path, duckdb_database *out_database);
/*!
Extended version of duckdb_open. Creates a new database or opens an existing database file stored at the given path.
The instantiated database should be closed with 'duckdb_close'.
* @param path Path to the database file on disk, or `nullptr` or `:memory:` to open an in-memory database.
* @param out_database The result database object.
* @param config (Optional) configuration used to start up the database system.
* @param out_error If set and the function returns DuckDBError, this will contain the reason why the start-up failed.
Note that the error must be freed using `duckdb_free`.
* @return `DuckDBSuccess` on success or `DuckDBError` on failure.
*/
DUCKDB_API duckdb_state duckdb_open_ext(const char *path, duckdb_database *out_database, duckdb_config config,
char **out_error);
/*!
Closes the specified database and de-allocates all memory allocated for that database.
This should be called after you are done with any database allocated through `duckdb_open` or `duckdb_open_ext`.
Note that failing to call `duckdb_close` (in case of e.g. a program crash) will not cause data corruption.
Still, it is recommended to always correctly close a database object after you are done with it.
* @param database The database object to shut down.
*/
DUCKDB_API void duckdb_close(duckdb_database *database);
/*!
Opens a connection to a database. Connections are required to query the database, and store transactional state
associated with the connection.
The instantiated connection should be closed using 'duckdb_disconnect'.
* @param database The database file to connect to.
* @param out_connection The result connection object.
* @return `DuckDBSuccess` on success or `DuckDBError` on failure.
*/
DUCKDB_API duckdb_state duckdb_connect(duckdb_database database, duckdb_connection *out_connection);
/*!
Interrupt running query
* @param connection The connection to interrupt
*/
DUCKDB_API void duckdb_interrupt(duckdb_connection connection);
/*!
Get progress of the running query
* @param connection The working connection
* @return -1 if no progress or a percentage of the progress
*/
DUCKDB_API duckdb_query_progress_type duckdb_query_progress(duckdb_connection connection);
/*!
Closes the specified connection and de-allocates all memory allocated for that connection.
* @param connection The connection to close.
*/
DUCKDB_API void duckdb_disconnect(duckdb_connection *connection);
/*!
Returns the version of the linked DuckDB, with a version postfix for dev versions
Usually used for developing C extensions that must return this for a compatibility check.
*/
DUCKDB_API const char *duckdb_library_version();
//===--------------------------------------------------------------------===//
// Configuration
//===--------------------------------------------------------------------===//
/*!
Initializes an empty configuration object that can be used to provide start-up options for the DuckDB instance
through `duckdb_open_ext`.
The duckdb_config must be destroyed using 'duckdb_destroy_config'
This will always succeed unless there is a malloc failure.
Note that `duckdb_destroy_config` should always be called on the resulting config, even if the function returns
`DuckDBError`.
* @param out_config The result configuration object.
* @return `DuckDBSuccess` on success or `DuckDBError` on failure.
*/
DUCKDB_API duckdb_state duckdb_create_config(duckdb_config *out_config);
/*!
This returns the total amount of configuration options available for usage with `duckdb_get_config_flag`.
This should not be called in a loop as it internally loops over all the options.
* @return The amount of config options available.
*/
DUCKDB_API size_t duckdb_config_count();
/*!
Obtains a human-readable name and description of a specific configuration option. This can be used to e.g.
display configuration options. This will succeed unless `index` is out of range (i.e. `>= duckdb_config_count`).
The result name or description MUST NOT be freed.
* @param index The index of the configuration option (between 0 and `duckdb_config_count`)
* @param out_name A name of the configuration flag.
* @param out_description A description of the configuration flag.
* @return `DuckDBSuccess` on success or `DuckDBError` on failure.
*/
DUCKDB_API duckdb_state duckdb_get_config_flag(size_t index, const char **out_name, const char **out_description);
/*!
Sets the specified option for the specified configuration. The configuration option is indicated by name.
To obtain a list of config options, see `duckdb_get_config_flag`.
In the source code, configuration options are defined in `config.cpp`.
This can fail if either the name is invalid, or if the value provided for the option is invalid.
* @param config The configuration object to set the option on.
* @param name The name of the configuration flag to set.
* @param option The value to set the configuration flag to.
* @return `DuckDBSuccess` on success or `DuckDBError` on failure.
*/
DUCKDB_API duckdb_state duckdb_set_config(duckdb_config config, const char *name, const char *option);
/*!
Destroys the specified configuration object and de-allocates all memory allocated for the object.
* @param config The configuration object to destroy.
*/
DUCKDB_API void duckdb_destroy_config(duckdb_config *config);
//===--------------------------------------------------------------------===//
// Query Execution
//===--------------------------------------------------------------------===//
/*!
Executes a SQL query within a connection and stores the full (materialized) result in the out_result pointer.
If the query fails to execute, DuckDBError is returned and the error message can be retrieved by calling
`duckdb_result_error`.
Note that after running `duckdb_query`, `duckdb_destroy_result` must be called on the result object even if the
query fails, otherwise the error stored within the result will not be freed correctly.
* @param connection The connection to perform the query in.
* @param query The SQL query to run.
* @param out_result The query result.
* @return `DuckDBSuccess` on success or `DuckDBError` on failure.
*/
DUCKDB_API duckdb_state duckdb_query(duckdb_connection connection, const char *query, duckdb_result *out_result);
/*!
Closes the result and de-allocates all memory allocated for that connection.
* @param result The result to destroy.
*/
DUCKDB_API void duckdb_destroy_result(duckdb_result *result);
/*!
Returns the column name of the specified column. The result should not need to be freed; the column names will
automatically be destroyed when the result is destroyed.
Returns `NULL` if the column is out of range.
* @param result The result object to fetch the column name from.
* @param col The column index.
* @return The column name of the specified column.
*/
DUCKDB_API const char *duckdb_column_name(duckdb_result *result, idx_t col);
/*!
Returns the column type of the specified column.
Returns `DUCKDB_TYPE_INVALID` if the column is out of range.
* @param result The result object to fetch the column type from.
* @param col The column index.
* @return The column type of the specified column.
*/
DUCKDB_API duckdb_type duckdb_column_type(duckdb_result *result, idx_t col);
/*!
Returns the statement type of the statement that was executed
* @param result The result object to fetch the statement type from.
* @return duckdb_statement_type value or DUCKDB_STATEMENT_TYPE_INVALID
*/
DUCKDB_API duckdb_statement_type duckdb_result_statement_type(duckdb_result result);
/*!
Returns the logical column type of the specified column.
The return type of this call should be destroyed with `duckdb_destroy_logical_type`.
Returns `NULL` if the column is out of range.
* @param result The result object to fetch the column type from.
* @param col The column index.
* @return The logical column type of the specified column.
*/
DUCKDB_API duckdb_logical_type duckdb_column_logical_type(duckdb_result *result, idx_t col);
/*!
Returns the number of columns present in a the result object.
* @param result The result object.
* @return The number of columns present in the result object.
*/
DUCKDB_API idx_t duckdb_column_count(duckdb_result *result);
#ifndef DUCKDB_API_NO_DEPRECATED
/*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
Returns the number of rows present in the result object.
* @param result The result object.
* @return The number of rows present in the result object.
*/
DUCKDB_API idx_t duckdb_row_count(duckdb_result *result);
#endif
/*!
Returns the number of rows changed by the query stored in the result. This is relevant only for INSERT/UPDATE/DELETE
queries. For other queries the rows_changed will be 0.
* @param result The result object.
* @return The number of rows changed.
*/
DUCKDB_API idx_t duckdb_rows_changed(duckdb_result *result);
#ifndef DUCKDB_API_NO_DEPRECATED
/*!
**DEPRECATED**: Prefer using `duckdb_result_get_chunk` instead.
Returns the data of a specific column of a result in columnar format.
The function returns a dense array which contains the result data. The exact type stored in the array depends on the
corresponding duckdb_type (as provided by `duckdb_column_type`). For the exact type by which the data should be
accessed, see the comments in [the types section](types) or the `DUCKDB_TYPE` enum.
For example, for a column of type `DUCKDB_TYPE_INTEGER`, rows can be accessed in the following manner:
```c
int32_t *data = (int32_t *) duckdb_column_data(&result, 0);
printf("Data for row %d: %d\n", row, data[row]);
```
* @param result The result object to fetch the column data from.
* @param col The column index.
* @return The column data of the specified column.
*/
DUCKDB_API void *duckdb_column_data(duckdb_result *result, idx_t col);
/*!
**DEPRECATED**: Prefer using `duckdb_result_get_chunk` instead.
Returns the nullmask of a specific column of a result in columnar format. The nullmask indicates for every row
whether or not the corresponding row is `NULL`. If a row is `NULL`, the values present in the array provided
by `duckdb_column_data` are undefined.
```c
int32_t *data = (int32_t *) duckdb_column_data(&result, 0);
bool *nullmask = duckdb_nullmask_data(&result, 0);
if (nullmask[row]) {
printf("Data for row %d: NULL\n", row);
} else {
printf("Data for row %d: %d\n", row, data[row]);
}
```
* @param result The result object to fetch the nullmask from.
* @param col The column index.
* @return The nullmask of the specified column.
*/
DUCKDB_API bool *duckdb_nullmask_data(duckdb_result *result, idx_t col);
#endif
/*!
Returns the error message contained within the result. The error is only set if `duckdb_query` returns `DuckDBError`.
The result of this function must not be freed. It will be cleaned up when `duckdb_destroy_result` is called.
* @param result The result object to fetch the error from.
* @return The error of the result.
*/
DUCKDB_API const char *duckdb_result_error(duckdb_result *result);
/*!
Returns the result error type contained within the result. The error is only set if `duckdb_query` returns
`DuckDBError`.
* @param result The result object to fetch the error from.
* @return The error type of the result.
*/
DUCKDB_API duckdb_error_type duckdb_result_error_type(duckdb_result *result);
//===--------------------------------------------------------------------===//
// Result Functions
//===--------------------------------------------------------------------===//
#ifndef DUCKDB_API_NO_DEPRECATED
/*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
Fetches a data chunk from the duckdb_result. This function should be called repeatedly until the result is exhausted.
The result must be destroyed with `duckdb_destroy_data_chunk`.
This function supersedes all `duckdb_value` functions, as well as the `duckdb_column_data` and `duckdb_nullmask_data`
functions. It results in significantly better performance, and should be preferred in newer code-bases.
If this function is used, none of the other result functions can be used and vice versa (i.e. this function cannot be
mixed with the legacy result functions).
Use `duckdb_result_chunk_count` to figure out how many chunks there are in the result.
* @param result The result object to fetch the data chunk from.
* @param chunk_index The chunk index to fetch from.
* @return The resulting data chunk. Returns `NULL` if the chunk index is out of bounds.
*/
DUCKDB_API duckdb_data_chunk duckdb_result_get_chunk(duckdb_result result, idx_t chunk_index);
/*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
Checks if the type of the internal result is StreamQueryResult.
* @param result The result object to check.
* @return Whether or not the result object is of the type StreamQueryResult
*/
DUCKDB_API bool duckdb_result_is_streaming(duckdb_result result);
/*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
Returns the number of data chunks present in the result.
* @param result The result object
* @return Number of data chunks present in the result.
*/
DUCKDB_API idx_t duckdb_result_chunk_count(duckdb_result result);
#endif
/*!
Returns the return_type of the given result, or DUCKDB_RETURN_TYPE_INVALID on error
* @param result The result object
* @return The return_type
*/
DUCKDB_API duckdb_result_type duckdb_result_return_type(duckdb_result result);