11 #ifndef PQXX_H_LARGEOBJECT 12 #define PQXX_H_LARGEOBJECT 14 #if !defined(PQXX_HEADER_PRE) 15 # error "Include libpqxx headers as <pqxx/header>, not <pqxx/header.hxx>." 20 #include "pqxx/dbtransaction.hxx" 40 [[deprecated(
"Use blob instead.")]]
largeobject() noexcept = default;
77 [[nodiscard]] oid
id() const noexcept {
return m_id; }
91 return m_id == other.m_id;
97 return m_id != other.m_id;
103 return m_id <= other.m_id;
109 return m_id >= other.m_id;
115 return m_id < other.m_id;
121 return m_id > other.m_id;
140 PQXX_PURE
static internal::pq::PGconn *
143 PQXX_PRIVATE std::string reason(
connection const &,
int err)
const;
171 static constexpr
auto default_mode{
172 std::ios::in | std::ios::out | std::ios::binary};
245 void write(
char const buf[], std::size_t len);
251 void write(std::string_view buf) {
write(std::data(buf), std::size(buf)); }
260 size_type read(
char buf[], std::size_t len);
305 off_type cwrite(
char const buf[], std::size_t len) noexcept;
314 off_type cread(
char buf[], std::size_t len) noexcept;
321 [[nodiscard]]
pos_type ctell()
const noexcept;
328 void process_notice(
zview) noexcept;
334 using largeobject::operator==;
335 using largeobject::operator!=;
336 using largeobject::operator<;
337 using largeobject::operator<=;
338 using largeobject::operator>;
339 using largeobject::operator>=;
346 PQXX_PRIVATE std::string reason(
int err)
const;
347 internal::pq::PGconn *raw_connection()
const 352 PQXX_PRIVATE
void open(
openmode mode);
353 void close() noexcept;
372 template<
typename CHAR =
char,
typename TRAITS = std::
char_traits<CHAR>>
387 static constexpr
auto default_mode{
388 std::ios::in | std::ios::out | std::ios::binary};
390 #include "pqxx/internal/ignore-deprecated-pre.hxx" 393 size_type buf_size = 512) :
394 m_bufsize{buf_size}, m_obj{t, o, mode}, m_g{
nullptr}, m_p{
nullptr}
398 #include "pqxx/internal/ignore-deprecated-post.hxx" 402 size_type buf_size = 512) :
403 m_bufsize{buf_size}, m_obj{t, o, mode}, m_g{
nullptr}, m_p{
nullptr}
417 m_obj.process_notice(s);
424 this->setg(this->eback(), this->eback(), this->egptr());
425 return overflow(eof());
437 return adjust_eof(newpos);
442 auto *
const pp{this->pptr()};
445 auto *
const pb{this->pbase()};
450 auto const write_sz{pp - pb};
451 auto const written_sz{
452 m_obj.cwrite(pb, static_cast<std::size_t>(pp - pb))};
455 "pqxx::largeobject: write failed " 456 "(is transaction still valid on write or flush?), " 457 "libpq reports error"};
458 else if (write_sz != written_sz)
460 "pqxx::largeobject: write failed " 461 "(is transaction still valid on write or flush?), " +
464 auto const out{adjust_eof(written_sz)};
466 if constexpr (std::is_arithmetic_v<decltype(out)>)
471 this->setp(m_p, m_p + m_bufsize);
476 *this->pptr() =
static_cast<char_type>(ch);
484 return overflow(eof());
489 if (this->gptr() ==
nullptr)
491 auto *
const eb{this->eback()};
492 auto const res{adjust_eof(
493 m_obj.cread(this->eback(),
static_cast<std::size_t
>(m_bufsize)))};
495 eb, eb, eb + (res == eof() ? 0 : static_cast<std::size_t>(res)));
496 return (res == eof() or res == 0) ? eof() : traits_type::to_int_type(*eb);
503 return traits_type::eof();
507 template<
typename INTYPE>
static std::streampos adjust_eof(INTYPE pos)
509 bool const at_eof{pos == -1};
510 if constexpr (std::is_arithmetic_v<std::streampos>)
513 (at_eof ? eof() : pos),
"large object seek"sv);
517 return std::streampos(at_eof ? eof() : pos);
523 if ((mode & std::ios::in) != 0)
525 m_g =
new char_type[unsigned(m_bufsize)];
526 this->setg(m_g, m_g, m_g);
528 if ((mode & std::ios::out) != 0)
530 m_p =
new char_type[unsigned(m_bufsize)];
531 this->setp(m_p, m_p + m_bufsize);
535 size_type
const m_bufsize;
553 template<
typename CHAR =
char,
typename TRAITS = std::
char_traits<CHAR>>
556 using super = std::basic_istream<CHAR, TRAITS>;
565 #include "pqxx/internal/ignore-deprecated-pre.hxx" 575 m_buf{t, o, std::ios::in | std::ios::binary, buf_size}
579 #include "pqxx/internal/ignore-deprecated-post.hxx" 590 m_buf{t, o, std::ios::in | std::ios::binary, buf_size}
611 template<
typename CHAR =
char,
typename TRAITS = std::
char_traits<CHAR>>
614 using super = std::basic_ostream<CHAR, TRAITS>;
623 #include "pqxx/internal/ignore-deprecated-pre.hxx" 633 m_buf{t, o, std::ios::out | std::ios::binary, buf_size}
637 #include "pqxx/internal/ignore-deprecated-post.hxx" 648 m_buf{t, o, std::ios::out | std::ios::binary, buf_size}
660 catch (std::exception
const &e)
662 m_buf.process_notice(e.what());
683 template<
typename CHAR =
char,
typename TRAITS = std::
char_traits<CHAR>>
686 using super = std::basic_iostream<CHAR, TRAITS>;
705 t, o, std::ios::in | std::ios::out | std::ios::binary, buf_size}
720 t, o, std::ios::in | std::ios::out | std::ios::binary, buf_size}
732 catch (std::exception
const &e)
734 m_buf.process_notice(e.what());
CHAR char_type
Definition: largeobject.hxx:689
void to_file(std::string_view file) const
Export large object's contents to a local file.
Definition: largeobject.hxx:228
basic_lostream(dbtransaction &t, oid o, largeobject::size_type buf_size=512)
Create a basic_lostream.
Definition: largeobject.hxx:716
bool operator<=(largeobject const &other) const
Compare object identities.
Definition: largeobject.hxx:101
virtual int_type overflow(int_type ch) override
Definition: largeobject.hxx:440
typename traits_type::int_type int_type
Definition: largeobject.hxx:619
basic_ilostream(dbtransaction &t, oid o, largeobject::size_type buf_size=512)
End a code block started by "ignore-deprecated-pre.hxx".
Definition: largeobject.hxx:587
Connection to a database.
Definition: connection.hxx:249
typename traits_type::pos_type pos_type
Definition: largeobject.hxx:562
basic_olostream(dbtransaction &t, oid o, largeobject::size_type buf_size=512)
End a code block started by "ignore-deprecated-pre.hxx".
Definition: largeobject.hxx:645
~largeobjectaccess() noexcept
Definition: largeobject.hxx:216
size_type pos_type
Definition: largeobject.hxx:158
void write(std::string_view buf)
Write string to large object.
Definition: largeobject.hxx:251
TO check_cast(FROM value, std::string_view description)
Cast a numeric value to another type, or throw if it underflows/overflows.
Definition: util.hxx:151
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:32
Marker-type wrapper: zero-terminated std::string_view.
Definition: zview.hxx:37
basic_olostream(dbtransaction &t, largeobject o, largeobject::size_type buf_size=512)
Create a basic_olostream.
Definition: largeobject.hxx:630
TRAITS traits_type
Definition: largeobject.hxx:618
TRAITS traits_type
Definition: largeobject.hxx:560
constexpr oid oid_none
The "null" oid.
Definition: util.hxx:342
largeobject_streambuf(dbtransaction &t, oid o, openmode mode=default_mode, size_type buf_size=512)
End a code block started by "ignore-deprecated-pre.hxx".
Definition: largeobject.hxx:400
bool operator!=(largeobject const &other) const
Compare object identities.
Definition: largeobject.hxx:95
int64_t large_object_size_type
Number of bytes in a large object.
Definition: types.hxx:43
typename traits_type::off_type off_type
Definition: largeobject.hxx:382
void remove(dbtransaction &t) const
Delete large object from database.
Definition: largeobject.cxx:123
Internal error in libpqxx library.
Definition: except.hxx:230
Accessor for large object's contents.
Definition: largeobject.hxx:153
TRAITS traits_type
Definition: largeobject.hxx:379
typename traits_type::pos_type pos_type
Definition: largeobject.hxx:692
largeobjectaccess::seekdir seekdir
Definition: largeobject.hxx:384
typename traits_type::int_type int_type
Definition: largeobject.hxx:380
static PQXX_PURE internal::pq::PGconn * raw_connection(dbtransaction const &T)
Definition: largeobject.cxx:139
std::string to_string(TYPE const &value)
Convert a value to a readable string that PostgreSQL will understand.
bool operator==(largeobject const &other) const
Compare object identities.
Definition: largeobject.hxx:89
~basic_olostream()
Definition: largeobject.hxx:653
virtual ~largeobject_streambuf() noexcept
Definition: largeobject.hxx:408
Input stream that gets its data from a large object.
Definition: largeobject.hxx:554
virtual int_type underflow() override
Definition: largeobject.hxx:487
bool operator<(largeobject const &other) const
Compare object identities.
Definition: largeobject.hxx:113
typename traits_type::pos_type pos_type
Definition: largeobject.hxx:620
virtual int sync() override
Definition: largeobject.hxx:421
typename traits_type::pos_type pos_type
Definition: largeobject.hxx:381
basic_ilostream(dbtransaction &t, largeobject o, largeobject::size_type buf_size=512)
Create a basic_ilostream.
Definition: largeobject.hxx:572
void to_file(dbtransaction &t, std::string_view file) const
Export large object's contents to a local file.
Definition: largeobject.cxx:107
largeobjectaccess::openmode openmode
Definition: largeobject.hxx:383
std::ios::openmode openmode
Open mode: in, out (can be combined using "bitwise or").
Definition: largeobject.hxx:168
oid id() const noexcept
Object identifier.
Definition: largeobject.hxx:77
CHAR char_type
Definition: largeobject.hxx:559
Identity of a large object.
Definition: largeobject.hxx:33
Abstract transaction base class: bracket transactions on the database.
Definition: dbtransaction.hxx:53
virtual int_type overflow()
Definition: largeobject.hxx:482
basic_lostream(dbtransaction &t, largeobject o, largeobject::size_type buf_size=512)
Create a basic_lostream.
Definition: largeobject.hxx:701
largeobject_streambuf(dbtransaction &t, largeobject o, openmode mode=default_mode, size_type buf_size=512)
Definition: largeobject.hxx:391
bool operator>(largeobject const &other) const
Compare object identities.
Definition: largeobject.hxx:119
typename traits_type::off_type off_type
Definition: largeobject.hxx:563
typename traits_type::int_type int_type
Definition: largeobject.hxx:691
typename traits_type::off_type off_type
Definition: largeobject.hxx:621
Stream that reads and writes a large object.
Definition: largeobject.hxx:684
Streambuf to use large objects in standard I/O streams.
Definition: largeobject.hxx:373
CHAR char_type
Definition: largeobject.hxx:378
large_object_size_type size_type
Definition: largeobject.hxx:36
bool operator>=(largeobject const &other) const
Compare object identities.
Definition: largeobject.hxx:107
virtual pos_type seekoff(off_type offset, seekdir dir, openmode) override
Definition: largeobject.hxx:428
CHAR char_type
Definition: largeobject.hxx:617
typename traits_type::int_type int_type
Definition: largeobject.hxx:561
Output stream that writes data back to a large object.
Definition: largeobject.hxx:612
void process_notice(zview const &s)
For use by large object stream classes.
Definition: largeobject.hxx:415
std::ios::seekdir seekdir
Seek direction: beg, cur, end.
Definition: largeobject.hxx:175
constexpr bool cmp_less_equal(LEFT lhs, RIGHT rhs) noexcept
C++20 std::cmp_less_equal, or workaround if not available.
Definition: util.hxx:98
TRAITS traits_type
Definition: largeobject.hxx:690
virtual pos_type seekpos(pos_type pos, openmode) override
Definition: largeobject.hxx:433
size_type off_type
Definition: largeobject.hxx:157
~basic_lostream()
Definition: largeobject.hxx:725
typename traits_type::off_type off_type
Definition: largeobject.hxx:693