16 #if !defined(PQXX_HEADER_PRE)
17 # error "Include libpqxx headers as <pqxx/header>, not <pqxx/header.hxx>."
22 #if defined(PQXX_HAVE_PATH)
23 # include <filesystem>
27 #if defined(PQXX_HAVE_RANGES)
32 #if __has_include(<span>)
36 #include "pqxx/dbtransaction.hxx"
68 [[nodiscard]]
static blob open_r(dbtransaction &,
oid);
70 [[nodiscard]]
static blob open_w(dbtransaction &,
oid);
72 [[nodiscard]]
static blob open_rw(dbtransaction &,
oid);
86 blob &operator=(
blob const &) =
delete;
96 static constexpr std::size_t chunk_limit = 0x7fffffff;
107 std::size_t read(
bytes &buf, std::size_t size);
109 #if defined(PQXX_HAVE_SPAN)
116 template<std::
size_t extent = std::dynamic_extent>
117 std::span<std::byte> read(std::span<std::byte, extent> buf)
119 return buf.subspan(0, raw_read(std::data(buf), std::size(buf)));
121 #endif // PQXX_HAVE_SPAN
123 #if defined(PQXX_HAVE_CONCEPTS) && defined(PQXX_HAVE_RANGES) && \
124 defined(PQXX_HAVE_SPAN)
131 template<binary DATA> std::span<std::byte> read(DATA &buf)
133 return {std::data(buf), raw_read(std::data(buf), std::size(buf))};
135 #else // PQXX_HAVE_CONCEPTS && PQXX_HAVE_SPAN
151 return {std::data(buf), raw_read(std::data(buf), std::size(buf))};
153 #endif // PQXX_HAVE_CONCEPTS && PQXX_HAVE_SPAN
155 #if defined(PQXX_HAVE_CONCEPTS) && defined(PQXX_HAVE_RANGES)
175 template<binary DATA>
void write(DATA
const &data)
177 raw_write(std::data(data), std::size(data));
199 template<
typename DATA>
void write(DATA
const &data)
201 raw_write(std::data(data), std::size(data));
212 void resize(std::int64_t size);
215 [[nodiscard]] std::int64_t tell()
const;
219 std::int64_t seek_abs(std::int64_t offset = 0);
225 std::int64_t seek_rel(std::int64_t offset = 0);
231 std::int64_t seek_end(std::int64_t offset = 0);
242 static void append_from_buf(dbtransaction &tx,
bytes_view data,
oid id);
245 [[nodiscard]]
static oid from_file(dbtransaction &,
char const path[]);
247 #if defined(PQXX_HAVE_PATH) && !defined(_WIN32)
252 [[nodiscard]]
static oid
253 from_file(dbtransaction &tx, std::filesystem::path
const &path)
255 return from_file(tx, path.c_str());
263 static oid from_file(dbtransaction &,
char const path[],
oid);
265 #if defined(PQXX_HAVE_PATH) && !defined(_WIN32)
274 from_file(dbtransaction &tx, std::filesystem::path
const &path,
oid id)
276 return from_file(tx, path.c_str(), id);
284 static void to_buf(dbtransaction &,
oid,
bytes &, std::size_t max_size);
293 static std::size_t append_to_buf(
294 dbtransaction &tx,
oid id, std::int64_t offset,
bytes &buf,
295 std::size_t append_max);
298 static void to_file(dbtransaction &,
oid,
char const path[]);
300 #if defined(PQXX_HAVE_PATH) && !defined(_WIN32)
306 to_file(dbtransaction &tx,
oid id, std::filesystem::path
const &path)
308 to_file(tx,
id, path.c_str());
327 PQXX_PRIVATE blob(connection &cx,
int fd) noexcept : m_conn{&cx}, m_fd{fd} {}
328 static PQXX_PRIVATE blob open_internal(dbtransaction &,
oid,
int);
329 static PQXX_PRIVATE pqxx::internal::pq::PGconn *
331 static PQXX_PRIVATE
pqxx::internal::pq::PGconn *
332 raw_conn(
pqxx::dbtransaction const &) noexcept;
333 static PQXX_PRIVATE std::
string errmsg(connection const *);
334 static PQXX_PRIVATE std::
string errmsg(dbtransaction const &tx)
336 return errmsg(&tx.conn());
338 PQXX_PRIVATE std::string errmsg()
const {
return errmsg(m_conn); }
339 PQXX_PRIVATE std::int64_t seek(std::int64_t offset,
int whence);
340 std::size_t raw_read(std::byte buf[], std::size_t size);
341 void raw_write(std::byte
const buf[], std::size_t size);
343 connection *m_conn =
nullptr;
std::vector< std::string_view > to_buf(char *here, char const *end, TYPE...value)
Convert multiple values to strings inside a single buffer.
Definition: strconv.hxx:493
Abstract transaction base class: bracket transactions on the database.
Definition: dbtransaction.hxx:53
The home of all libpqxx classes, functions, templates, etc.
Definition: array.cxx:26
std::conditional< has_generic_bytes_char_traits, std::basic_string< std::byte >, std::basic_string< std::byte, byte_char_traits >>::type bytes
Type alias for a container containing bytes.
Definition: util.hxx:375
unsigned int oid
PostgreSQL database row identifier.
Definition: libpq-forward.hxx:33
std::conditional< has_generic_bytes_char_traits, std::basic_string_view< std::byte >, std::basic_string_view< std::byte, byte_char_traits >>::type bytes_view
Type alias for a view of bytes.
Definition: util.hxx:385
void write(DATA const &data)
Write data large object, at the current position.
Definition: blob.hxx:199
Connection to a database.
Definition: connection.hxx:278
bytes_view read(std::vector< std::byte, ALLOC > &buf)
Read up to std::size(buf) bytes from the object.
Definition: blob.hxx:149