1 | #include "duckdb/common/types/null_value.hpp" |
---|---|
2 | #include "duckdb/common/types/string_type.hpp" |
3 | |
4 | #include "duckdb/common/exception.hpp" |
5 | |
6 | #include <cstring> |
7 | |
8 | using namespace std; |
9 | |
10 | namespace duckdb { |
11 | |
12 | bool IsNullValue(data_ptr_t ptr, TypeId type) { |
13 | data_t data[100]; |
14 | SetNullValue(data, type); |
15 | return memcmp(ptr, data, GetTypeIdSize(type)) == 0; |
16 | } |
17 | |
18 | //! Writes NullValue<T> value of a specific type to a memory address |
19 | void SetNullValue(data_ptr_t ptr, TypeId type) { |
20 | switch (type) { |
21 | case TypeId::BOOL: |
22 | case TypeId::INT8: |
23 | *((int8_t *)ptr) = NullValue<int8_t>(); |
24 | break; |
25 | case TypeId::INT16: |
26 | *((int16_t *)ptr) = NullValue<int16_t>(); |
27 | break; |
28 | case TypeId::INT32: |
29 | *((int32_t *)ptr) = NullValue<int32_t>(); |
30 | break; |
31 | case TypeId::INT64: |
32 | *((int64_t *)ptr) = NullValue<int64_t>(); |
33 | break; |
34 | case TypeId::FLOAT: |
35 | *((float *)ptr) = NullValue<float>(); |
36 | break; |
37 | case TypeId::DOUBLE: |
38 | *((double *)ptr) = NullValue<double>(); |
39 | break; |
40 | case TypeId::VARCHAR: |
41 | *((string_t *)ptr) = string_t(NullValue<const char *>()); |
42 | break; |
43 | default: |
44 | throw InvalidTypeException(type, "Unsupported type for SetNullValue!"); |
45 | } |
46 | } |
47 | |
48 | } // namespace duckdb |
49 |