8 #define SOCI_POSTGRESQL_SOURCE 11 #include <libpq/libpq-fs.h> 20 #ifdef SOCI_POSTGRESQL_NOPARAMS 21 #ifndef SOCI_POSTGRESQL_NOBINDBYNAME 22 #define SOCI_POSTGRESQL_NOBINDBYNAME 23 #endif // SOCI_POSTGRESQL_NOBINDBYNAME 24 #endif // SOCI_POSTGRESQL_NOPARAMS 27 #pragma warning(disable:4355) 36 , rowsAffectedBulk_(-1LL), justDescribed_(false)
37 , hasIntoElements_(false), hasVectorIntoElements_(false)
38 , hasUseElements_(false), hasVectorUseElements_(false)
77 #ifdef SOCI_POSTGRESQL_NOBINDBYNAME 83 enum { normal, in_quotes, in_name } state = normal;
88 for (std::string::const_iterator it = query.begin(), end = query.end();
103 const std::string::const_iterator next_it = it + 1;
104 if ((next_it != end) && (*next_it ==
':'))
111 else if ((next_it != end) && (*next_it ==
'='))
138 if (std::isalnum(*it) || *it ==
'_')
146 std::ostringstream ss;
147 ss <<
'$' << position++;
158 const std::string::const_iterator next_it = it + 1;
159 if ((next_it != end) && (*next_it ==
':'))
170 if (state == in_name)
173 std::ostringstream ss;
174 ss <<
'$' << position++;
178 #endif // SOCI_POSTGRESQL_NOBINDBYNAME 180 #ifndef SOCI_POSTGRESQL_NOPREPARE 192 query_.c_str(),
static_cast<int>(
names_.size()), NULL));
201 #endif // SOCI_POSTGRESQL_NOPREPARE 221 "Bulk use with single into elements is not supported.");
233 int numberOfExecutions = 1;
246 "Binding for use elements must be either by position " 249 long long rowsAffectedBulkTemp = 0;
250 for (
int i = 0; i != numberOfExecutions; ++i)
252 std::vector<char *> paramValues;
260 for (UseByPosBuffersMap::iterator
265 char ** buffers = it->second;
266 paramValues.push_back(buffers[i]);
273 for (std::vector<std::string>::iterator
277 UseByNameBuffersMap::iterator b
282 "Missing use element for bind by name (");
287 char ** buffers = b->second;
288 paramValues.push_back(buffers[i]);
292 #ifdef SOCI_POSTGRESQL_NOPARAMS 294 throw soci_error(
"Queries with parameters are not supported.");
298 #ifdef SOCI_POSTGRESQL_NOPREPARE 301 static_cast<int>(paramValues.size()),
302 NULL, ¶mValues[0], NULL, NULL, 0));
310 static_cast<int>(paramValues.size()),
311 ¶mValues[0], NULL, NULL, 0));
319 static_cast<int>(paramValues.size()),
320 NULL, ¶mValues[0], NULL, NULL, 0));
323 #endif // SOCI_POSTGRESQL_NOPREPARE 325 #endif // SOCI_POSTGRESQL_NOPARAMS 327 if (numberOfExecutions > 1)
341 if (numberOfExecutions > 1)
355 #ifdef SOCI_POSTGRESQL_NOPREPARE 371 #endif // SOCI_POSTGRESQL_NOPREPARE 399 return fetch(number);
456 long long result = std::strtoll(resultStr, &end, 0);
457 if (end != resultStr)
477 std::string
const & query)
479 std::string newQuery(
"select ");
489 int columns = PQnfields(
result_);
494 std::string & columnName)
497 int const pos = colNum - 1;
499 unsigned long const typeOid = PQftype(
result_, pos);
548 int form = PQfformat(
result_, pos);
549 int size = PQfsize(
result_, pos);
550 if (form == 0 && size == -1)
556 std::stringstream message;
557 message <<
"unknown data type with typelem: " << typeOid <<
" for colNum: " << colNum <<
" with name: " << PQfname(
result_, pos);
563 columnName = PQfname(
result_, pos);
details::statement_type stType_
bool check_for_data(char const *errMsg) const
PGresult * get_result() const
virtual int prepare_for_describe()
bool hasVectorIntoElements_
long long rowsAffectedBulk_
void deallocate_prepared_statement(const std::string &statementName)
virtual void prepare(std::string const &query, details::statement_type stType)
virtual postgresql_vector_into_type_backend * make_vector_into_type_backend()
bool hasVectorUseElements_
details::postgresql_result result_
virtual postgresql_standard_into_type_backend * make_into_type_backend()
~postgresql_statement_backend()
virtual postgresql_standard_use_type_backend * make_use_type_backend()
virtual exec_fetch_result fetch(int number)
postgresql_statement_backend(postgresql_session_backend &session)
virtual postgresql_vector_use_type_backend * make_vector_use_type_backend()
std::vector< std::string > names_
virtual int get_number_of_rows()
postgresql_session_backend & session_
std::string statementName_
virtual void describe_column(int colNum, data_type &dtype, std::string &columnName)
void reset(PGresult *result=NULL)
void check_for_errors(char const *errMsg) const
virtual long long get_affected_rows()
UseByPosBuffersMap useByPosBuffers_
UseByNameBuffersMap useByNameBuffers_
virtual std::string rewrite_for_procedure_call(std::string const &query)
virtual exec_fetch_result execute(int number)
std::string get_next_statement_name()