13 #ifndef PQXX_H_LARGEOBJECT 14 #define PQXX_H_LARGEOBJECT 16 #include "pqxx/compiler-public.hxx" 17 #include "pqxx/compiler-internal-pre.hxx" 21 #include "pqxx/dbtransaction.hxx" 73 oid
id() const noexcept {
return m_id; }
86 {
return m_id == other.m_id; }
90 {
return m_id != other.m_id; }
94 {
return m_id <= other.m_id; }
98 {
return m_id >= other.m_id; }
102 {
return m_id < other.m_id; }
106 {
return m_id > other.m_id; }
114 void to_file(
dbtransaction &T,
const std::string &File)
const;
124 PQXX_PURE
static internal::pq::PGconn *raw_connection(
127 PQXX_PRIVATE std::string reason(
const connection_base &,
int err)
const;
165 openmode mode=std::ios::in|std::ios::out);
177 openmode mode=std::ios::in|std::ios::out);
188 openmode mode=std::ios::in|std::ios::out);
198 const std::string &File,
199 openmode mode=std::ios::in|std::ios::out);
227 void write(
const char Buf[],
size_type Len);
234 { write(Buf.c_str(),
static_cast<size_type>(Buf.size())); }
308 void process_notice(
const std::string &) noexcept;
314 using largeobject::operator==;
315 using largeobject::operator!=;
316 using largeobject::operator<;
317 using largeobject::operator<=;
318 using largeobject::operator>;
319 using largeobject::operator>=;
322 PQXX_PRIVATE std::string reason(
int err)
const;
323 internal::pq::PGconn *raw_connection()
const 326 PQXX_PRIVATE
void open(
openmode mode);
327 void close() noexcept;
347 template<
typename CHAR=
char,
typename TRAITS=std::
char_traits<CHAR>>
349 public std::basic_streambuf<CHAR, TRAITS>
351 using size_type = long;
364 openmode mode=std::ios::in|std::ios::out,
365 size_type BufSize=512) :
370 { initialize(mode); }
375 openmode mode=std::ios::in|std::ios::out,
376 size_type BufSize=512) :
381 { initialize(mode); }
384 {
delete [] m_p;
delete [] m_g; }
394 this->setg(this->eback(), this->eback(), this->egptr());
395 return overflow(EoF());
412 return AdjustEOF(newpos);
417 char *
const pp = this->pptr();
418 if (pp ==
nullptr)
return EoF();
419 char *
const pb = this->pbase();
422 if (pp > pb) res =
int_type(AdjustEOF(m_obj.cwrite(pb, pp-pb)));
423 this->setp(m_p, m_p + m_bufsize);
428 *this->pptr() = char(ch);
436 if (this->gptr() ==
nullptr)
return EoF();
437 char *
const eb = this->eback();
438 const int_type res(static_cast<int_type>(
439 AdjustEOF(m_obj.cread(this->eback(), m_bufsize))));
440 this->setg(eb, eb, eb + ((res==EoF()) ? 0 : res));
441 return ((res == 0) or (res == EoF())) ? EoF() : *eb;
446 static int_type EoF() {
return traits_type::eof(); }
449 template<
typename INTYPE>
450 static std::streampos AdjustEOF(INTYPE pos)
451 {
return (pos==-1) ? std::streampos(EoF()) : std::streampos(pos); }
455 if (mode & std::ios::in)
457 m_g =
new char_type[unsigned(m_bufsize)];
458 this->setg(m_g, m_g, m_g);
460 if (mode & std::ios::out)
462 m_p =
new char_type[unsigned(m_bufsize)];
463 this->setp(m_p, m_p + m_bufsize);
467 const size_type m_bufsize;
484 template<
typename CHAR=
char,
typename TRAITS=std::
char_traits<CHAR>>
486 public std::basic_istream<CHAR, TRAITS>
488 using super = std::basic_istream<CHAR, TRAITS>;
508 m_buf{T, O, std::ios::in, BufSize}
509 { super::init(&m_buf); }
522 m_buf{T, O, std::ios::in, BufSize}
523 { super::init(&m_buf); }
541 template<
typename CHAR=
char,
typename TRAITS=std::
char_traits<CHAR>>
543 public std::basic_ostream<CHAR, TRAITS>
545 using super = std::basic_ostream<CHAR, TRAITS>;
564 m_buf{T, O, std::ios::out, BufSize}
565 { super::init(&m_buf); }
578 m_buf{T, O, std::ios::out, BufSize}
579 { super::init(&m_buf); }
585 m_buf.pubsync(); m_buf.pubsync();
587 catch (
const std::exception &e)
589 m_buf.process_notice(e.what());
609 template<
typename CHAR=
char,
typename TRAITS=std::
char_traits<CHAR>>
611 public std::basic_iostream<CHAR, TRAITS>
613 using super = std::basic_iostream<CHAR, TRAITS>;
633 m_buf{T, O, std::ios::in | std::ios::out, BufSize}
634 { super::init(&m_buf); }
647 m_buf{T, O, std::ios::in | std::ios::out, BufSize}
648 { super::init(&m_buf); }
654 m_buf.pubsync(); m_buf.pubsync();
656 catch (
const std::exception &e)
658 m_buf.process_notice(e.what());
670 #include "pqxx/compiler-internal-post.hxx" typename traits_type::off_type off_type
Definition: largeobject.hxx:357
~largeobjectaccess() noexcept
Definition: largeobject.hxx:201
CHAR char_type
Definition: largeobject.hxx:547
long off_type
Definition: largeobject.hxx:141
void to_file(dbtransaction &T, const std::string &File) const
Export large object's contents to a local file.
Definition: largeobject.cxx:106
virtual pos_type seekpos(pos_type pos, openmode) override
Definition: largeobject.hxx:407
bool operator>(const largeobject &other) const
Compare object identities.
Definition: largeobject.hxx:105
CHAR char_type
Definition: largeobject.hxx:616
virtual pos_type seekoff(off_type offset, seekdir dir, openmode) override
Definition: largeobject.hxx:398
void process_notice(const std::string &s)
For use by large object stream classes.
Definition: largeobject.hxx:388
bool operator<=(const largeobject &other) const
Compare object identities.
Definition: largeobject.hxx:93
TRAITS traits_type
Definition: largeobject.hxx:354
Input stream that gets its data from a large object.
Definition: largeobject.hxx:485
std::ios::openmode openmode
Open mode: in, out (can be combined with the "or" operator)
Definition: largeobject.hxx:149
basic_lostream(dbtransaction &T, oid O, largeobject::size_type BufSize=512)
Create a basic_lostream.
Definition: largeobject.hxx:642
typename traits_type::int_type int_type
Definition: largeobject.hxx:355
typename traits_type::pos_type pos_type
Definition: largeobject.hxx:494
connection_base abstract base class; represents a connection to a database.
Definition: connection_base.hxx:139
largeobjectaccess::seekdir seekdir
Definition: largeobject.hxx:359
TRAITS traits_type
Definition: largeobject.hxx:548
constexpr oid oid_none
The "null" oid.
Definition: util.hxx:77
typename traits_type::int_type int_type
Definition: largeobject.hxx:549
TRAITS traits_type
Definition: largeobject.hxx:492
Identity of a large object.
Definition: largeobject.hxx:34
basic_olostream(dbtransaction &T, oid O, largeobject::size_type BufSize=512)
Create a basic_olostream.
Definition: largeobject.hxx:573
basic_lostream(dbtransaction &T, largeobject O, largeobject::size_type BufSize=512)
Create a basic_lostream.
Definition: largeobject.hxx:628
CHAR char_type
Definition: largeobject.hxx:353
bool operator<(const largeobject &other) const
Compare object identities.
Definition: largeobject.hxx:101
Stream that reads and writes a large object.
Definition: largeobject.hxx:610
typename traits_type::pos_type pos_type
Definition: largeobject.hxx:619
Streambuf to use large objects in standard I/O streams.
Definition: largeobject.hxx:348
Abstract base class responsible for bracketing a backend transaction.
Definition: dbtransaction.hxx:62
virtual int sync() override
Definition: largeobject.hxx:391
typename traits_type::off_type off_type
Definition: largeobject.hxx:495
basic_ilostream(dbtransaction &T, oid O, largeobject::size_type BufSize=512)
Create a basic_ilostream.
Definition: largeobject.hxx:517
virtual ~largeobject_streambuf() noexcept
Definition: largeobject.hxx:383
typename traits_type::off_type off_type
Definition: largeobject.hxx:551
largeobject_streambuf(dbtransaction &T, largeobject O, openmode mode=std::ios::in|std::ios::out, size_type BufSize=512)
Definition: largeobject.hxx:361
largeobject_streambuf(dbtransaction &T, oid O, openmode mode=std::ios::in|std::ios::out, size_type BufSize=512)
Definition: largeobject.hxx:372
Output stream that writes data back to a large object.
Definition: largeobject.hxx:542
virtual int_type underflow() override
Definition: largeobject.hxx:434
Accessor for large object's contents.
Definition: largeobject.hxx:137
typename traits_type::off_type off_type
Definition: largeobject.hxx:620
std::ios::seekdir seekdir
Seek direction: beg, cur, end.
Definition: largeobject.hxx:156
bool operator!=(const largeobject &other) const
Compare object identities.
Definition: largeobject.hxx:89
static PQXX_PURE internal::pq::PGconn * raw_connection(const dbtransaction &T)
Definition: largeobject.cxx:134
basic_ilostream(dbtransaction &T, largeobject O, largeobject::size_type BufSize=512)
Create a basic_ilostream.
Definition: largeobject.hxx:503
void remove(dbtransaction &T) const
Delete large object from database.
Definition: largeobject.cxx:121
TRAITS traits_type
Definition: largeobject.hxx:617
long large_object_size_type
Number of bytes in a large object. (Unusual: it's signed.)
Definition: types.hxx:33
size_type pos_type
Definition: largeobject.hxx:142
~basic_lostream()
Definition: largeobject.hxx:650
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:25
void write(const std::string &Buf)
Write string to large object.
Definition: largeobject.hxx:233
typename traits_type::int_type int_type
Definition: largeobject.hxx:618
basic_olostream(dbtransaction &T, largeobject O, largeobject::size_type BufSize=512)
Create a basic_olostream.
Definition: largeobject.hxx:559
typename traits_type::int_type int_type
Definition: largeobject.hxx:493
~basic_olostream()
Definition: largeobject.hxx:581
bool operator==(const largeobject &other) const
Compare object identities.
Definition: largeobject.hxx:85
typename traits_type::pos_type pos_type
Definition: largeobject.hxx:356
void to_file(const std::string &File) const
Export large object's contents to a local file.
Definition: largeobject.hxx:213
large_object_size_type size_type
Definition: largeobject.hxx:37
typename traits_type::pos_type pos_type
Definition: largeobject.hxx:550
largeobjectaccess::openmode openmode
Definition: largeobject.hxx:358
CHAR char_type
Definition: largeobject.hxx:491
oid id() const noexcept
Object identifier.
Definition: largeobject.hxx:73
bool operator>=(const largeobject &other) const
Compare object identities.
Definition: largeobject.hxx:97
virtual int_type overflow(int_type ch=EoF()) override
Definition: largeobject.hxx:415