1//===----------------------------------------------------------------------===//
2// DuckDB
3//
4// duckdb/main/capi/capi_internal.hpp
5//
6//
7//===----------------------------------------------------------------------===//
8
9#pragma once
10
11#include "duckdb.h"
12#include "duckdb.hpp"
13#include "duckdb/common/types.hpp"
14#include "duckdb/common/types/data_chunk.hpp"
15#include "duckdb/main/appender.hpp"
16#include "duckdb/common/arrow/arrow_options.hpp"
17
18#include <cstring>
19#include <cassert>
20
21#ifdef _WIN32
22#ifndef strdup
23#define strdup _strdup
24#endif
25#endif
26
27namespace duckdb {
28
29struct DatabaseData {
30 unique_ptr<DuckDB> database;
31};
32
33struct PreparedStatementWrapper {
34 unique_ptr<PreparedStatement> statement;
35 vector<Value> values;
36};
37
38struct ExtractStatementsWrapper {
39 vector<unique_ptr<SQLStatement>> statements;
40 string error;
41};
42
43struct PendingStatementWrapper {
44 unique_ptr<PendingQueryResult> statement;
45 bool allow_streaming;
46};
47
48struct ArrowResultWrapper {
49 unique_ptr<MaterializedQueryResult> result;
50 unique_ptr<DataChunk> current_chunk;
51 ArrowOptions options;
52};
53
54struct AppenderWrapper {
55 unique_ptr<Appender> appender;
56 string error;
57};
58
59enum class CAPIResultSetType : uint8_t {
60 CAPI_RESULT_TYPE_NONE = 0,
61 CAPI_RESULT_TYPE_MATERIALIZED,
62 CAPI_RESULT_TYPE_STREAMING,
63 CAPI_RESULT_TYPE_DEPRECATED
64};
65
66struct DuckDBResultData {
67 //! The underlying query result
68 unique_ptr<QueryResult> result;
69 // Results can only use either the new API or the old API, not a mix of the two
70 // They start off as "none" and switch to one or the other when an API method is used
71 CAPIResultSetType result_set_type;
72};
73
74duckdb_type ConvertCPPTypeToC(const LogicalType &type);
75LogicalTypeId ConvertCTypeToCPP(duckdb_type c_type);
76idx_t GetCTypeSize(duckdb_type type);
77duckdb_state duckdb_translate_result(unique_ptr<QueryResult> result, duckdb_result *out);
78bool deprecated_materialize_result(duckdb_result *result);
79
80} // namespace duckdb
81