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 [[deprecated(
"Use blob instead.")]]
largeobject() noexcept = default;
76 [[nodiscard]] oid
id() const noexcept {
return m_id; }
90 return m_id == other.m_id;
96 return m_id != other.m_id;
102 return m_id <= other.m_id;
108 return m_id >= other.m_id;
114 return m_id < other.m_id;
120 return m_id > other.m_id;
139 PQXX_PURE
static internal::pq::PGconn *
142 PQXX_PRIVATE std::string reason(
connection const &,
int err)
const;
170 static constexpr
auto default_mode{
171 std::ios::in | std::ios::out | std::ios::binary};
244 void write(
char const buf[], std::size_t len);
250 void write(std::string_view buf) {
write(buf.data(), std::size(buf)); }
259 size_type read(
char buf[], std::size_t len);
304 off_type cwrite(
char const buf[], std::size_t len) noexcept;
313 off_type cread(
char buf[], std::size_t len) noexcept;
320 [[nodiscard]]
pos_type ctell()
const noexcept;
327 void process_notice(
zview) noexcept;
333 using largeobject::operator==;
334 using largeobject::operator!=;
335 using largeobject::operator<;
336 using largeobject::operator<=;
337 using largeobject::operator>;
338 using largeobject::operator>=;
345 PQXX_PRIVATE std::string reason(
int err)
const;
346 internal::pq::PGconn *raw_connection()
const 351 PQXX_PRIVATE
void open(
openmode mode);
352 void close() noexcept;
371 template<
typename CHAR =
char,
typename TRAITS = std::
char_traits<CHAR>>
386 static constexpr
auto default_mode{
387 std::ios::in | std::ios::out | std::ios::binary};
391 size_type buf_size = 512) :
392 m_bufsize{buf_size}, m_obj{t, o, mode}, m_g{
nullptr}, m_p{
nullptr}
399 size_type buf_size = 512) :
400 m_bufsize{buf_size}, m_obj{t, o, mode}, m_g{
nullptr}, m_p{
nullptr}
418 this->setg(this->eback(), this->eback(), this->egptr());
419 return overflow(eof());
431 return adjust_eof(newpos);
436 auto *
const pp{this->pptr()};
439 auto *
const pb{this->pbase()};
444 auto const write_sz{pp - pb};
445 auto const written_sz{
446 m_obj.cwrite(pb, static_cast<std::size_t>(pp - pb))};
447 if (written_sz <= static_cast<off_type>(0))
449 "pqxx::largeobject: write failed " 450 "(is transaction still valid on write or flush?), " 451 "libpq reports error"};
452 else if (write_sz != written_sz)
454 "pqxx::largeobject: write failed " 455 "(is transaction still valid on write or flush?), " +
458 auto const out{adjust_eof(written_sz)};
460 if constexpr (std::is_arithmetic_v<decltype(out)>)
465 this->setp(m_p, m_p + m_bufsize);
470 *this->pptr() =
static_cast<char_type>(ch);
480 if (this->gptr() ==
nullptr)
482 auto *
const eb{this->eback()};
483 auto const res{adjust_eof(
484 m_obj.cread(this->eback(),
static_cast<std::size_t
>(m_bufsize)))};
486 eb, eb, eb + (res == eof() ? 0 : static_cast<std::size_t>(res)));
487 return (res == eof() or res == 0) ? eof() : traits_type::to_int_type(*eb);
492 static int_type eof() {
return traits_type::eof(); }
495 template<
typename INTYPE>
static std::streampos adjust_eof(INTYPE pos)
497 bool const at_eof{pos == -1};
498 if constexpr (std::is_arithmetic_v<std::streampos>)
501 (at_eof ? eof() : pos),
"large object seek"sv);
505 return std::streampos(at_eof ? eof() : pos);
511 if ((mode & std::ios::in) != 0)
513 m_g =
new char_type[unsigned(m_bufsize)];
514 this->setg(m_g, m_g, m_g);
516 if ((mode & std::ios::out) != 0)
518 m_p =
new char_type[unsigned(m_bufsize)];
519 this->setp(m_p, m_p + m_bufsize);
523 size_type
const m_bufsize;
541 template<
typename CHAR =
char,
typename TRAITS = std::
char_traits<CHAR>>
544 using super = std::basic_istream<CHAR, TRAITS>;
562 m_buf{t, o, std::ios::in | std::ios::binary, buf_size}
576 m_buf{t, o, std::ios::in | std::ios::binary, buf_size}
597 template<
typename CHAR =
char,
typename TRAITS = std::
char_traits<CHAR>>
600 using super = std::basic_ostream<CHAR, TRAITS>;
618 m_buf{t, o, std::ios::out | std::ios::binary, buf_size}
632 m_buf{t, o, std::ios::out | std::ios::binary, buf_size}
644 catch (std::exception
const &e)
646 m_buf.process_notice(e.what());
667 template<
typename CHAR =
char,
typename TRAITS = std::
char_traits<CHAR>>
670 using super = std::basic_iostream<CHAR, TRAITS>;
689 t, o, std::ios::in | std::ios::out | std::ios::binary, buf_size}
704 t, o, std::ios::in | std::ios::out | std::ios::binary, buf_size}
716 catch (std::exception
const &e)
718 m_buf.process_notice(e.what());
729 #include "pqxx/internal/compiler-internal-post.hxx" bool operator!=(largeobject const &other) const
Compare object identities.
Definition: largeobject.hxx:94
bool operator<(largeobject const &other) const
Compare object identities.
Definition: largeobject.hxx:112
Output stream that writes data back to a large object.
Definition: largeobject.hxx:598
typename traits_type::int_type int_type
Definition: largeobject.hxx:675
virtual pos_type seekpos(pos_type pos, openmode) override
Definition: largeobject.hxx:427
typename traits_type::pos_type pos_type
Definition: largeobject.hxx:676
large_object_size_type size_type
Definition: largeobject.hxx:35
typename traits_type::off_type off_type
Definition: largeobject.hxx:677
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:25
CHAR char_type
Definition: largeobject.hxx:547
bool operator>=(largeobject const &other) const
Compare object identities.
Definition: largeobject.hxx:106
basic_olostream(dbtransaction &t, oid o, largeobject::size_type buf_size=512)
Create a basic_olostream.
Definition: largeobject.hxx:629
oid id() const noexcept
Object identifier.
Definition: largeobject.hxx:76
typename traits_type::int_type int_type
Definition: largeobject.hxx:605
virtual int_type overflow(int_type ch) override
Definition: largeobject.hxx:434
void process_notice(zview const &s)
For use by large object stream classes.
Definition: largeobject.hxx:412
largeobject_streambuf(dbtransaction &t, largeobject o, openmode mode=default_mode, size_type buf_size=512)
Definition: largeobject.hxx:389
Accessor for large object's contents.
Definition: largeobject.hxx:152
bool operator>(largeobject const &other) const
Compare object identities.
Definition: largeobject.hxx:118
~largeobjectaccess() noexcept
Definition: largeobject.hxx:215
void write(std::string_view buf)
Write string to large object.
Definition: largeobject.hxx:250
typename traits_type::off_type off_type
Definition: largeobject.hxx:381
TRAITS traits_type
Definition: largeobject.hxx:378
largeobjectaccess::seekdir seekdir
Definition: largeobject.hxx:383
static PQXX_PURE internal::pq::PGconn * raw_connection(dbtransaction const &T)
Definition: largeobject.cxx:133
CHAR char_type
Definition: largeobject.hxx:377
~basic_lostream()
Definition: largeobject.hxx:709
CHAR char_type
Definition: largeobject.hxx:673
Input stream that gets its data from a large object.
Definition: largeobject.hxx:542
basic_olostream(dbtransaction &t, largeobject o, largeobject::size_type buf_size=512)
Create a basic_olostream.
Definition: largeobject.hxx:615
void remove(dbtransaction &t) const
Delete large object from database.
Definition: largeobject.cxx:117
Identity of a large object.
Definition: largeobject.hxx:32
virtual int_type overflow()
Definition: largeobject.hxx:476
std::string to_string(TYPE const &value)
Convert a value to a readable string that PostgreSQL will understand.
size_type off_type
Definition: largeobject.hxx:156
basic_lostream(dbtransaction &t, largeobject o, largeobject::size_type buf_size=512)
Create a basic_lostream.
Definition: largeobject.hxx:685
virtual int_type underflow() override
Definition: largeobject.hxx:478
Marker-type wrapper: zero-terminated std::string_view.
Definition: zview.hxx:37
TRAITS traits_type
Definition: largeobject.hxx:604
Stream that reads and writes a large object.
Definition: largeobject.hxx:668
Streambuf to use large objects in standard I/O streams.
Definition: largeobject.hxx:372
typename traits_type::pos_type pos_type
Definition: largeobject.hxx:380
virtual int sync() override
Definition: largeobject.hxx:415
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:549
typename traits_type::int_type int_type
Definition: largeobject.hxx:379
basic_ilostream(dbtransaction &t, largeobject o, largeobject::size_type buf_size=512)
Create a basic_ilostream.
Definition: largeobject.hxx:559
Internal error in libpqxx library.
Definition: except.hxx:157
typename traits_type::pos_type pos_type
Definition: largeobject.hxx:606
void to_file(std::string_view file) const
Export large object's contents to a local file.
Definition: largeobject.hxx:227
largeobjectaccess::openmode openmode
Definition: largeobject.hxx:382
virtual ~largeobject_streambuf() noexcept
Definition: largeobject.hxx:405
size_type pos_type
Definition: largeobject.hxx:157
bool operator<=(largeobject const &other) const
Compare object identities.
Definition: largeobject.hxx:100
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:75
std::ios::openmode openmode
Open mode: in, out (can be combined using "bitwise or").
Definition: largeobject.hxx:167
~basic_olostream()
Definition: largeobject.hxx:637
std::ios::seekdir seekdir
Seek direction: beg, cur, end.
Definition: largeobject.hxx:174
largeobject_streambuf(dbtransaction &t, oid o, openmode mode=default_mode, size_type buf_size=512)
Definition: largeobject.hxx:397
TRAITS traits_type
Definition: largeobject.hxx:548
TRAITS traits_type
Definition: largeobject.hxx:674
constexpr oid oid_none
The "null" oid.
Definition: util.hxx:211
int64_t large_object_size_type
Number of bytes in a large object.
Definition: types.hxx:33
virtual pos_type seekoff(off_type offset, seekdir dir, openmode) override
Definition: largeobject.hxx:422
basic_lostream(dbtransaction &t, oid o, largeobject::size_type buf_size=512)
Create a basic_lostream.
Definition: largeobject.hxx:700
bool operator==(largeobject const &other) const
Compare object identities.
Definition: largeobject.hxx:88
Connection to a database.
Definition: connection.hxx:169
typename traits_type::off_type off_type
Definition: largeobject.hxx:607
basic_ilostream(dbtransaction &t, oid o, largeobject::size_type buf_size=512)
Create a basic_ilostream.
Definition: largeobject.hxx:573
Abstract transaction base class: bracket transactions on the database.
Definition: dbtransaction.hxx:52
typename traits_type::off_type off_type
Definition: largeobject.hxx:551
CHAR char_type
Definition: largeobject.hxx:603
typename traits_type::pos_type pos_type
Definition: largeobject.hxx:550