8#ifndef BOOST_SQLITE_ERROR_HPP
9#define BOOST_SQLITE_ERROR_HPP
11#include <boost/sqlite/detail/config.hpp>
12#include <boost/sqlite/cstring_ref.hpp>
13#include <boost/sqlite/memory.hpp>
14#include <boost/system/error_code.hpp>
15#include <boost/system/error_category.hpp>
16#include <boost/system/result.hpp>
19BOOST_SQLITE_BEGIN_NAMESPACE
22system::error_category & sqlite_category();
40 std::memcpy(msg_.get(), msg.data(), msg.size() + 1);
46 reserve(msg.size() + 1u);
47 std::memcpy(msg_.get(), msg.data(), msg.size() + 1);
60 msg_.reset(sqlite3_vmprintf(fmt.c_str(), args));
72 sqlite3_vsnprintf(capacity(), msg_.get(), fmt.c_str(), args);
81 if (sqlite3_msize(msg_.get()) < sz)
82 msg_.reset(
static_cast<char*
>(sqlite3_realloc64(msg_.release(), sz)));
85 msg_.reset(
static_cast<char*
>(sqlite3_malloc64(sz)));
89 std::size_t
capacity()
const {
return msg_ ? sqlite3_msize(msg_.get()) : 0u;}
96 return msg_.release();
99 void clear() noexcept {
if (msg_) *msg_ =
'\0'; }
102 operator bool()
const {
return msg_.operator bool();}
104 unique_ptr<char> msg_;
120 error(
int code,
error_info info) : code(code), info(std::move(info)) {}
121 explicit error(
int code) : code(code) {}
122 error(
int code, core::string_view info)
126 error(system::error_code code, error_info info)
127 : code(code.category() == sqlite_category() ? code.value() : SQLITE_FAIL),
128 info(std::move(info)) {}
130 error(system::error_code code) : code(code.category() == sqlite_category() ? code.value() : SQLITE_FAIL)
132 if (code.category() == sqlite_category())
133 info = error_info{code.what()};
136 error(error && ) noexcept = default;
139BOOST_NORETURN BOOST_SQLITE_DECL
void throw_exception_from_error( error const & e, boost::source_location const & loc );
141template<typename T =
void>
142using result = system::result<T, error>;
145struct is_result_type : std::false_type {};
148struct is_result_type<result<T>> : std::true_type {};
151BOOST_SQLITE_END_NAMESPACE
Small wrapper for a null-terminated string that can be directly passed to C APIS.
Additional information about error conditions stored in an sqlite-allocate string.
cstring_ref format(cstring_ref fmt,...)
use sqlite_mprintf to generate a message
void clear() noexcept
Restores the object to its initial state.
void reset(char *c=nullptr)
transfer ownership into the message
cstring_ref message() const noexcept
Gets the error message.
void reserve(std::size_t sz)
reserve data in the buffer i.e. allocate
cstring_ref snformat(cstring_ref fmt,...)
use sqlite_snprintf to generate a message
void set_message(core::string_view msg)
set the message by copy
error_info()=default
Default constructor.
error_info(core::string_view msg) noexcept
Initialization constructor.
std::size_t capacity() const
Get the allocated memory.
An error containing both a code & optional message.
error_info info
The additional information of the error.
int code
The code of the error.