11 #ifndef PQXX_H_LARGEOBJECT 12 #define PQXX_H_LARGEOBJECT 14 #include "pqxx/compiler-public.hxx" 15 #include "pqxx/internal/compiler-internal-pre.hxx" 19 #include "pqxx/dbtransaction.hxx" 39 PQXX_DEPRECATED(
"Use blob instead.")
largeobject() noexcept = default;
51 PQXX_DEPRECATED("Use
blob instead.")
59 PQXX_DEPRECATED(
"Use blob instead.")
67 PQXX_DEPRECATED(
"Use blob instead.")
75 [[nodiscard]] oid
id() const noexcept {
return m_id; }
89 return m_id == other.m_id;
95 return m_id != other.m_id;
101 return m_id <= other.m_id;
107 return m_id >= other.m_id;
113 return m_id < other.m_id;
119 return m_id > other.m_id;
138 PQXX_PURE
static internal::pq::PGconn *
141 PQXX_PRIVATE std::string reason(
connection const &,
int err)
const;
169 static constexpr
auto default_mode{
170 std::ios::in | std::ios::out | std::ios::binary};
181 PQXX_DEPRECATED(
"Use blob instead.")
192 PQXX_DEPRECATED("Use
blob instead.")
202 PQXX_DEPRECATED("Use
blob instead.")
212 PQXX_DEPRECATED("Use
blob instead.")
245 void write(
char const buf[], std::size_t len);
251 void write(std::string_view buf) {
write(buf.data(), 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 PQXX_DEPRECATED(
"Use blob instead.")
393 size_type buf_size = 512) :
394 m_bufsize{buf_size}, m_obj{t, o, mode}, m_g{
nullptr}, m_p{
nullptr}
399 PQXX_DEPRECATED(
"Use blob instead.")
402 size_type buf_size = 512) :
403 m_bufsize{buf_size}, m_obj{t, o, mode}, m_g{
nullptr}, m_p{
nullptr}
421 this->setg(this->eback(), this->eback(), this->egptr());
422 return overflow(eof());
434 return adjust_eof(newpos);
439 auto *
const pp{this->pptr()};
442 auto *
const pb{this->pbase()};
447 auto const write_sz{pp - pb};
448 auto const written_sz{
449 m_obj.cwrite(pb, static_cast<std::size_t>(pp - pb))};
450 if (written_sz <= static_cast<off_type>(0))
452 "pqxx::largeobject: write failed " 453 "(is transaction still valid on write or flush?), " 454 "libpq reports error"};
455 else if (write_sz != written_sz)
457 "pqxx::largeobject: write failed " 458 "(is transaction still valid on write or flush?), " +
461 auto const out{adjust_eof(written_sz)};
463 if constexpr (std::is_arithmetic_v<decltype(out)>)
468 this->setp(m_p, m_p + m_bufsize);
473 *this->pptr() =
static_cast<char_type>(ch);
483 if (this->gptr() ==
nullptr)
485 auto *
const eb{this->eback()};
486 auto const res{adjust_eof(
487 m_obj.cread(this->eback(),
static_cast<std::size_t
>(m_bufsize)))};
489 eb, eb, eb + (res == eof() ? 0 : static_cast<std::size_t>(res)));
490 return (res == eof() or res == 0) ? eof() : traits_type::to_int_type(*eb);
495 static int_type eof() {
return traits_type::eof(); }
498 template<
typename INTYPE>
static std::streampos adjust_eof(INTYPE pos)
500 bool const at_eof{pos == -1};
501 if constexpr (std::is_arithmetic_v<std::streampos>)
504 (at_eof ? eof() : pos),
"large object seek"sv);
508 return std::streampos(at_eof ? eof() : pos);
514 if ((mode & std::ios::in) != 0)
516 m_g =
new char_type[unsigned(m_bufsize)];
517 this->setg(m_g, m_g, m_g);
519 if ((mode & std::ios::out) != 0)
521 m_p =
new char_type[unsigned(m_bufsize)];
522 this->setp(m_p, m_p + m_bufsize);
526 size_type
const m_bufsize;
544 template<
typename CHAR =
char,
typename TRAITS = std::
char_traits<CHAR>>
547 using super = std::basic_istream<CHAR, TRAITS>;
562 PQXX_DEPRECATED(
"Use blob instead.")
566 m_buf{t, o, std::ios::in | std::ios::binary, buf_size}
577 PQXX_DEPRECATED(
"Use blob instead.")
581 m_buf{t, o, std::ios::in | std::ios::binary, buf_size}
602 template<
typename CHAR =
char,
typename TRAITS = std::
char_traits<CHAR>>
605 using super = std::basic_ostream<CHAR, TRAITS>;
620 PQXX_DEPRECATED(
"Use blob instead.")
624 m_buf{t, o, std::ios::out | std::ios::binary, buf_size}
635 PQXX_DEPRECATED(
"Use blob instead.")
639 m_buf{t, o, std::ios::out | std::ios::binary, buf_size}
651 catch (std::exception
const &e)
674 template<
typename CHAR =
char,
typename TRAITS = std::
char_traits<CHAR>>
677 using super = std::basic_iostream<CHAR, TRAITS>;
692 PQXX_DEPRECATED(
"Use blob instead.")
697 t, o, std::ios::in | std::ios::out | std::ios::binary, buf_size}
708 PQXX_DEPRECATED(
"Use blob instead.")
713 t, o, std::ios::in | std::ios::out | std::ios::binary, buf_size}
725 catch (std::exception
const &e)
738 #include "pqxx/internal/compiler-internal-post.hxx" constexpr oid oid_none
The "null" oid.
Definition: util.hxx:215
typename traits_type::int_type int_type
Definition: largeobject.hxx:610
virtual int sync() override
Definition: largeobject.hxx:418
void to_file(dbtransaction &t, std::string_view file) const
Export large object's contents to a local file.
Definition: largeobject.cxx:101
typename traits_type::int_type int_type
Definition: largeobject.hxx:380
virtual pos_type seekoff(off_type offset, seekdir dir, openmode) override
Definition: largeobject.hxx:425
bool operator<=(largeobject const &other) const
Compare object identities.
Definition: largeobject.hxx:99
TRAITS traits_type
Definition: largeobject.hxx:609
TRAITS traits_type
Definition: largeobject.hxx:551
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:25
std::string to_string(TYPE const &value)
Convert a value to a readable string that PostgreSQL will understand.
TRAITS traits_type
Definition: largeobject.hxx:681
Accessor for large object's contents.
Definition: largeobject.hxx:151
size_type pos_type
Definition: largeobject.hxx:156
bool operator==(largeobject const &other) const
Compare object identities.
Definition: largeobject.hxx:87
Input stream that gets its data from a large object.
Definition: largeobject.hxx:545
typename traits_type::off_type off_type
Definition: largeobject.hxx:554
bool operator!=(largeobject const &other) const
Compare object identities.
Definition: largeobject.hxx:93
bool operator<(largeobject const &other) const
Compare object identities.
Definition: largeobject.hxx:111
typename traits_type::int_type int_type
Definition: largeobject.hxx:682
typename traits_type::pos_type pos_type
Definition: largeobject.hxx:553
typename traits_type::pos_type pos_type
Definition: largeobject.hxx:611
Identity of a large object.
Definition: largeobject.hxx:32
~basic_olostream()
Definition: largeobject.hxx:644
Connection to a database.
Definition: connection.hxx:181
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:79
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:173
virtual pos_type seekpos(pos_type pos, openmode) override
Definition: largeobject.hxx:430
Stream that reads and writes a large object.
Definition: largeobject.hxx:675
typename traits_type::pos_type pos_type
Definition: largeobject.hxx:683
Streambuf to use large objects in standard I/O streams.
Definition: largeobject.hxx:373
TRAITS traits_type
Definition: largeobject.hxx:379
Abstract transaction base class: bracket transactions on the database.
Definition: dbtransaction.hxx:52
static PQXX_PURE internal::pq::PGconn * raw_connection(dbtransaction const &T)
Definition: largeobject.cxx:133
large_object_size_type size_type
Definition: largeobject.hxx:35
typename traits_type::off_type off_type
Definition: largeobject.hxx:684
bool operator>=(largeobject const &other) const
Compare object identities.
Definition: largeobject.hxx:105
CHAR char_type
Definition: largeobject.hxx:680
Internal error in libpqxx library.
Definition: except.hxx:157
CHAR char_type
Definition: largeobject.hxx:608
void remove(dbtransaction &t) const
Delete large object from database.
Definition: largeobject.cxx:117
typename traits_type::int_type int_type
Definition: largeobject.hxx:552
std::ios::openmode openmode
Open mode: in, out (can be combined using "bitwise or").
Definition: largeobject.hxx:166
oid id() const noexcept
Object identifier.
Definition: largeobject.hxx:75
virtual int_type overflow(int_type ch) override
Definition: largeobject.hxx:437
Output stream that writes data back to a large object.
Definition: largeobject.hxx:603
bool operator>(largeobject const &other) const
Compare object identities.
Definition: largeobject.hxx:117
typename traits_type::off_type off_type
Definition: largeobject.hxx:382
int64_t large_object_size_type
Number of bytes in a large object.
Definition: types.hxx:33
typename traits_type::off_type off_type
Definition: largeobject.hxx:612
largeobjectaccess::seekdir seekdir
Definition: largeobject.hxx:384
size_type off_type
Definition: largeobject.hxx:155
typename traits_type::pos_type pos_type
Definition: largeobject.hxx:381
CHAR char_type
Definition: largeobject.hxx:378
~basic_lostream()
Definition: largeobject.hxx:718
void write(std::string_view buf)
Write string to large object.
Definition: largeobject.hxx:251
Marker-type wrapper: zero-terminated std::string_view.
Definition: zview.hxx:37
void to_file(std::string_view file) const
Export large object's contents to a local file.
Definition: largeobject.hxx:228
largeobjectaccess::openmode openmode
Definition: largeobject.hxx:383
CHAR char_type
Definition: largeobject.hxx:550
virtual int_type overflow()
Definition: largeobject.hxx:479
virtual ~largeobject_streambuf() noexcept
Definition: largeobject.hxx:408
virtual int_type underflow() override
Definition: largeobject.hxx:481