13 #ifndef PQXX_H_LARGEOBJECT 14 #define PQXX_H_LARGEOBJECT 16 #include "pqxx/compiler-public.hxx" 17 #include "pqxx/internal/compiler-internal-pre.hxx" 21 #include "pqxx/dbtransaction.hxx" 74 [[nodiscard]] oid
id() const noexcept {
return m_id; }
88 return m_id == other.m_id;
94 return m_id != other.m_id;
100 return m_id <= other.m_id;
106 return m_id >= other.m_id;
112 return m_id < other.m_id;
118 return m_id > other.m_id;
137 PQXX_PURE
static internal::pq::PGconn *
140 PQXX_PRIVATE std::string reason(
connection const &,
int err)
const;
166 static constexpr
auto default_mode{
167 std::ios::in | std::ios::out | std::ios::binary};
238 void write(
char const buf[], std::size_t len);
244 void write(std::string_view buf) {
write(buf.data(), std::size(buf)); }
253 size_type read(
char buf[], std::size_t len);
298 off_type cwrite(
char const buf[], std::size_t len) noexcept;
307 off_type cread(
char buf[], std::size_t len) noexcept;
314 [[nodiscard]]
pos_type ctell()
const noexcept;
321 void process_notice(
zview) noexcept;
327 using largeobject::operator==;
328 using largeobject::operator!=;
329 using largeobject::operator<;
330 using largeobject::operator<=;
331 using largeobject::operator>;
332 using largeobject::operator>=;
339 PQXX_PRIVATE std::string reason(
int err)
const;
340 internal::pq::PGconn *raw_connection()
const 345 PQXX_PRIVATE
void open(
openmode mode);
346 void close() noexcept;
362 template<
typename CHAR =
char,
typename TRAITS = std::
char_traits<CHAR>>
377 static constexpr
auto default_mode{
378 std::ios::in | std::ios::out | std::ios::binary};
382 size_type buf_size = 512) :
383 m_bufsize{buf_size}, m_obj{t, o, mode}, m_g{
nullptr}, m_p{
nullptr}
390 size_type buf_size = 512) :
391 m_bufsize{buf_size}, m_obj{t, o, mode}, m_g{
nullptr}, m_p{
nullptr}
409 this->setg(this->eback(), this->eback(), this->egptr());
410 return overflow(eof());
422 return adjust_eof(newpos);
427 auto *
const pp{this->pptr()};
430 auto *
const pb{this->pbase()};
435 auto const write_sz{pp - pb};
436 auto const written_sz{
437 m_obj.cwrite(pb, static_cast<std::size_t>(pp - pb))};
438 if (written_sz <= static_cast<off_type>(0))
440 "pqxx::largeobject: write failed " 441 "(is transaction still valid on write or flush?), " 442 "libpq reports error"};
443 else if (write_sz != written_sz)
445 "pqxx::largeobject: write failed " 446 "(is transaction still valid on write or flush?), " +
449 auto const out{adjust_eof(written_sz)};
451 if constexpr (std::is_arithmetic_v<decltype(out)>)
456 this->setp(m_p, m_p + m_bufsize);
461 *this->pptr() =
static_cast<char_type>(ch);
471 if (this->gptr() ==
nullptr)
473 auto *
const eb{this->eback()};
474 auto const res{adjust_eof(
475 m_obj.cread(this->eback(),
static_cast<std::size_t
>(m_bufsize)))};
477 eb, eb, eb + (res == eof() ? 0 : static_cast<std::size_t>(res)));
478 return (res == eof() or res == 0) ? eof() : traits_type::to_int_type(*eb);
483 static int_type eof() {
return traits_type::eof(); }
486 template<
typename INTYPE>
static std::streampos adjust_eof(INTYPE pos)
488 bool const at_eof{pos == -1};
489 if constexpr (std::is_arithmetic_v<std::streampos>)
492 (at_eof ? eof() : pos),
"large object seek"sv);
496 return std::streampos(at_eof ? eof() : pos);
502 if ((mode & std::ios::in) != 0)
504 m_g =
new char_type[unsigned(m_bufsize)];
505 this->setg(m_g, m_g, m_g);
507 if ((mode & std::ios::out) != 0)
509 m_p =
new char_type[unsigned(m_bufsize)];
510 this->setp(m_p, m_p + m_bufsize);
514 size_type
const m_bufsize;
531 template<
typename CHAR =
char,
typename TRAITS = std::
char_traits<CHAR>>
534 using super = std::basic_istream<CHAR, TRAITS>;
552 m_buf{t, o, std::ios::in | std::ios::binary, buf_size}
566 m_buf{t, o, std::ios::in | std::ios::binary, buf_size}
587 template<
typename CHAR =
char,
typename TRAITS = std::
char_traits<CHAR>>
590 using super = std::basic_ostream<CHAR, TRAITS>;
608 m_buf{t, o, std::ios::out | std::ios::binary, buf_size}
622 m_buf{t, o, std::ios::out | std::ios::binary, buf_size}
634 catch (std::exception
const &e)
636 m_buf.process_notice(e.what());
656 template<
typename CHAR =
char,
typename TRAITS = std::
char_traits<CHAR>>
659 using super = std::basic_iostream<CHAR, TRAITS>;
678 t, o, std::ios::in | std::ios::out | std::ios::binary, buf_size}
693 t, o, std::ios::in | std::ios::out | std::ios::binary, buf_size}
705 catch (std::exception
const &e)
707 m_buf.process_notice(e.what());
718 #include "pqxx/internal/compiler-internal-post.hxx" CHAR char_type
Definition: largeobject.hxx:593
TRAITS traits_type
Definition: largeobject.hxx:594
typename traits_type::off_type off_type
Definition: largeobject.hxx:666
virtual int_type overflow()
Definition: largeobject.hxx:467
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
typename traits_type::off_type off_type
Definition: largeobject.hxx:541
largeobject_streambuf(dbtransaction &t, largeobject o, openmode mode=default_mode, size_type buf_size=512)
Definition: largeobject.hxx:380
bool operator>(largeobject const &other) const
Compare object identities.
Definition: largeobject.hxx:116
Output stream that writes data back to a large object.
Definition: largeobject.hxx:588
largeobjectaccess::seekdir seekdir
Definition: largeobject.hxx:374
Accessor for large object's contents.
Definition: largeobject.hxx:148
int64_t large_object_size_type
Number of bytes in a large object.
Definition: types.hxx:33
typename traits_type::int_type int_type
Definition: largeobject.hxx:370
bool operator!=(largeobject const &other) const
Compare object identities.
Definition: largeobject.hxx:92
virtual pos_type seekoff(off_type offset, seekdir dir, openmode) override
Definition: largeobject.hxx:413
basic_ilostream(dbtransaction &t, largeobject o, largeobject::size_type buf_size=512)
Create a basic_ilostream.
Definition: largeobject.hxx:549
virtual ~largeobject_streambuf() noexcept
Definition: largeobject.hxx:396
size_type off_type
Definition: largeobject.hxx:152
std::ios::openmode openmode
Open mode: in, out (can be combined using "bitwise or").
Definition: largeobject.hxx:163
std::ios::seekdir seekdir
Seek direction: beg, cur, end.
Definition: largeobject.hxx:170
CHAR char_type
Definition: largeobject.hxx:537
~basic_lostream()
Definition: largeobject.hxx:698
bool operator>=(largeobject const &other) const
Compare object identities.
Definition: largeobject.hxx:104
largeobject_streambuf(dbtransaction &t, oid o, openmode mode=default_mode, size_type buf_size=512)
Definition: largeobject.hxx:388
Internal error in libpqxx library.
Definition: except.hxx:157
virtual int sync() override
Definition: largeobject.hxx:406
typename traits_type::pos_type pos_type
Definition: largeobject.hxx:665
basic_lostream(dbtransaction &t, oid o, largeobject::size_type buf_size=512)
Create a basic_lostream.
Definition: largeobject.hxx:689
oid id() const noexcept
Object identifier.
Definition: largeobject.hxx:74
~basic_olostream()
Definition: largeobject.hxx:627
void to_file(std::string_view file) const
Export large object's contents to a local file.
Definition: largeobject.hxx:221
basic_ilostream(dbtransaction &t, oid o, largeobject::size_type buf_size=512)
Create a basic_ilostream.
Definition: largeobject.hxx:563
bool operator==(largeobject const &other) const
Compare object identities.
Definition: largeobject.hxx:86
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:25
size_type pos_type
Definition: largeobject.hxx:153
static PQXX_PURE internal::pq::PGconn * raw_connection(dbtransaction const &T)
Definition: largeobject.cxx:132
typename traits_type::pos_type pos_type
Definition: largeobject.hxx:596
basic_lostream(dbtransaction &t, largeobject o, largeobject::size_type buf_size=512)
Create a basic_lostream.
Definition: largeobject.hxx:674
constexpr oid oid_none
The "null" oid.
Definition: util.hxx:211
typename traits_type::off_type off_type
Definition: largeobject.hxx:597
void to_file(dbtransaction &t, std::string_view file) const
Export large object's contents to a local file.
Definition: largeobject.cxx:100
bool operator<(largeobject const &other) const
Compare object identities.
Definition: largeobject.hxx:110
CHAR char_type
Definition: largeobject.hxx:662
typename traits_type::pos_type pos_type
Definition: largeobject.hxx:371
Connection to a database.
Definition: connection.hxx:163
TRAITS traits_type
Definition: largeobject.hxx:538
largeobjectaccess::openmode openmode
Definition: largeobject.hxx:373
typename traits_type::int_type int_type
Definition: largeobject.hxx:595
void process_notice(zview const &s)
For use by large object stream classes.
Definition: largeobject.hxx:403
Input stream that gets its data from a large object.
Definition: largeobject.hxx:532
Abstract transaction base class: bracket transactions on the database.
Definition: dbtransaction.hxx:52
virtual pos_type seekpos(pos_type pos, openmode) override
Definition: largeobject.hxx:418
basic_olostream(dbtransaction &t, largeobject o, largeobject::size_type buf_size=512)
Create a basic_olostream.
Definition: largeobject.hxx:605
virtual int_type underflow() override
Definition: largeobject.hxx:469
basic_olostream(dbtransaction &t, oid o, largeobject::size_type buf_size=512)
Create a basic_olostream.
Definition: largeobject.hxx:619
Identity of a large object.
Definition: largeobject.hxx:34
typename traits_type::off_type off_type
Definition: largeobject.hxx:372
large_object_size_type size_type
Definition: largeobject.hxx:37
CHAR char_type
Definition: largeobject.hxx:368
typename traits_type::pos_type pos_type
Definition: largeobject.hxx:540
void remove(dbtransaction &t) const
Delete large object from database.
Definition: largeobject.cxx:116
Marker-type wrapper: zero-terminated std::string_view.
Definition: zview.hxx:37
typename traits_type::int_type int_type
Definition: largeobject.hxx:539
Stream that reads and writes a large object.
Definition: largeobject.hxx:657
std::string to_string(TYPE const &value)
Convert a value to a readable string that PostgreSQL will understand.
virtual int_type overflow(int_type ch) override
Definition: largeobject.hxx:425
~largeobjectaccess() noexcept
Definition: largeobject.hxx:209
void write(std::string_view buf)
Write string to large object.
Definition: largeobject.hxx:244
TRAITS traits_type
Definition: largeobject.hxx:663
bool operator<=(largeobject const &other) const
Compare object identities.
Definition: largeobject.hxx:98
TRAITS traits_type
Definition: largeobject.hxx:369
typename traits_type::int_type int_type
Definition: largeobject.hxx:664
Streambuf to use large objects in standard I/O streams.
Definition: largeobject.hxx:363