Commit 8511b57e authored by msobczak's avatar msobczak

Changed naming convention to lower_case in interfaces.

parent 9527a774
......@@ -23,93 +23,93 @@
#pragma warning(disable:4355)
#endif
using namespace SOCI;
using namespace SOCI::details;
using namespace soci;
using namespace soci::details;
PostgreSQLBLOBBackEnd::PostgreSQLBLOBBackEnd(
PostgreSQLSessionBackEnd &session)
postgresql_blob_backend::postgresql_blob_backend(
postgresql_session_backend &session)
: session_(session), fd_(-1)
{
// nothing to do here, the descriptor is open in the postFetch
// method of the Into element
}
PostgreSQLBLOBBackEnd::~PostgreSQLBLOBBackEnd()
postgresql_blob_backend::~postgresql_blob_backend()
{
lo_close(session_.conn_, fd_);
}
std::size_t PostgreSQLBLOBBackEnd::getLen()
std::size_t postgresql_blob_backend::get_len()
{
int pos = lo_lseek(session_.conn_, fd_, 0, SEEK_END);
if (pos == -1)
{
throw SOCIError("Cannot retrieve the size of BLOB.");
throw soci_error("Cannot retrieve the size of BLOB.");
}
return static_cast<std::size_t>(pos);
}
std::size_t PostgreSQLBLOBBackEnd::read(
std::size_t postgresql_blob_backend::read(
std::size_t offset, char *buf, std::size_t toRead)
{
int pos = lo_lseek(session_.conn_, fd_,
static_cast<int>(offset), SEEK_SET);
if (pos == -1)
{
throw SOCIError("Cannot seek in BLOB.");
throw soci_error("Cannot seek in BLOB.");
}
int readn = lo_read(session_.conn_, fd_, buf, toRead);
if (readn < 0)
{
throw SOCIError("Cannot read from BLOB.");
throw soci_error("Cannot read from BLOB.");
}
return static_cast<std::size_t>(readn);
}
std::size_t PostgreSQLBLOBBackEnd::write(
std::size_t postgresql_blob_backend::write(
std::size_t offset, char const *buf, std::size_t toWrite)
{
int pos = lo_lseek(session_.conn_, fd_,
static_cast<int>(offset), SEEK_SET);
if (pos == -1)
{
throw SOCIError("Cannot seek in BLOB.");
throw soci_error("Cannot seek in BLOB.");
}
int writen = lo_write(session_.conn_, fd_,
const_cast<char *>(buf), toWrite);
if (writen < 0)
{
throw SOCIError("Cannot write to BLOB.");
throw soci_error("Cannot write to BLOB.");
}
return static_cast<std::size_t>(writen);
}
std::size_t PostgreSQLBLOBBackEnd::append(
std::size_t postgresql_blob_backend::append(
char const *buf, std::size_t toWrite)
{
int pos = lo_lseek(session_.conn_, fd_, 0, SEEK_END);
if (pos == -1)
{
throw SOCIError("Cannot seek in BLOB.");
throw soci_error("Cannot seek in BLOB.");
}
int writen = lo_write(session_.conn_, fd_,
const_cast<char *>(buf), toWrite);
if (writen < 0)
{
throw SOCIError("Cannot append to BLOB.");
throw soci_error("Cannot append to BLOB.");
}
return static_cast<std::size_t>(writen);
}
void PostgreSQLBLOBBackEnd::trim(std::size_t /* newLen */)
void postgresql_blob_backend::trim(std::size_t /* newLen */)
{
throw SOCIError("Trimming BLOBs is not supported.");
throw soci_error("Trimming BLOBs is not supported.");
}
......@@ -25,14 +25,14 @@ long parse10(char const *&p1, char *&p2, char *msg)
}
else
{
throw SOCI::SOCIError(msg);
throw soci::soci_error(msg);
}
}
} // namespace anonymous
void SOCI::details::PostgreSQL::parseStdTm(char const *buf, std::tm &t)
void soci::details::postgresql::parse_std_tm(char const *buf, std::tm &t)
{
char const *p1 = buf;
char *p2;
......
......@@ -10,28 +10,28 @@
#include "soci-postgresql.h"
namespace SOCI {
namespace soci {
namespace details {
namespace PostgreSQL {
namespace postgresql {
// helper function for parsing datetime values
void parseStdTm(char const *buf, std::tm &t);
void parse_std_tm(char const *buf, std::tm &t);
// helper for vector operations
template <typename T>
std::size_t getVectorSize(void *p)
std::size_t get_vector_size(void *p)
{
std::vector<T> *v = static_cast<std::vector<T> *>(p);
return v->size();
}
} // namespace PostgreSQL
} // namespace postgresql
} // namespace details
} // namespace SOCI
} // namespace soci
#endif // POSTGRESQL_COMMON_H_INCLUDED
......@@ -23,15 +23,15 @@
#pragma warning(disable:4355)
#endif
using namespace SOCI;
using namespace SOCI::details;
using namespace soci;
using namespace soci::details;
// concrete factory for Empty concrete strategies
PostgreSQLSessionBackEnd * PostgreSQLBackEndFactory::makeSession(
postgresql_session_backend * postgresql_backend_factory::make_session(
std::string const &connectString) const
{
return new PostgreSQLSessionBackEnd(connectString);
return new postgresql_session_backend(connectString);
}
PostgreSQLBackEndFactory const SOCI::postgresql;
postgresql_backend_factory const soci::postgresql;
......@@ -23,17 +23,17 @@
#pragma warning(disable:4355)
#endif
using namespace SOCI;
using namespace SOCI::details;
using namespace soci;
using namespace soci::details;
PostgreSQLRowIDBackEnd::PostgreSQLRowIDBackEnd(
PostgreSQLSessionBackEnd & /* session */)
postgresql_rowid_backend::postgresql_rowid_backend(
postgresql_session_backend & /* session */)
{
// nothing to do here
}
PostgreSQLRowIDBackEnd::~PostgreSQLRowIDBackEnd()
postgresql_rowid_backend::~postgresql_rowid_backend()
{
// nothing to do here
}
......@@ -23,43 +23,43 @@
#pragma warning(disable:4355 4996)
#endif
using namespace SOCI;
using namespace SOCI::details;
using namespace soci;
using namespace soci::details;
PostgreSQLSessionBackEnd::PostgreSQLSessionBackEnd(
postgresql_session_backend::postgresql_session_backend(
std::string const & connectString)
: statementCount_(0)
{
conn_ = PQconnectdb(connectString.c_str());
if (conn_ == NULL || PQstatus(conn_) != CONNECTION_OK)
{
throw SOCIError("Cannot establish connection to the database.");
throw soci_error("Cannot establish connection to the database.");
}
}
PostgreSQLSessionBackEnd::~PostgreSQLSessionBackEnd()
postgresql_session_backend::~postgresql_session_backend()
{
cleanUp();
clean_up();
}
namespace // anonymous
{
// helper function for hardoded queries
void hardExec(PGconn *conn, char const *query, char const *errMsg)
void hard_exec(PGconn *conn, char const *query, char const *errMsg)
{
PGresult *result = PQexec(conn, query);
if (result == NULL)
{
throw SOCIError(errMsg);
throw soci_error(errMsg);
}
ExecStatusType status = PQresultStatus(result);
if (status != PGRES_COMMAND_OK)
{
throw SOCIError(PQresultErrorMessage(result));
throw soci_error(PQresultErrorMessage(result));
}
PQclear(result);
......@@ -67,22 +67,22 @@ void hardExec(PGconn *conn, char const *query, char const *errMsg)
} // namespace anonymous
void PostgreSQLSessionBackEnd::begin()
void postgresql_session_backend::begin()
{
hardExec(conn_, "BEGIN", "Cannot begin transaction.");
hard_exec(conn_, "BEGIN", "Cannot begin transaction.");
}
void PostgreSQLSessionBackEnd::commit()
void postgresql_session_backend::commit()
{
hardExec(conn_, "COMMIT", "Cannot commit transaction.");
hard_exec(conn_, "COMMIT", "Cannot commit transaction.");
}
void PostgreSQLSessionBackEnd::rollback()
void postgresql_session_backend::rollback()
{
hardExec(conn_, "ROLLBACK", "Cannot rollback transaction.");
hard_exec(conn_, "ROLLBACK", "Cannot rollback transaction.");
}
void PostgreSQLSessionBackEnd::cleanUp()
void postgresql_session_backend::clean_up()
{
if (conn_ != NULL)
{
......@@ -91,24 +91,24 @@ void PostgreSQLSessionBackEnd::cleanUp()
}
}
std::string PostgreSQLSessionBackEnd::getNextStatementName()
std::string postgresql_session_backend::get_next_statement_name()
{
char nameBuf[20]; // arbitrary length
sprintf(nameBuf, "st_%d", ++statementCount_);
return nameBuf;
}
PostgreSQLStatementBackEnd * PostgreSQLSessionBackEnd::makeStatementBackEnd()
postgresql_statement_backend * postgresql_session_backend::make_statement_backend()
{
return new PostgreSQLStatementBackEnd(*this);
return new postgresql_statement_backend(*this);
}
PostgreSQLRowIDBackEnd * PostgreSQLSessionBackEnd::makeRowIDBackEnd()
postgresql_rowid_backend * postgresql_session_backend::make_rowid_backend()
{
return new PostgreSQLRowIDBackEnd(*this);
return new postgresql_rowid_backend(*this);
}
PostgreSQLBLOBBackEnd * PostgreSQLSessionBackEnd::makeBLOBBackEnd()
postgresql_blob_backend * postgresql_session_backend::make_blob_backend()
{
return new PostgreSQLBLOBBackEnd(*this);
return new postgresql_blob_backend(*this);
}
......@@ -32,70 +32,70 @@
#endif
namespace SOCI
namespace soci
{
struct PostgreSQLStatementBackEnd;
struct PostgreSQLStandardIntoTypeBackEnd : details::StandardIntoTypeBackEnd
struct postgresql_statement_backend;
struct postgresql_standard_into_type_backend : details::standard_into_type_backend
{
PostgreSQLStandardIntoTypeBackEnd(PostgreSQLStatementBackEnd &st)
postgresql_standard_into_type_backend(postgresql_statement_backend &st)
: statement_(st) {}
virtual void defineByPos(int &position,
virtual void define_by_pos(int &position,
void *data, details::eExchangeType type);
virtual void preFetch();
virtual void postFetch(bool gotData, bool calledFromFetch,
virtual void pre_fetch();
virtual void post_fetch(bool gotData, bool calledFromFetch,
eIndicator *ind);
virtual void cleanUp();
virtual void clean_up();
PostgreSQLStatementBackEnd &statement_;
postgresql_statement_backend &statement_;
void *data_;
details::eExchangeType type_;
int position_;
};
struct PostgreSQLVectorIntoTypeBackEnd : details::VectorIntoTypeBackEnd
struct postgresql_vector_into_type_backend : details::vector_into_type_backend
{
PostgreSQLVectorIntoTypeBackEnd(PostgreSQLStatementBackEnd &st)
postgresql_vector_into_type_backend(postgresql_statement_backend &st)
: statement_(st) {}
virtual void defineByPos(int &position,
virtual void define_by_pos(int &position,
void *data, details::eExchangeType type);
virtual void preFetch();
virtual void postFetch(bool gotData, eIndicator *ind);
virtual void pre_fetch();
virtual void post_fetch(bool gotData, eIndicator *ind);
virtual void resize(std::size_t sz);
virtual std::size_t size();
virtual void cleanUp();
virtual void clean_up();
PostgreSQLStatementBackEnd &statement_;
postgresql_statement_backend &statement_;
void *data_;
details::eExchangeType type_;
int position_;
};
struct PostgreSQLStandardUseTypeBackEnd : details::StandardUseTypeBackEnd
struct postgresql_standard_use_type_backend : details::standard_use_type_backend
{
PostgreSQLStandardUseTypeBackEnd(PostgreSQLStatementBackEnd &st)
postgresql_standard_use_type_backend(postgresql_statement_backend &st)
: statement_(st), position_(0), buf_(NULL) {}
virtual void bindByPos(int &position,
virtual void bind_by_pos(int &position,
void *data, details::eExchangeType type);
virtual void bindByName(std::string const &name,
virtual void bind_by_name(std::string const &name,
void *data, details::eExchangeType type);
virtual void preUse(eIndicator const *ind);
virtual void postUse(bool gotData, eIndicator *ind);
virtual void pre_use(eIndicator const *ind);
virtual void post_use(bool gotData, eIndicator *ind);
virtual void cleanUp();
virtual void clean_up();
PostgreSQLStatementBackEnd &statement_;
postgresql_statement_backend &statement_;
void *data_;
details::eExchangeType type_;
......@@ -104,23 +104,23 @@ struct PostgreSQLStandardUseTypeBackEnd : details::StandardUseTypeBackEnd
char *buf_;
};
struct PostgreSQLVectorUseTypeBackEnd : details::VectorUseTypeBackEnd
struct postgresql_vector_use_type_backend : details::vector_use_type_backend
{
PostgreSQLVectorUseTypeBackEnd(PostgreSQLStatementBackEnd &st)
postgresql_vector_use_type_backend(postgresql_statement_backend &st)
: statement_(st), position_(0) {}
virtual void bindByPos(int &position,
virtual void bind_by_pos(int &position,
void *data, details::eExchangeType type);
virtual void bindByName(std::string const &name,
virtual void bind_by_name(std::string const &name,
void *data, details::eExchangeType type);
virtual void preUse(eIndicator const *ind);
virtual void pre_use(eIndicator const *ind);
virtual std::size_t size();
virtual void cleanUp();
virtual void clean_up();
PostgreSQLStatementBackEnd &statement_;
postgresql_statement_backend &statement_;
void *data_;
details::eExchangeType type_;
......@@ -129,33 +129,33 @@ struct PostgreSQLVectorUseTypeBackEnd : details::VectorUseTypeBackEnd
std::vector<char *> buffers_;
};
struct PostgreSQLSessionBackEnd;
struct PostgreSQLStatementBackEnd : details::StatementBackEnd
struct postgresql_session_backend;
struct postgresql_statement_backend : details::statement_backend
{
PostgreSQLStatementBackEnd(PostgreSQLSessionBackEnd &session);
postgresql_statement_backend(postgresql_session_backend &session);
virtual void alloc();
virtual void cleanUp();
virtual void clean_up();
virtual void prepare(std::string const &query,
details::eStatementType eType);
virtual execFetchResult execute(int number);
virtual execFetchResult fetch(int number);
virtual int getNumberOfRows();
virtual int get_number_of_rows();
virtual std::string rewriteForProcedureCall(std::string const &query);
virtual std::string rewrite_for_procedure_call(std::string const &query);
virtual int prepareForDescribe();
virtual void describeColumn(int colNum, eDataType &dtype,
virtual int prepare_for_describe();
virtual void describe_column(int colNum, eDataType &dtype,
std::string &columnName);
virtual PostgreSQLStandardIntoTypeBackEnd * makeIntoTypeBackEnd();
virtual PostgreSQLStandardUseTypeBackEnd * makeUseTypeBackEnd();
virtual PostgreSQLVectorIntoTypeBackEnd * makeVectorIntoTypeBackEnd();
virtual PostgreSQLVectorUseTypeBackEnd * makeVectorUseTypeBackEnd();
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();
PostgreSQLSessionBackEnd &session_;
postgresql_session_backend &session_;
PGresult *result_;
std::string query_;
......@@ -185,22 +185,22 @@ struct PostgreSQLStatementBackEnd : details::StatementBackEnd
UseByNameBuffersMap useByNameBuffers_;
};
struct PostgreSQLRowIDBackEnd : details::RowIDBackEnd
struct postgresql_rowid_backend : details::rowid_backend
{
PostgreSQLRowIDBackEnd(PostgreSQLSessionBackEnd &session);
postgresql_rowid_backend(postgresql_session_backend &session);
~PostgreSQLRowIDBackEnd();
~postgresql_rowid_backend();
unsigned long value_;
};
struct PostgreSQLBLOBBackEnd : details::BLOBBackEnd
struct postgresql_blob_backend : details::blob_backend
{
PostgreSQLBLOBBackEnd(PostgreSQLSessionBackEnd &session);
postgresql_blob_backend(postgresql_session_backend &session);
~PostgreSQLBLOBBackEnd();
~postgresql_blob_backend();
virtual std::size_t getLen();
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,
......@@ -208,44 +208,43 @@ struct PostgreSQLBLOBBackEnd : details::BLOBBackEnd
virtual std::size_t append(char const *buf, std::size_t toWrite);
virtual void trim(std::size_t newLen);
PostgreSQLSessionBackEnd &session_;
postgresql_session_backend &session_;
unsigned long oid_; // oid of the large object
int fd_; // descriptor of the large object
};
struct PostgreSQLSessionBackEnd : details::SessionBackEnd
struct postgresql_session_backend : details::session_backend
{
PostgreSQLSessionBackEnd(std::string const &connectString);
postgresql_session_backend(std::string const &connectString);
~PostgreSQLSessionBackEnd();
~postgresql_session_backend();
virtual void begin();
virtual void commit();
virtual void rollback();
void cleanUp();
void clean_up();
virtual PostgreSQLStatementBackEnd * makeStatementBackEnd();
virtual PostgreSQLRowIDBackEnd * makeRowIDBackEnd();
virtual PostgreSQLBLOBBackEnd * makeBLOBBackEnd();
virtual postgresql_statement_backend * make_statement_backend();
virtual postgresql_rowid_backend * make_rowid_backend();
virtual postgresql_blob_backend * make_blob_backend();
std::string getNextStatementName();
std::string get_next_statement_name();
int statementCount_;
PGconn *conn_;
};
struct PostgreSQLBackEndFactory : BackEndFactory
struct postgresql_backend_factory : backend_factory
{
virtual PostgreSQLSessionBackEnd * makeSession(
virtual postgresql_session_backend * make_session(
std::string const &connectString) const;
};
SOCI_POSTGRESQL_DECL extern PostgreSQLBackEndFactory const postgresql;
SOCI_POSTGRESQL_DECL extern postgresql_backend_factory const postgresql;
} // namespace SOCI
} // namespace soci
#endif // SOCI_POSTGRESQL_H_INCLUDED
......@@ -25,12 +25,12 @@
#define strtoll(s, p, b) static_cast<long long>(_strtoi64(s, p, b))
#endif
using namespace SOCI;
using namespace SOCI::details;
using namespace SOCI::details::PostgreSQL;
using namespace soci;
using namespace soci::details;
using namespace soci::details::postgresql;
void PostgreSQLStandardIntoTypeBackEnd::defineByPos(
void postgresql_standard_into_type_backend::define_by_pos(
int &position, void *data, eExchangeType type)
{
data_ = data;
......@@ -38,12 +38,12 @@ void PostgreSQLStandardIntoTypeBackEnd::defineByPos(
position_ = position++;
}
void PostgreSQLStandardIntoTypeBackEnd::preFetch()
void postgresql_standard_into_type_backend::pre_fetch()
{
// nothing to do here
}
void PostgreSQLStandardIntoTypeBackEnd::postFetch(
void postgresql_standard_into_type_backend::post_fetch(
bool gotData, bool calledFromFetch, eIndicator *ind)
{
if (calledFromFetch == true && gotData == false)
......@@ -55,7 +55,7 @@ void PostgreSQLStandardIntoTypeBackEnd::postFetch(
if (gotData)
{
// PostgreSQL positions start at 0
// postgresql_ positions start at 0
int pos = position_ - 1;
// first, deal with indicators
......@@ -63,7 +63,7 @@ void PostgreSQLStandardIntoTypeBackEnd::postFetch(
{
if (ind == NULL)
{
throw SOCIError(
throw soci_error(
"Null value fetched and no indicator defined.");
}
......@@ -92,8 +92,8 @@ void PostgreSQLStandardIntoTypeBackEnd::postFetch(
break;
case eXCString:
{
CStringDescriptor *strDescr
= static_cast<CStringDescriptor *>(data_);
cstring_descriptor *strDescr
= static_cast<cstring_descriptor *>(data_);
std::strncpy(strDescr->str_, buf, strDescr->bufSize_ - 1);
strDescr->str_[strDescr->bufSize_ - 1] = '\0';
......@@ -142,17 +142,17 @@ void PostgreSQLStandardIntoTypeBackEnd::postFetch(
{
// attempt to parse the string and convert to std::tm
std::tm *dest = static_cast<std::tm *>(data_);
parseStdTm(buf, *dest);
parse_std_tm(buf, *dest);
}
break;
case eXRowID:
{
// RowID is internally identical to unsigned long
RowID *rid = static_cast<RowID *>(data_);
PostgreSQLRowIDBackEnd *rbe
= static_cast<PostgreSQLRowIDBackEnd *>(
rid->getBackEnd());
rowid *rid = static_cast<rowid *>(data_);
postgresql_rowid_backend *rbe
= static_cast<postgresql_rowid_backend *>(
rid->get_backend());
long long val = strtoll(buf, NULL, 10);
rbe->value_ = static_cast<unsigned long>(val);
......@@ -167,12 +167,12 @@ void PostgreSQLStandardIntoTypeBackEnd::postFetch(
INV_READ | INV_WRITE);
if (fd == -1)
{
throw SOCIError("Cannot open the BLOB object.");
throw soci_error("Cannot open the blob object.");
}
BLOB *b = static_cast<BLOB *>(data_);
PostgreSQLBLOBBackEnd *bbe
= static_cast<PostgreSQLBLOBBackEnd *>(b->getBackEnd());
blob *b = static_cast<blob *>(data_);
postgresql_blob_backend *bbe
= static_cast<postgresql_blob_backend *>(b->get_backend());
if (bbe->fd_ != -1)
{
......@@ -184,7 +184,7 @@ void PostgreSQLStandardIntoTypeBackEnd::postFetch(
break;
default:
throw SOCIError("Into element used with non-supported type.");
throw soci_error("Into element used with non-supported type.");
}
}
else // no data retrieved
......@@ -195,12 +195,12 @@ void PostgreSQLStandardIntoTypeBackEnd::postFetch(
}
else
{
throw SOCIError("No data fetched and no indicator defined.");
throw soci_error("No data fetched and no indicator defined.");
}
}
}
void PostgreSQLStandardIntoTypeBackEnd::cleanUp()
void postgresql_standard_into_type_backend::clean_up()
{
// nothing to do here
}
......@@ -27,11 +27,11 @@
using std::snprintf;
#endif
using namespace SOCI;
using namespace SOCI::details;
using namespace soci;
using namespace soci::details;
void PostgreSQLStandardUseTypeBackEnd::bindByPos(
void postgresql_standard_use_type_backend::bind_by_pos(
int &position, void *data, eExchangeType type)
{