boost_sqlite 1
A sqlite C++ library
Loading...
Searching...
No Matches
value.hpp
1// Copyright (c) 2022 Klemens D. Morgenstern
2//
3// Distributed under the Boost Software License, Version 1.0. (See accompanying
4// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5#ifndef BOOST_SQLITE_VALUE_HPP
6#define BOOST_SQLITE_VALUE_HPP
7
8#include <boost/sqlite/detail/config.hpp>
9#include <boost/sqlite/blob.hpp>
10#include <boost/sqlite/cstring_ref.hpp>
11
12
13BOOST_SQLITE_BEGIN_NAMESPACE
14
20enum class value_type
21{
23 integer = SQLITE_INTEGER,
25 floating = SQLITE_FLOAT,
27 text = SQLITE_TEXT,
29 blob = SQLITE_BLOB,
31 null = SQLITE_NULL,
32};
33
38struct value
39{
42 {
43 return static_cast<value_type>(sqlite3_value_type(value_));
44 }
46 int subtype() const
47 {
48 return sqlite3_value_subtype(value_);
49 }
51 bool is_null() const
52 {
53 return type() == value_type::null;
54 }
56 explicit operator bool () const
57 {
58 return type() != value_type::null;
59 }
61 int get_int() const
62 {
63 return sqlite3_value_int(value_);
64 }
66 sqlite3_int64 get_int64() const
67 {
68 return sqlite3_value_int64(value_);
69 }
71 double get_double() const
72 {
73 return sqlite3_value_double(value_);
74 }
76 BOOST_SQLITE_DECL
79 BOOST_SQLITE_DECL
81
83 value_type numeric_type() const{return static_cast<value_type>(sqlite3_value_numeric_type(value_));}
84
85#if SQLITE_VERSION_NUMBER >= 3032000
87 bool nochange() const {return 0 != sqlite3_value_nochange(value_);}
88#endif
89
90#if SQLITE_VERSION_NUMBER >= 3031000
92 bool from_bind() const {return 0 != sqlite3_value_frombind(value_);}
93#endif
95 explicit value(sqlite3_value * value_) noexcept : value_(value_) {}
96
98 using handle_type = sqlite3_value *;
100 handle_type handle() const {return value_;}
101 handle_type & handle() {return value_;}
102
103#if SQLITE_VERSION_NUMBER >= 3020000
106 template<typename T>
107 T * get_pointer() {return static_cast<T*>(sqlite3_value_pointer(value_, typeid(T).name()));}
108#endif
109 private:
110 sqlite3_value * value_ = nullptr;
111};
112
113static_assert(sizeof(value) == sizeof(sqlite3_value*), "value must be same as sqlite3_value* pointer");
114
115BOOST_SQLITE_END_NAMESPACE
116
117#endif //BOOST_SQLITE_VALUE_HPP
value_type
The type of a value.
Definition value.hpp:21
@ integer
An integral value.
@ text
A textual value.
@ floating
A floating piont value.
a view to a binary large object
Definition blob.hpp:21
An object that owns a binary large object.
Definition blob.hpp:48
Small wrapper for a null-terminated string that can be directly passed to C APIS.
A holder for a sqlite values used for internal APIs.
Definition value.hpp:39
bool from_bind() const
True if value originated from a bound parameter.
Definition value.hpp:92
sqlite3_int64 get_int64() const
Returns the value as an int64.
Definition value.hpp:66
double get_double() const
Returns the value as an double.
Definition value.hpp:71
bool nochange() const
True if the column is unchanged in an UPDATE against a virtual table.
Definition value.hpp:87
sqlite3_value * handle_type
The handle of the value.
Definition value.hpp:98
cstring_ref get_text() const
Returns the value as text, i.e. a string_view. Note that this value may be invalidated`.
value_type numeric_type() const
Best numeric datatype of the value.
Definition value.hpp:83
value_type type() const
The type of the value.
Definition value.hpp:41
value(sqlite3_value *value_) noexcept
Construct value from a handle.
Definition value.hpp:95
bool is_null() const
Is the held value null.
Definition value.hpp:51
blob_view get_blob() const
Returns the value as blob, i.e. raw memory. Note that this value may be invalidated`.
handle_type handle() const
Returns the handle.
Definition value.hpp:100
int get_int() const
Returns the value as regular int.
Definition value.hpp:61
int subtype() const
The subtype of the value, see.
Definition value.hpp:46