boost_sqlite 1
A sqlite C++ library
Loading...
Searching...
No Matches
field.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_FIELD_HPP
6#define BOOST_SQLITE_FIELD_HPP
7
8#include <boost/sqlite/detail/config.hpp>
9#include <boost/sqlite/blob.hpp>
10#include <boost/sqlite/cstring_ref.hpp>
11#include <boost/sqlite/value.hpp>
12
13#include <boost/core/detail/string_view.hpp>
14
15
16BOOST_SQLITE_BEGIN_NAMESPACE
17
21struct field
22{
25 {
26 return static_cast<value_type>( sqlite3_column_type(stm_, col_));
27 }
29 bool is_null() const
30 {
31 return type() == value_type::null;
32 }
34 explicit operator bool () const
35 {
36 return type() != value_type::null;
37 }
39 int get_int() const
40 {
41 return sqlite3_column_int(stm_, col_);
42 }
44 sqlite3_int64 get_int64() const
45 {
46 return sqlite3_column_int64(stm_, col_);
47 }
49 double get_double() const
50 {
51 return sqlite3_column_double(stm_, col_);
52 }
54 BOOST_SQLITE_DECL
57 BOOST_SQLITE_DECL
61 {
62 return value(sqlite3_column_value(stm_, col_));
63 }
66 {
67 return sqlite3_column_name(stm_, col_);
68 }
71 {
72 return sqlite3_column_table_name(stm_, col_);
73 }
76 {
77 return sqlite3_column_origin_name(stm_, col_);
78 }
79
80 private:
81 friend struct row;
82 sqlite3_stmt * stm_;
83 int col_ = -1;
84};
85
86BOOST_SQLITE_END_NAMESPACE
87
88#endif //BOOST_SQLITE_FIELD_HPP
value_type
The type of a value.
Definition value.hpp:21
a view to a binary large object
Definition blob.hpp:21
Small wrapper for a null-terminated string that can be directly passed to C APIS.
A holder for a sqlite field, i.e. something returned from a query.
Definition field.hpp:22
cstring_ref table_name() const
Returns the name of the table.
Definition field.hpp:70
value_type type() const
The type of the value.
Definition field.hpp:24
cstring_ref get_text() const
Returns the value as text, i.e. a string_view. Note that this value may be invalidated`.
double get_double() const
Returns the value as an double.
Definition field.hpp:49
cstring_ref column_origin_name() const
Returns the name of the original data source.
Definition field.hpp:75
sqlite3_int64 get_int64() const
Returns the value as an int64.
Definition field.hpp:44
int get_int() const
Returns the value as regular int.
Definition field.hpp:39
bool is_null() const
Is the held value null.
Definition field.hpp:29
cstring_ref column_name() const
Returns the name of the column.
Definition field.hpp:65
value get_value() const
Returns the field as a value.
Definition field.hpp:60
blob_view get_blob() const
Returns the value as blob, i.e. raw memory. Note that this value may be invalidated`.
Representation of a row in a database.
Definition row.hpp:21
A holder for a sqlite values used for internal APIs.
Definition value.hpp:39