19 #ifndef PQXX_H_LARGEOBJECT 20 #define PQXX_H_LARGEOBJECT 22 #include "pqxx/compiler-public.hxx" 23 #include "pqxx/compiler-internal-pre.hxx" 25 #ifdef PQXX_HAVE_STREAMBUF 28 #include <streambuf.h> 31 #include "pqxx/dbtransaction" 37 class largeobjectaccess;
86 oid
id()
const throw () {
return m_ID; }
99 {
return m_ID == other.m_ID; }
103 {
return m_ID != other.m_ID; }
107 {
return m_ID <= other.m_ID; }
111 {
return m_ID >= other.m_ID; }
115 {
return m_ID < other.m_ID; }
119 {
return m_ID > other.m_ID; }
127 void to_file(
dbtransaction &T,
const PGSTD::string &File)
const;
137 static internal::pq::PGconn * PQXX_PURE RawConnection(
const dbtransaction &T);
139 PGSTD::string Reason(
int err)
const;
201 openmode mode = PGSTD::ios::in | PGSTD::ios::out);
210 const PGSTD::string &File,
212 PGSTD::ios::in | PGSTD::ios::out);
229 #ifdef PQXX_BROKEN_USING_DECL 250 void write(
const char Buf[],
size_type Len);
256 void write(
const PGSTD::string &Buf)
257 { write(Buf.c_str(),
static_cast<size_type>(Buf.size())); }
299 pos_type cseek(off_type dest, seekdir dir)
throw ();
308 off_type cwrite(
const char Buf[],
size_type Len)
throw ();
317 off_type cread(
char Buf[],
size_type Len)
throw ();
324 pos_type ctell()
const throw ();
331 void process_notice(
const PGSTD::string &)
throw ();
337 using largeobject::operator==;
338 using largeobject::operator!=;
339 using largeobject::operator<;
340 using largeobject::operator<=;
341 using largeobject::operator>;
342 using largeobject::operator>=;
345 PGSTD::string PQXX_PRIVATE Reason(
int err)
const;
346 internal::pq::PGconn *RawConnection()
const 349 void open(openmode mode);
350 void close()
throw ();
371 template<
typename CHAR=
char,
typename TRAITS=PGSTD::
char_traits<CHAR> >
373 #ifdef PQXX_HAVE_STREAMBUF 374 public PGSTD::basic_streambuf<CHAR, TRAITS>
376 public PGSTD::streambuf
379 typedef long size_type;
384 #ifdef PQXX_HAVE_STREAMBUF 385 typedef typename traits_type::pos_type
pos_type;
386 typedef typename traits_type::off_type
off_type;
396 openmode mode = PGSTD::ios::in | PGSTD::ios::out,
397 size_type BufSize=512) :
402 { initialize(mode); }
406 openmode mode = PGSTD::ios::in | PGSTD::ios::out,
407 size_type BufSize=512) :
412 { initialize(mode); }
420 #ifdef PQXX_HAVE_STREAMBUF 426 this->setg(this->eback(), this->eback(), this->egptr());
427 return overflow(EoF());
438 virtual pos_type
seekpos(pos_type pos, openmode)
443 return AdjustEOF(newpos);
448 char *
const pp = this->pptr();
449 if (!pp)
return EoF();
450 char *
const pb = this->pbase();
453 if (pp > pb) res = int_type(AdjustEOF(m_Obj.cwrite(pb, pp-pb)));
454 this->setp(m_P, m_P + m_BufSize);
459 *this->pptr() = char(ch);
467 if (!this->gptr())
return EoF();
468 char *
const eb = this->eback();
469 const int_type res(static_cast<int_type>(
470 AdjustEOF(m_Obj.cread(this->eback(), m_BufSize))));
471 this->setg(eb, eb, eb + ((res==EoF()) ? 0 : res));
472 return (!res || (res == EoF())) ? EoF() : *eb;
477 static int_type EoF() {
return traits_type::eof(); }
480 template<
typename INTYPE>
481 static PGSTD::streampos AdjustEOF(INTYPE pos)
482 {
return (pos==-1) ? PGSTD::streampos(EoF()) : PGSTD::streampos(pos); }
484 void initialize(openmode mode)
486 if (mode & PGSTD::ios::in)
488 m_G =
new char_type[unsigned(m_BufSize)];
489 this->setg(m_G, m_G, m_G);
491 if (mode & PGSTD::ios::out)
493 m_P =
new char_type[unsigned(m_BufSize)];
494 this->setp(m_P, m_P + m_BufSize);
498 const size_type m_BufSize;
502 char_type *m_G, *m_P;
515 template<
typename CHAR=
char,
typename TRAITS=PGSTD::
char_traits<CHAR> >
517 #ifdef PQXX_HAVE_STREAMBUF 518 public PGSTD::basic_istream<CHAR, TRAITS>
520 public PGSTD::istream
523 #ifdef PQXX_HAVE_STREAMBUF 524 typedef PGSTD::basic_istream<CHAR, TRAITS> super;
526 typedef PGSTD::istream super;
546 m_Buf(T, O, PGSTD::ios::in, BufSize)
547 { super::init(&m_Buf); }
559 m_Buf(T, O, PGSTD::ios::in, BufSize)
560 { super::init(&m_Buf); }
578 template<
typename CHAR=
char,
typename TRAITS=PGSTD::
char_traits<CHAR> >
580 #ifdef PQXX_HAVE_STREAMBUF 581 public PGSTD::basic_ostream<CHAR, TRAITS>
583 public PGSTD::ostream
586 #ifdef PQXX_HAVE_STREAMBUF 587 typedef PGSTD::basic_ostream<CHAR, TRAITS> super;
589 typedef PGSTD::ostream super;
608 m_Buf(T, O, PGSTD::ios::out, BufSize)
609 { super::init(&m_Buf); }
621 m_Buf(T, O, PGSTD::ios::out, BufSize)
622 { super::init(&m_Buf); }
628 #ifdef PQXX_HAVE_STREAMBUF 629 m_Buf.pubsync(); m_Buf.pubsync();
631 m_Buf.sync(); m_Buf.sync();
634 catch (
const PGSTD::exception &e)
636 m_Buf.process_notice(e.what());
656 template<
typename CHAR=
char,
typename TRAITS=PGSTD::
char_traits<CHAR> >
658 #ifdef PQXX_HAVE_STREAMBUF 659 public PGSTD::basic_iostream<CHAR, TRAITS>
661 public PGSTD::iostream
664 #ifdef PQXX_HAVE_STREAMBUF 665 typedef PGSTD::basic_iostream<CHAR, TRAITS> super;
667 typedef PGSTD::iostream super;
687 m_Buf(T, O, PGSTD::ios::in | PGSTD::ios::out, BufSize)
688 { super::init(&m_Buf); }
700 m_Buf(T, O, PGSTD::ios::in | PGSTD::ios::out, BufSize)
701 { super::init(&m_Buf); }
707 #ifdef PQXX_HAVE_STREAMBUF 708 m_Buf.pubsync(); m_Buf.pubsync();
710 m_Buf.sync(); m_Buf.sync();
713 catch (
const PGSTD::exception &e)
715 m_Buf.process_notice(e.what());
727 #include "pqxx/compiler-internal-post.hxx" std::ios::seekdir seekdir
Seek direction: beg, cur, end.
Definition: largeobject.hxx:168
Input stream that gets its data from a large object.
Definition: largeobject.hxx:516
traits_type::off_type off_type
Definition: largeobject.hxx:534
bool operator>=(const largeobject &other) const
Compare object identities.
Definition: largeobject.hxx:110
traits_type::pos_type pos_type
Definition: largeobject.hxx:595
basic_olostream(dbtransaction &T, oid O, largeobject::size_type BufSize=512)
Create a basic_olostream.
Definition: largeobject.hxx:617
void to_file(const std::string &File) const
Export large object's contents to a local file.
Definition: largeobject.hxx:226
bool operator==(const largeobject &other) const
Compare object identities.
Definition: largeobject.hxx:98
~largeobjectaccess()
Definition: largeobject.hxx:214
Streambuf to use large objects in standard I/O streams.
Definition: largeobject.hxx:372
bool operator!=(const largeobject &other) const
Compare object identities.
Definition: largeobject.hxx:102
virtual ~largeobject_streambuf()
Definition: largeobject.hxx:414
basic_lostream< char > lostream
Definition: largeobject.hxx:723
std::ios::openmode openmode
Open mode: in, out (can be combined with the "or" operator)
Definition: largeobject.hxx:161
oid id() const
Object identifier.
Definition: largeobject.hxx:86
size_type pos_type
Definition: largeobject.hxx:154
void process_notice(const std::string &s)
For use by large object stream classes.
Definition: largeobject.hxx:418
~basic_olostream()
Definition: largeobject.hxx:624
virtual pos_type seekpos(pos_type pos, openmode)
Definition: largeobject.hxx:438
void write(const std::string &Buf)
Write string to large object.
Definition: largeobject.hxx:256
void remove(dbtransaction &T) const
Delete large object from database.
Definition: largeobject.cxx:128
virtual int sync()
Definition: largeobject.hxx:423
TRAITS traits_type
Definition: largeobject.hxx:593
traits_type::off_type off_type
Definition: largeobject.hxx:675
basic_olostream(dbtransaction &T, largeobject O, largeobject::size_type BufSize=512)
Create a basic_olostream.
Definition: largeobject.hxx:604
basic_ilostream(dbtransaction &T, oid O, largeobject::size_type BufSize=512)
Create a basic_ilostream.
Definition: largeobject.hxx:555
basic_lostream(dbtransaction &T, largeobject O, largeobject::size_type BufSize=512)
Create a basic_lostream.
Definition: largeobject.hxx:683
traits_type::int_type int_type
Definition: largeobject.hxx:383
CHAR char_type
Definition: largeobject.hxx:530
TRAITS traits_type
Definition: largeobject.hxx:382
bool operator<(const largeobject &other) const
Compare object identities.
Definition: largeobject.hxx:114
Output stream that writes data back to a large object.
Definition: largeobject.hxx:579
basic_ilostream(dbtransaction &T, largeobject O, largeobject::size_type BufSize=512)
Create a basic_ilostream.
Definition: largeobject.hxx:542
basic_olostream< char > olostream
Definition: largeobject.hxx:644
Identity of a large object.
Definition: largeobject.hxx:47
traits_type::int_type int_type
Definition: largeobject.hxx:673
Definition: dbtransaction.hxx:73
traits_type::pos_type pos_type
Definition: largeobject.hxx:533
traits_type::pos_type pos_type
Definition: largeobject.hxx:674
CHAR char_type
Definition: largeobject.hxx:381
The home of all libpqxx classes, functions, templates, etc.
Definition: basic_connection.hxx:35
largeobject_streambuf(dbtransaction &T, oid O, openmode mode=std::ios::in|std::ios::out, size_type BufSize=512)
Definition: largeobject.hxx:404
basic_lostream(dbtransaction &T, oid O, largeobject::size_type BufSize=512)
Create a basic_lostream.
Definition: largeobject.hxx:696
CHAR char_type
Definition: largeobject.hxx:592
basic_ilostream< char > ilostream
Definition: largeobject.hxx:566
largeobject_streambuf(dbtransaction &T, largeobject O, openmode mode=std::ios::in|std::ios::out, size_type BufSize=512)
Definition: largeobject.hxx:394
Stream that reads and writes a large object.
Definition: largeobject.hxx:657
bool operator<=(const largeobject &other) const
Compare object identities.
Definition: largeobject.hxx:106
streamoff off_type
Definition: largeobject.hxx:388
long size_type
Definition: largeobject.hxx:50
largeobjectaccess::openmode openmode
Definition: largeobject.hxx:391
virtual int_type overflow(int_type ch=EoF())
Definition: largeobject.hxx:446
Accessor for large object's contents.
Definition: largeobject.hxx:149
TRAITS traits_type
Definition: largeobject.hxx:531
bool operator>(const largeobject &other) const
Compare object identities.
Definition: largeobject.hxx:118
CHAR char_type
Definition: largeobject.hxx:671
traits_type::off_type off_type
Definition: largeobject.hxx:596
void to_file(dbtransaction &T, const std::string &File) const
Export large object's contents to a local file.
Definition: largeobject.cxx:114
~basic_lostream()
Definition: largeobject.hxx:703
long off_type
Definition: largeobject.hxx:153
virtual pos_type seekoff(off_type offset, seekdir dir, openmode)
Definition: largeobject.hxx:431
virtual int_type underflow()
Definition: largeobject.hxx:465
TRAITS traits_type
Definition: largeobject.hxx:672
streampos pos_type
Definition: largeobject.hxx:389
static internal::pq::PGconn *PQXX_PURE RawConnection(const dbtransaction &T)
Definition: largeobject.cxx:140
traits_type::int_type int_type
Definition: largeobject.hxx:594
traits_type::int_type int_type
Definition: largeobject.hxx:532
largeobjectaccess::seekdir seekdir
Definition: largeobject.hxx:392