forked from alitrack/duckdb_fdw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
duckdb.h
3122 lines (2424 loc) · 111 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
//
//
//===----------------------------------------------------------------------===//
#pragma once
//! duplicate of duckdb/main/winapi.hpp
#ifndef DUCKDB_API
#ifdef _WIN32
#if defined(DUCKDB_BUILD_LIBRARY) && !defined(DUCKDB_BUILD_LOADABLE_EXTENSION)
#define DUCKDB_API __declspec(dllexport)
#else
#define DUCKDB_API __declspec(dllimport)
#endif
#else
#define DUCKDB_API
#endif
#endif
//! duplicate of duckdb/main/winapi.hpp
#ifndef DUCKDB_EXTENSION_API
#ifdef _WIN32
#ifdef DUCKDB_BUILD_LOADABLE_EXTENSION
#define DUCKDB_EXTENSION_API __declspec(dllexport)
#else
#define DUCKDB_EXTENSION_API
#endif
#else
#define DUCKDB_EXTENSION_API __attribute__((visibility("default")))
#endif
#endif
//! In the future, we are planning to move extension functions to a separate header. For now you can set the define
//! below to remove the functions that are planned to be moved out of this header.
// #define DUCKDB_NO_EXTENSION_FUNCTIONS
//! Set the define below to remove all functions that are deprecated or planned to be deprecated
// #define DUCKDB_API_NO_DEPRECATED
//! API versions
//! If no explicit API version is defined, the latest API version is used.
//! Note that using older API versions (i.e. not using DUCKDB_API_LATEST) is deprecated.
//! These will not be supported long-term, and will be removed in future versions.
#ifndef DUCKDB_API_0_3_1
#define DUCKDB_API_0_3_1 1
#endif
#ifndef DUCKDB_API_0_3_2
#define DUCKDB_API_0_3_2 2
#endif
#ifndef DUCKDB_API_LATEST
#define DUCKDB_API_LATEST DUCKDB_API_0_3_2
#endif
#ifndef DUCKDB_API_VERSION
#define DUCKDB_API_VERSION DUCKDB_API_LATEST
#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,
} duckdb_type;
//! An enum over the returned state of different functions.
typedef enum { DuckDBSuccess = 0, DuckDBError = 1 } duckdb_state;
//! An enum over the pending state of a pending query result.
typedef enum {
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_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_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;
//===--------------------------------------------------------------------===//
// 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 {
#if DUCKDB_API_VERSION < DUCKDB_API_0_3_2
void *data;
bool *nullmask;
duckdb_type type;
char *name;
#else
// 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;
#endif
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 *__vctr;
} * 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 {
#if DUCKDB_API_VERSION < DUCKDB_API_0_3_2
idx_t column_count;
idx_t row_count;
idx_t rows_changed;
duckdb_column *columns;
char *error_message;
#else
// 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;
#endif
void *internal_data;
} duckdb_result;
//! A database object. Should be closed with `duckdb_close`.
typedef struct _duckdb_database {
void *__db;
} * duckdb_database;
//! A connection to a duckdb database. Must be closed with `duckdb_disconnect`.
typedef struct _duckdb_connection {
void *__conn;
} * 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 *__prep;
} * duckdb_prepared_statement;
//! Extracted statements. Must be destroyed with `duckdb_destroy_extracted`.
typedef struct _duckdb_extracted_statements {
void *__extrac;
} * 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 *__pend;
} * duckdb_pending_result;
//! The appender enables fast data loading into DuckDB.
//! Must be destroyed with `duckdb_appender_destroy`.
typedef struct _duckdb_appender {
void *__appn;
} * duckdb_appender;
//! Can be used to provide start-up options for the DuckDB instance.
//! Must be destroyed with `duckdb_destroy_config`.
typedef struct _duckdb_config {
void *__cnfg;
} * duckdb_config;
//! Holds an internal logical type.
//! Must be destroyed with `duckdb_destroy_logical_type`.
typedef struct _duckdb_logical_type {
void *__lglt;
} * duckdb_logical_type;
//! Contains a data chunk from a duckdb_result.
//! Must be destroyed with `duckdb_destroy_data_chunk`.
typedef struct _duckdb_data_chunk {
void *__dtck;
} * duckdb_data_chunk;
//! Holds a DuckDB value, which wraps a type.
//! Must be destroyed with `duckdb_destroy_value`.
typedef struct _duckdb_value {
void *__val;
} * duckdb_value;
//===--------------------------------------------------------------------===//
// Table function types
//===--------------------------------------------------------------------===//
#ifndef DUCKDB_NO_EXTENSION_FUNCTIONS
//! A table function. Must be destroyed with `duckdb_destroy_table_function`.
typedef void *duckdb_table_function;
//! The bind info of the function. When setting this info, it is necessary to pass a destroy-callback function.
typedef void *duckdb_bind_info;
//! Additional function init info. When setting this info, it is necessary to pass a destroy-callback function.
typedef void *duckdb_init_info;
//! Additional function info. When setting this info, it is necessary to pass a destroy-callback function.
typedef void *duckdb_function_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);
//===--------------------------------------------------------------------===//
// Replacement scan types
//===--------------------------------------------------------------------===//
//! Additional replacement scan info. When setting this info, it is necessary to pass a destroy-callback function.
typedef void *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);
#endif
//===--------------------------------------------------------------------===//
// Arrow-related types
//===--------------------------------------------------------------------===//
//! Holds an arrow query result. Must be destroyed with `duckdb_destroy_arrow`.
typedef struct _duckdb_arrow {
void *__arrw;
} * duckdb_arrow;
//! Holds an arrow array stream. Must be destroyed with `duckdb_destroy_arrow_stream`.
typedef struct _duckdb_arrow_stream {
void *__arrwstr;
} * duckdb_arrow_stream;
//! Holds an arrow schema. Remember to release the respective ArrowSchema object.
typedef struct _duckdb_arrow_schema {
void *__arrs;
} * duckdb_arrow_schema;
//! Holds an arrow array. Remember to release the respective ArrowArray object.
typedef struct _duckdb_arrow_array {
void *__arra;
} * duckdb_arrow_array;
//===--------------------------------------------------------------------===//
// 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'.
* path: Path to the database file on disk, or `nullptr` or `:memory:` to open an in-memory database.
* out_database: The result database object.
* returns: `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'.
* path: Path to the database file on disk, or `nullptr` or `:memory:` to open an in-memory database.
* out_database: The result database object.
* config: (Optional) configuration used to start up the database system.
* 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`.
* returns: `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.
* 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'.
* database: The database file to connect to.
* out_connection: The result connection object.
* returns: `DuckDBSuccess` on success or `DuckDBError` on failure.
*/
DUCKDB_API duckdb_state duckdb_connect(duckdb_database database, duckdb_connection *out_connection);
/*!
Interrupt running query
* connection: The connection to interrupt
*/
DUCKDB_API void duckdb_interrupt(duckdb_connection connection);
/*!
Get progress of the running query
* connection: The working connection
* returns: -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.
* 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.
* out_config: The result configuration object.
* returns: `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.
* returns: 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.
* index: The index of the configuration option (between 0 and `duckdb_config_count`)
* out_name: A name of the configuration flag.
* out_description: A description of the configuration flag.
* returns: `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.
* duckdb_config: The configuration object to set the option on.
* name: The name of the configuration flag to set.
* option: The value to set the configuration flag to.
* returns: `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.
* 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.
* connection: The connection to perform the query in.
* query: The SQL query to run.
* out_result: The query result.
* returns: `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.
* 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.
* result: The result object to fetch the column name from.
* col: The column index.
* returns: 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.
* result: The result object to fetch the column type from.
* col: The column index.
* returns: 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
* result: The result object to fetch the statement type from.
* returns: 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.
* result: The result object to fetch the column type from.
* col: The column index.
* returns: 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.
* result: The result object.
* returns: 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.
* result: The result object.
* returns: 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.
* result: The result object.
* returns: 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]);
```
* result: The result object to fetch the column data from.
* col: The column index.
* returns: 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]);
}
```
* result: The result object to fetch the nullmask from.
* col: The column index.
* returns: 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.
* result: The result object to fetch the error from.
* returns: The error of the result.
*/
DUCKDB_API const char *duckdb_result_error(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.
* result: The result object to fetch the data chunk from.
* chunk_index: The chunk index to fetch from.
* returns: 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.
* result: The result object to check.
* returns: 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.
* result: The result object
* returns: 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
* result: The result object
* returns: The return_type
*/
DUCKDB_API duckdb_result_type duckdb_result_return_type(duckdb_result result);
#ifndef DUCKDB_API_NO_DEPRECATED
//===--------------------------------------------------------------------===//
// Safe fetch functions
//===--------------------------------------------------------------------===//
// These functions will perform conversions if necessary.
// On failure (e.g. if conversion cannot be performed or if the value is NULL) a default value is returned.
// Note that these functions are slow since they perform bounds checking and conversion
// For fast access of values prefer using `duckdb_result_get_chunk`
/*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
* returns: The boolean value at the specified location, or false if the value cannot be converted.
*/
DUCKDB_API bool duckdb_value_boolean(duckdb_result *result, idx_t col, idx_t row);
/*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
* returns: The int8_t value at the specified location, or 0 if the value cannot be converted.
*/
DUCKDB_API int8_t duckdb_value_int8(duckdb_result *result, idx_t col, idx_t row);
/*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
* returns: The int16_t value at the specified location, or 0 if the value cannot be converted.
*/
DUCKDB_API int16_t duckdb_value_int16(duckdb_result *result, idx_t col, idx_t row);
/*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
* returns: The int32_t value at the specified location, or 0 if the value cannot be converted.
*/
DUCKDB_API int32_t duckdb_value_int32(duckdb_result *result, idx_t col, idx_t row);
/*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
* returns: The int64_t value at the specified location, or 0 if the value cannot be converted.
*/
DUCKDB_API int64_t duckdb_value_int64(duckdb_result *result, idx_t col, idx_t row);
/*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
* returns: The duckdb_hugeint value at the specified location, or 0 if the value cannot be converted.
*/
DUCKDB_API duckdb_hugeint duckdb_value_hugeint(duckdb_result *result, idx_t col, idx_t row);
/*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
* returns: The duckdb_uhugeint value at the specified location, or 0 if the value cannot be converted.
*/
DUCKDB_API duckdb_uhugeint duckdb_value_uhugeint(duckdb_result *result, idx_t col, idx_t row);
/*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
* returns: The duckdb_decimal value at the specified location, or 0 if the value cannot be converted.
*/
DUCKDB_API duckdb_decimal duckdb_value_decimal(duckdb_result *result, idx_t col, idx_t row);
/*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
* returns: The uint8_t value at the specified location, or 0 if the value cannot be converted.
*/
DUCKDB_API uint8_t duckdb_value_uint8(duckdb_result *result, idx_t col, idx_t row);
/*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
* returns: The uint16_t value at the specified location, or 0 if the value cannot be converted.
*/
DUCKDB_API uint16_t duckdb_value_uint16(duckdb_result *result, idx_t col, idx_t row);
/*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
* returns: The uint32_t value at the specified location, or 0 if the value cannot be converted.
*/
DUCKDB_API uint32_t duckdb_value_uint32(duckdb_result *result, idx_t col, idx_t row);
/*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
* returns: The uint64_t value at the specified location, or 0 if the value cannot be converted.
*/
DUCKDB_API uint64_t duckdb_value_uint64(duckdb_result *result, idx_t col, idx_t row);
/*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
* returns: The float value at the specified location, or 0 if the value cannot be converted.
*/
DUCKDB_API float duckdb_value_float(duckdb_result *result, idx_t col, idx_t row);
/*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
* returns: The double value at the specified location, or 0 if the value cannot be converted.
*/
DUCKDB_API double duckdb_value_double(duckdb_result *result, idx_t col, idx_t row);
/*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
* returns: The duckdb_date value at the specified location, or 0 if the value cannot be converted.
*/
DUCKDB_API duckdb_date duckdb_value_date(duckdb_result *result, idx_t col, idx_t row);
/*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
* returns: The duckdb_time value at the specified location, or 0 if the value cannot be converted.
*/
DUCKDB_API duckdb_time duckdb_value_time(duckdb_result *result, idx_t col, idx_t row);
/*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
* returns: The duckdb_timestamp value at the specified location, or 0 if the value cannot be converted.
*/
DUCKDB_API duckdb_timestamp duckdb_value_timestamp(duckdb_result *result, idx_t col, idx_t row);
/*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
* returns: The duckdb_interval value at the specified location, or 0 if the value cannot be converted.
*/
DUCKDB_API duckdb_interval duckdb_value_interval(duckdb_result *result, idx_t col, idx_t row);
/*!
* DEPRECATED: use duckdb_value_string instead. This function does not work correctly if the string contains null bytes.
* returns: The text value at the specified location as a null-terminated string, or nullptr if the value cannot be
converted. The result must be freed with `duckdb_free`.
*/
DUCKDB_API char *duckdb_value_varchar(duckdb_result *result, idx_t col, idx_t row);
/*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
* returns: The string value at the specified location. Attempts to cast the result value to string.
* No support for nested types, and for other complex types.
* The resulting field "string.data" must be freed with `duckdb_free.`