From efcea3a80da7c4479d5fe168435ecc9fd06bdc72 Mon Sep 17 00:00:00 2001 From: John Turner Date: Sun, 14 Sep 2025 00:16:10 -0400 Subject: Squashed 'subprojects/boost-sqlite/' content from commit 3378e35 git-subtree-dir: subprojects/boost-sqlite git-subtree-split: 3378e353705271e569cf4ba15c467b840a39798c --- include/boost/sqlite/field.hpp | 85 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 include/boost/sqlite/field.hpp (limited to 'include/boost/sqlite/field.hpp') diff --git a/include/boost/sqlite/field.hpp b/include/boost/sqlite/field.hpp new file mode 100644 index 0000000..20fe4bd --- /dev/null +++ b/include/boost/sqlite/field.hpp @@ -0,0 +1,85 @@ +// Copyright (c) 2022 Klemens D. Morgenstern +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +#ifndef BOOST_SQLITE_FIELD_HPP +#define BOOST_SQLITE_FIELD_HPP + +#include +#include +#include +#include + +#include + + +BOOST_SQLITE_BEGIN_NAMESPACE + +/** @brief A holder for a sqlite field, i.e. something returned from a query. + @ingroup reference + */ +struct field +{ + typedef sqlite_int64 int64; + + /// The type of the value + value_type type() const + { + return static_cast( sqlite3_column_type(stm_, col_)); + } + /// Is the held value null + bool is_null() const + { + return type() == value_type::null; + } + /// Is the held value is not null + explicit operator bool () const + { + return type() != value_type::null; + } + /// Returns the value as an `int64`. + int64 get_int() const + { + return sqlite3_column_int64(stm_, col_); + } + /// Returns the value as an `double`. + double get_double() const + { + return sqlite3_column_double(stm_, col_); + } + /// Returns the value as text, i.e. a string_view. Note that this value may be invalidated`. + BOOST_SQLITE_DECL + cstring_ref get_text() const; + /// Returns the value as blob, i.e. raw memory. Note that this value may be invalidated`. + BOOST_SQLITE_DECL + blob_view get_blob() const; + /// Returns the field as a value. + value get_value() const + { + return value(sqlite3_column_value(stm_, col_)); + } + /// Returns the name of the column. + cstring_ref column_name() const + { + return sqlite3_column_name(stm_, col_); + } + /// Returns the name of the table. + cstring_ref table_name() const + { + return sqlite3_column_table_name(stm_, col_); + } + /// Returns the name of the original data source. + cstring_ref column_origin_name() const + { + return sqlite3_column_origin_name(stm_, col_); + } + + private: + friend struct row; + sqlite3_stmt * stm_; + int col_ = -1; +}; + +BOOST_SQLITE_END_NAMESPACE + +#endif //BOOST_SQLITE_FIELD_HPP -- cgit v1.2.3