/usr/include/pqxx/tablewriter.hxx is in libpqxx3-dev 1:3.1.1-0ubuntu4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | /*-------------------------------------------------------------------------
*
* FILE
* pqxx/tablewriter.hxx
*
* DESCRIPTION
* definition of the pqxx::tablewriter class.
* pqxx::tablewriter enables optimized batch updates to a database table
* DO NOT INCLUDE THIS FILE DIRECTLY; include pqxx/tablewriter.hxx instead.
*
* Copyright (c) 2001-2008, Jeroen T. Vermeulen <jtv@xs4all.nl>
*
* See COPYING for copyright license. If you did not receive a file called
* COPYING with this source code, please notify the distributor of this mistake,
* or contact the author.
*
*-------------------------------------------------------------------------
*/
#ifndef PQXX_H_TABLEWRITER
#define PQXX_H_TABLEWRITER
#include "pqxx/compiler-public.hxx"
#include "pqxx/compiler-internal-pre.hxx"
#include "pqxx/tablestream"
/* Methods tested in eg. self-test program test001 are marked with "//[t1]"
*/
namespace pqxx
{
class tablereader; // See pqxx/tablereader.h
/// Efficiently write data directly to a database table.
/** A tablewriter provides a Spartan but efficient way of writing data tuples
* into a table. It provides a plethora of STL-like insertion methods: it has
* insert() methods, push_back(), as well as an overloaded insertion operator
* (<tt><<</tt>), and it supports inserters created by std::back_inserter().
* All of these are templatized so you can use any container type or iterator
* range to feed tuples into the table.
*
* Note that in each case, a container or range represents the fields of a
* single tuple--not a collection of tuples.
*/
class PQXX_LIBEXPORT tablewriter : public tablestream
{
public:
typedef unsigned size_type;
tablewriter(transaction_base &,
const PGSTD::string &WName,
const PGSTD::string &Null=PGSTD::string()); //[t5]
/// Write only the given sequence of columns
/** @since PostgreSQL backend 7.3.
*
* This constructor takes a sequence of names of columns to write to. Only
* those columns will be written, and they will be taken from your input data
* in that order.
*/
template<typename ITER> tablewriter(transaction_base &,
const PGSTD::string &WName,
ITER begincolumns,
ITER endcolumns); //[t9]
/// Write only the given sequence of columns, with customized "null" string
/** @since PostgreSQL backend 7.3.
*
* This constructor takes a sequence of names of columns to write to. Only
* those columns will be written, and they will be taken from your input data
* in that order.
*
* @param T The transaction that this tablewriter will operate on.
* @param WName A name for this table writer, to help with debugging.
* @param begincolumns Beginning of a sequence of names of columns to write.
* @param endcolumns End of a sequence of names of columns to write.
* @param Null The string that is used in your input data to denote null.
*/
template<typename ITER> tablewriter(transaction_base &T,
const PGSTD::string &WName,
ITER begincolumns,
ITER endcolumns,
const PGSTD::string &Null); //[t9]
~tablewriter() throw (); //[t5]
template<typename IT> void insert(IT Begin, IT End); //[t5]
template<typename TUPLE> void insert(const TUPLE &); //[t5]
template<typename IT> void push_back(IT Begin, IT End); //[t10]
template<typename TUPLE> void push_back(const TUPLE &); //[t10]
void reserve(size_type) {} //[t9]
template<typename TUPLE> tablewriter &operator<<(const TUPLE &); //[t5]
/// Copy table from one database to another
tablewriter &operator<<(tablereader &); //[t6]
/// Translate tuple of data to a string in DBMS-specific format.
/** @warning This is definitely not portable between databases.
*/
template<typename IT> PGSTD::string generate(IT Begin, IT End) const; //[t10]
template<typename TUPLE> PGSTD::string generate(const TUPLE &) const; //[t10]
/// Finish stream action, check for errors, and detach from transaction
/** It is recommended that you call this function before the tablestream's
* destructor is run. This function will check any final errors which may not
* become apparent until the transaction is committed otherwise.
*
* As an added benefit, this will free up the transaction while the
* tablestream object itself still exists.
*/
virtual void complete(); //[t5]
/// Write line of raw data (e.g. obtained from tablereader.get_raw_line).
void write_raw_line(const PGSTD::string &);
private:
void setup(transaction_base &,
const PGSTD::string &WName,
const PGSTD::string &Columns = PGSTD::string());
void PQXX_PRIVATE writer_close();
};
} // namespace pqxx
namespace PGSTD
{
/// Specialized back_insert_iterator for tablewriter
/** Doesn't require a value_type to be defined. Accepts any container type
* instead.
*/
template<>
class back_insert_iterator<pqxx::tablewriter> : //[t9]
public iterator<output_iterator_tag, void,void,void,void>
{
public:
explicit back_insert_iterator(pqxx::tablewriter &W) throw () : //[t83]
m_Writer(&W) {}
back_insert_iterator &
operator=(const back_insert_iterator &rhs) throw () //[t83]
{
m_Writer = rhs.m_Writer;
return *this;
}
template<typename TUPLE>
back_insert_iterator &operator=(const TUPLE &T) //[t83]
{
m_Writer->insert(T);
return *this;
}
back_insert_iterator &operator++() { return *this; } //[t83]
back_insert_iterator &operator++(int) { return *this; } //[t83]
back_insert_iterator &operator*() { return *this; } //[t83]
private:
pqxx::tablewriter *m_Writer;
};
} // namespace PGSTD
namespace pqxx
{
template<typename ITER> inline tablewriter::tablewriter(transaction_base &T,
const PGSTD::string &WName,
ITER begincolumns,
ITER endcolumns) :
namedclass("tablewriter", WName),
tablestream(T, PGSTD::string())
{
setup(T, WName, columnlist(begincolumns, endcolumns));
}
template<typename ITER> inline tablewriter::tablewriter(transaction_base &T,
const PGSTD::string &WName,
ITER begincolumns,
ITER endcolumns,
const PGSTD::string &Null) :
namedclass("tablewriter", WName),
tablestream(T, Null)
{
setup(T, WName, columnlist(begincolumns, endcolumns));
}
namespace internal
{
PGSTD::string PQXX_LIBEXPORT Escape(const PGSTD::string &s,
const PGSTD::string &null);
template<typename STR> inline PGSTD::string EscapeAny(const PGSTD::string &s,
const PGSTD::string &null) { return Escape(s,null); }
template<typename STR> inline PGSTD::string EscapeAny(const char s[],
const PGSTD::string &null) {return s ? Escape(PGSTD::string(s),null):"\\N";}
template<typename T> inline PGSTD::string EscapeAny(const T &t,
const PGSTD::string &null) { return Escape(to_string(t), null); }
template<typename IT> class Escaper
{
const PGSTD::string &m_null;
public:
explicit Escaper(const PGSTD::string &null) : m_null(null) {}
PGSTD::string operator()(IT i) const { return EscapeAny(*i, m_null); }
};
}
template<typename IT>
inline PGSTD::string tablewriter::generate(IT Begin, IT End) const
{
return separated_list("\t", Begin, End, internal::Escaper<IT>(NullStr()));
}
template<typename TUPLE>
inline PGSTD::string tablewriter::generate(const TUPLE &T) const
{
return generate(T.begin(), T.end());
}
template<typename IT> inline void tablewriter::insert(IT Begin, IT End)
{
write_raw_line(generate(Begin, End));
}
template<typename TUPLE> inline void tablewriter::insert(const TUPLE &T)
{
insert(T.begin(), T.end());
}
template<typename IT>
inline void tablewriter::push_back(IT Begin, IT End)
{
insert(Begin, End);
}
template<typename TUPLE>
inline void tablewriter::push_back(const TUPLE &T)
{
insert(T.begin(), T.end());
}
template<typename TUPLE>
inline tablewriter &tablewriter::operator<<(const TUPLE &T)
{
insert(T);
return *this;
}
} // namespace pqxx
#include "pqxx/compiler-internal-post.hxx"
#endif
|