/usr/include/soci/postgresql/soci-postgresql.h is in libsoci-dev 3.2.3-2ubuntu2.
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 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 | //
// Copyright (C) 2004-2008 Maciej Sobczak, Stephen Hutton
// Copyright (C) 2011 Gevorg Voskanyan
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef SOCI_POSTGRESQL_H_INCLUDED
#define SOCI_POSTGRESQL_H_INCLUDED
#ifdef _WIN32
# ifdef SOCI_DLL
# ifdef SOCI_POSTGRESQL_SOURCE
# define SOCI_POSTGRESQL_DECL __declspec(dllexport)
# else
# define SOCI_POSTGRESQL_DECL __declspec(dllimport)
# endif // SOCI_POSTGRESQL_SOURCE
# endif // SOCI_DLL
#endif // _WIN32
//
// If SOCI_POSTGRESQL_DECL isn't defined yet define it now
#ifndef SOCI_POSTGRESQL_DECL
# define SOCI_POSTGRESQL_DECL
#endif
#include <soci-backend.h>
#include <libpq-fe.h>
#include <vector>
#ifdef _MSC_VER
#pragma warning(disable:4512 4511)
#endif
namespace soci
{
class postgresql_soci_error : public soci_error
{
public:
postgresql_soci_error(std::string const & msg, char const * sqlst);
std::string sqlstate() const;
private:
char sqlstate_[ 5 ]; // not std::string to keep copy-constructor no-throw
};
namespace details
{
// A class thinly encapsulating PGresult. Its main purpose is to ensure that
// PQclear() is always called, avoiding result memory leaks.
class postgresql_result
{
public:
// Creates a wrapper for the given, possibly NULL, result. The wrapper
// object takes ownership of the object and will call PQclear() on it.
explicit postgresql_result(PGresult* result = NULL)
{
init(result);
}
// Frees any currently stored result pointer and takes ownership of the
// given one.
void reset(PGresult* result = NULL)
{
free();
init(result);
}
// Check whether the status is PGRES_COMMAND_OK and throw an exception if
// it is different. Notice that if the query can return any results,
// check_for_data() below should be used instead to verify whether anything
// was returned or not.
//
// The provided error message is used only for the exception being thrown
// and should describe the operation which yielded this result.
void check_for_errors(char const* errMsg) const;
// Check whether the status indicates successful query completion, either
// with the return results (in which case true is returned) or without them
// (then false is returned). If the status corresponds to an error, throws
// an exception, just as check_for_errors().
bool check_for_data(char const* errMsg) const;
// Implicit conversion to const PGresult: this is somewhat dangerous but
// allows us to avoid changing the existing code that uses PGresult and
// avoids the really bad problem with calling PQclear() twice accidentally
// as this would require a conversion to non-const pointer that we do not
// provide.
operator const PGresult*() const { return result_; }
// Get the associated result (which may be NULL). Unlike the implicit
// conversion above, this one returns a non-const pointer, so you should be
// careful to avoid really modifying it.
PGresult* get_result() const { return result_; }
// Dtor frees the result.
~postgresql_result() { free(); }
private:
void init(PGresult* result)
{
result_ = result;
}
void free()
{
// Notice that it is safe to call PQclear() with NULL pointer, it
// simply does nothing in this case.
PQclear(result_);
}
PGresult* result_;
// This class can't be copied as it owns result_ which can't be duplicated.
postgresql_result(postgresql_result const &);
postgresql_result& operator=(postgresql_result const &);
};
} // namespace details
struct postgresql_statement_backend;
struct postgresql_standard_into_type_backend : details::standard_into_type_backend
{
postgresql_standard_into_type_backend(postgresql_statement_backend & st)
: statement_(st) {}
virtual void define_by_pos(int & position,
void * data, details::exchange_type type);
virtual void pre_fetch();
virtual void post_fetch(bool gotData, bool calledFromFetch,
indicator * ind);
virtual void clean_up();
postgresql_statement_backend & statement_;
void * data_;
details::exchange_type type_;
int position_;
};
struct postgresql_vector_into_type_backend : details::vector_into_type_backend
{
postgresql_vector_into_type_backend(postgresql_statement_backend & st)
: statement_(st) {}
virtual void define_by_pos(int & position,
void * data, details::exchange_type type);
virtual void pre_fetch();
virtual void post_fetch(bool gotData, indicator * ind);
virtual void resize(std::size_t sz);
virtual std::size_t size();
virtual void clean_up();
postgresql_statement_backend & statement_;
void * data_;
details::exchange_type type_;
int position_;
};
struct postgresql_standard_use_type_backend : details::standard_use_type_backend
{
postgresql_standard_use_type_backend(postgresql_statement_backend & st)
: statement_(st), position_(0), buf_(NULL) {}
virtual void bind_by_pos(int & position,
void * data, details::exchange_type type, bool readOnly);
virtual void bind_by_name(std::string const & name,
void * data, details::exchange_type type, bool readOnly);
virtual void pre_use(indicator const * ind);
virtual void post_use(bool gotData, indicator * ind);
virtual void clean_up();
postgresql_statement_backend & statement_;
void * data_;
details::exchange_type type_;
int position_;
std::string name_;
char * buf_;
};
struct postgresql_vector_use_type_backend : details::vector_use_type_backend
{
postgresql_vector_use_type_backend(postgresql_statement_backend & st)
: statement_(st), position_(0) {}
virtual void bind_by_pos(int & position,
void * data, details::exchange_type type);
virtual void bind_by_name(std::string const & name,
void * data, details::exchange_type type);
virtual void pre_use(indicator const * ind);
virtual std::size_t size();
virtual void clean_up();
postgresql_statement_backend & statement_;
void * data_;
details::exchange_type type_;
int position_;
std::string name_;
std::vector<char *> buffers_;
};
struct postgresql_session_backend;
struct postgresql_statement_backend : details::statement_backend
{
postgresql_statement_backend(postgresql_session_backend & session);
~postgresql_statement_backend();
virtual void alloc();
virtual void clean_up();
virtual void prepare(std::string const & query,
details::statement_type stType);
virtual exec_fetch_result execute(int number);
virtual exec_fetch_result fetch(int number);
virtual long long get_affected_rows();
virtual int get_number_of_rows();
virtual std::string rewrite_for_procedure_call(std::string const & query);
virtual int prepare_for_describe();
virtual void describe_column(int colNum, data_type & dtype,
std::string & columnName);
virtual postgresql_standard_into_type_backend * make_into_type_backend();
virtual postgresql_standard_use_type_backend * make_use_type_backend();
virtual postgresql_vector_into_type_backend * make_vector_into_type_backend();
virtual postgresql_vector_use_type_backend * make_vector_use_type_backend();
postgresql_session_backend & session_;
details::postgresql_result result_;
std::string query_;
details::statement_type stType_;
std::string statementName_;
std::vector<std::string> names_; // list of names for named binds
long long rowsAffectedBulk_; // number of rows affected by the last bulk operation
int numberOfRows_; // number of rows retrieved from the server
int currentRow_; // "current" row number to consume in postFetch
int rowsToConsume_; // number of rows to be consumed in postFetch
bool justDescribed_; // to optimize row description with immediately
// following actual statement execution
bool hasIntoElements_;
bool hasVectorIntoElements_;
bool hasUseElements_;
bool hasVectorUseElements_;
// the following maps are used for finding data buffers according to
// use elements specified by the user
typedef std::map<int, char **> UseByPosBuffersMap;
UseByPosBuffersMap useByPosBuffers_;
typedef std::map<std::string, char **> UseByNameBuffersMap;
UseByNameBuffersMap useByNameBuffers_;
};
struct postgresql_rowid_backend : details::rowid_backend
{
postgresql_rowid_backend(postgresql_session_backend & session);
~postgresql_rowid_backend();
unsigned long value_;
};
struct postgresql_blob_backend : details::blob_backend
{
postgresql_blob_backend(postgresql_session_backend & session);
~postgresql_blob_backend();
virtual std::size_t get_len();
virtual std::size_t read(std::size_t offset, char * buf,
std::size_t toRead);
virtual std::size_t write(std::size_t offset, char const * buf,
std::size_t toWrite);
virtual std::size_t append(char const * buf, std::size_t toWrite);
virtual void trim(std::size_t newLen);
postgresql_session_backend & session_;
unsigned long oid_; // oid of the large object
int fd_; // descriptor of the large object
};
struct postgresql_session_backend : details::session_backend
{
postgresql_session_backend(connection_parameters const & parameters);
~postgresql_session_backend();
virtual void begin();
virtual void commit();
virtual void rollback();
void deallocate_prepared_statement(const std::string & statementName);
virtual bool get_next_sequence_value(session & s,
std::string const & sequence, long & value);
virtual std::string get_backend_name() const { return "postgresql"; }
void clean_up();
virtual postgresql_statement_backend * make_statement_backend();
virtual postgresql_rowid_backend * make_rowid_backend();
virtual postgresql_blob_backend * make_blob_backend();
std::string get_next_statement_name();
int statementCount_;
PGconn * conn_;
};
struct postgresql_backend_factory : backend_factory
{
postgresql_backend_factory() {}
virtual postgresql_session_backend * make_session(
connection_parameters const & parameters) const;
};
extern SOCI_POSTGRESQL_DECL postgresql_backend_factory const postgresql;
extern "C"
{
// for dynamic backend loading
SOCI_POSTGRESQL_DECL backend_factory const * factory_postgresql();
SOCI_POSTGRESQL_DECL void register_factory_postgresql();
} // extern "C"
} // namespace soci
#endif // SOCI_POSTGRESQL_H_INCLUDED
|