5#ifndef BOOST_SQLITE_BLOB_HPP
6#define BOOST_SQLITE_BLOB_HPP
8#include <boost/sqlite/detail/config.hpp>
9#include <boost/sqlite/memory.hpp>
10#include <boost/sqlite/error.hpp>
15BOOST_SQLITE_BEGIN_NAMESPACE
23 const void *
data()
const {
return data_;}
25 std::size_t
size()
const {
return size_;}
27 blob_view(
const void * data, std::size_t size) : data_(data), size_(size) {}
32 typename std::enable_if<
33 std::is_pointer<
decltype(std::declval<T>().data())>::value
34 && std::is_convertible<
decltype(std::declval<T>().size()), std::size_t>::value
35 >::type * =
nullptr) : data_(
value.data()), size_(
value.size()) {}
39 const void * data_{
nullptr};
40 std::size_t size_{0u};
50 void *
data()
const {
return impl_.get();}
52 std::size_t
size()
const {
return size_;}
57 impl_.reset(sqlite3_malloc(bv.size()));
59 std::memcpy(impl_.get(), bv.data(), size_);
62 explicit blob(std::size_t n) : impl_(sqlite3_malloc(n)), size_(n) {}
64 void *
release() && {
return std::move(impl_).release(); }
66 unique_ptr<void> impl_;
67 std::size_t size_{0u};
70blob_view::blob_view(
const blob & b) : data_(b.data()), size_(b.size()) {}
84 void reopen(sqlite3_int64 row_id, system::error_code & ec);
92 void read_at(
void *data,
int len,
int offset, system::error_code &ec);
94 void read_at(
void *data,
int len,
int offset);
100 void write_at(
const void *data,
int len,
int offset, system::error_code &ec);
102 void write_at(
const void *data,
int len,
int offset);
106 std::size_t
size()
const {
return static_cast<std::size_t
>(sqlite3_blob_bytes(blob_.get()));}
117 void operator()(sqlite3_blob *impl)
119 sqlite3_blob_close(impl);
122 std::unique_ptr<sqlite3_blob, deleter_> blob_;
128blob_handle open_blob(connection & conn,
134 system::error_code &ec,
138blob_handle open_blob(connection & conn,
143 bool read_only =
false);
148BOOST_SQLITE_END_NAMESPACE
zero_blob
Helper type to pass a blob full of zeroes without allocating extra memory.
an object that holds a binary large object. Can be obtained by using blob_handle.
blob_handle()=default
Default constructor.
handle_type release() &&
Release the owned handle.
blob_handle(sqlite3_blob *blob)
Construct from a handle. Takes owner ship.
void read_at(void *data, int len, int offset, system::error_code &ec)
Read data from the blob.
void write_at(const void *data, int len, int offset)
Write data to the blob.
void reopen(sqlite3_int64 row_id)
Reopen on another row.
sqlite3_blob * handle_type
The handle of the blob.
void write_at(const void *data, int len, int offset, system::error_code &ec)
Write data to the blob.
handle_type handle()
Returns the handle of the blob.
std::size_t size() const
The size of the blob.
void read_at(void *data, int len, int offset)
Read data from the blob.
void reopen(sqlite3_int64 row_id, system::error_code &ec)
Reopen on another row.
a view to a binary large object
std::size_t size() const
The size of the data int he blob, in bytes.
const void * data() const
The data in the blob.
blob_view(const void *data, std::size_t size)
Construct a blob.
blob_view(const T &value, typename std::enable_if< std::is_pointer< decltype(std::declval< T >().data())>::value &&std::is_convertible< decltype(std::declval< T >().size()), std::size_t >::value >::type *=nullptr)
Construct a blob from some other blob-like structure.
An object that owns a binary large object.
blob(blob_view bv)
Create a blob from a blob_view.
void * release() &&
Release & take ownership of the blob.
blob(std::size_t n)
Create an empty blob with size n.
std::size_t size() const
The size of the data int he blob, in bytes.
void * data() const
The data in the blob.
A holder for a sqlite values used for internal APIs.