1 | #include "duckdb/main/capi/cast/utils.hpp" |
2 | |
3 | namespace duckdb { |
4 | |
5 | template <> |
6 | duckdb_decimal FetchDefaultValue::Operation() { |
7 | duckdb_decimal result; |
8 | result.scale = 0; |
9 | result.width = 0; |
10 | result.value = {.lower: 0, .upper: 0}; |
11 | return result; |
12 | } |
13 | |
14 | template <> |
15 | date_t FetchDefaultValue::Operation() { |
16 | date_t result; |
17 | result.days = 0; |
18 | return result; |
19 | } |
20 | |
21 | template <> |
22 | dtime_t FetchDefaultValue::Operation() { |
23 | dtime_t result; |
24 | result.micros = 0; |
25 | return result; |
26 | } |
27 | |
28 | template <> |
29 | timestamp_t FetchDefaultValue::Operation() { |
30 | timestamp_t result; |
31 | result.value = 0; |
32 | return result; |
33 | } |
34 | |
35 | template <> |
36 | interval_t FetchDefaultValue::Operation() { |
37 | interval_t result; |
38 | result.months = 0; |
39 | result.days = 0; |
40 | result.micros = 0; |
41 | return result; |
42 | } |
43 | |
44 | template <> |
45 | char *FetchDefaultValue::Operation() { |
46 | return nullptr; |
47 | } |
48 | |
49 | template <> |
50 | duckdb_string FetchDefaultValue::Operation() { |
51 | duckdb_string result; |
52 | result.data = nullptr; |
53 | result.size = 0; |
54 | return result; |
55 | } |
56 | |
57 | template <> |
58 | duckdb_blob FetchDefaultValue::Operation() { |
59 | duckdb_blob result; |
60 | result.data = nullptr; |
61 | result.size = 0; |
62 | return result; |
63 | } |
64 | |
65 | //===--------------------------------------------------------------------===// |
66 | // Blob Casts |
67 | //===--------------------------------------------------------------------===// |
68 | |
69 | template <> |
70 | bool FromCBlobCastWrapper::Operation(duckdb_blob input, duckdb_string &result) { |
71 | string_t input_str(const_char_ptr_cast(src: input.data), input.size); |
72 | return ToCStringCastWrapper<duckdb::CastFromBlob>::template Operation<string_t, duckdb_string>(input: input_str, result); |
73 | } |
74 | |
75 | } // namespace duckdb |
76 | |
77 | bool CanUseDeprecatedFetch(duckdb_result *result, idx_t col, idx_t row) { |
78 | if (!result) { |
79 | return false; |
80 | } |
81 | if (!duckdb::deprecated_materialize_result(result)) { |
82 | return false; |
83 | } |
84 | if (col >= result->__deprecated_column_count || row >= result->__deprecated_row_count) { |
85 | return false; |
86 | } |
87 | return true; |
88 | } |
89 | |
90 | bool CanFetchValue(duckdb_result *result, idx_t col, idx_t row) { |
91 | if (!CanUseDeprecatedFetch(result, col, row)) { |
92 | return false; |
93 | } |
94 | if (result->__deprecated_columns[col].__deprecated_nullmask[row]) { |
95 | return false; |
96 | } |
97 | return true; |
98 | } |
99 | |