code cleanup

This commit is contained in:
Günter Obiltschnig 2020-01-25 20:43:13 +01:00
parent 65be8b0bb6
commit 14e58b7fea
20 changed files with 209 additions and 304 deletions

View File

@ -17,17 +17,17 @@
#ifndef SQL_PostgreSQL_Binder_INCLUDED
#define SQL_PostgreSQL_Binder_INCLUDED
#include "Poco/Data/PostgreSQL/PostgreSQL.h"
#include "Poco/Data/PostgreSQL/PostgreSQLTypes.h"
#include "Poco/Data/PostgreSQL/PostgreSQLException.h"
#include "Poco/Data/AbstractBinder.h"
#include "Poco/Data/MetaColumn.h"
#include "Poco/Data/LOB.h"
#include "Poco/Types.h"
#include <libpq-fe.h>
namespace Poco {
namespace Data {
namespace PostgreSQL {
@ -38,11 +38,11 @@ class PostgreSQL_API Binder: public Poco::Data::AbstractBinder
/// Allows data type mapping at statement execution time.
{
public:
typedef SharedPtr<Binder> Ptr;
using Ptr = SharedPtr<Binder>;
Binder();
/// Creates the Binder.
virtual ~Binder();
/// Destroys the Binder.
@ -244,12 +244,11 @@ private:
/// due to security risk.
{
}
void realBind(std::size_t aPosition, Poco::Data::MetaColumn::ColumnDataType aFieldType, const void* aBufferPtr, std::size_t aLength);
/// Common bind implementation
private:
InputParameterVector _bindVector;
};

View File

@ -13,33 +13,28 @@
// SPDX-License-Identifier: BSL-1.0
//
#ifndef SQL_PostgreSQL_Connector_INCLUDED
#define SQL_PostgreSQL_Connector_INCLUDED
#include "Poco/Data/PostgreSQL/PostgreSQL.h"
#include "Poco/Data/SessionImpl.h"
#include "Poco/Data/Connector.h"
#include "Poco/AutoPtr.h"
#include <string>
// Note: to avoid static (de)initialization problems,
// during connector automatic (un)registration, it is
// best to have this as a macro.
#define POCO_DATA_POSTGRESQL_CONNECTOR_NAME "postgresql"
namespace Poco {
namespace Data {
namespace PostgreSQL {
class PostgreSQL_API Connector: public Poco::Data::Connector
/// Connector instantiates PostgreSQL SessionImpl objects.
{
public:
static std::string KEY;
static const std::string KEY;
Connector();
/// Creates the Connector.
@ -65,55 +60,4 @@ public:
} } } // namespace Poco::Data::PostgreSQL
//
// Automatic Connector registration
//
struct PostgreSQL_API PostgreSQLConnectorRegistrator
/// Connector registering class.
/// A global instance of this class is instantiated
/// with sole purpose to automatically register the
/// PostgreSQL connector with central Poco Data registry.
{
PostgreSQLConnectorRegistrator()
/// Calls Poco::Data::PostgreSQL::registerConnector();
{
Poco::Data::PostgreSQL::Connector::registerConnector();
}
~PostgreSQLConnectorRegistrator()
/// Calls Poco::Data::PostgreSQL::unregisterConnector();
{
Poco::Data::PostgreSQL::Connector::unregisterConnector();
}
};
#if !defined(POCO_NO_AUTOMATIC_LIB_INIT)
#if defined(POCO_OS_FAMILY_WINDOWS)
extern "C" const struct PostgreSQL_API PostgreSQLConnectorRegistrator pocoPostgreSQLConnectorRegistrator;
#if defined(PostgreSQL_EXPORTS)
#if defined(_WIN64)
#define POCO_DATA_POSTGRESQL_FORCE_SYMBOL(s) __pragma(comment (linker, "/export:"#s))
#elif defined(_WIN32)
#define POCO_DATA_POSTGRESQL_FORCE_SYMBOL(s) __pragma(comment (linker, "/export:_"#s))
#endif
#else // !PostgreSQL_EXPORTS
#if defined(_WIN64)
#define POCO_DATA_POSTGRESQL_FORCE_SYMBOL(s) __pragma(comment (linker, "/include:"#s))
#elif defined(_WIN32)
#define POCO_DATA_POSTGRESQL_FORCE_SYMBOL(s) __pragma(comment (linker, "/include:_"#s))
#endif
#endif // PostgreSQL_EXPORTS
#else // !POCO_OS_FAMILY_WINDOWS
#define POCO_DATA_POSTGRESQL_FORCE_SYMBOL(s) extern "C" const struct PostgreSQLConnectorRegistrator s;
#endif // POCO_OS_FAMILY_WINDOWS
POCO_DATA_POSTGRESQL_FORCE_SYMBOL(pocoPostgreSQLConnectorRegistrator)
#endif // POCO_NO_AUTOMATIC_LIB_INIT
//
// End automatic Connector registration
//
#endif // Data_PostgreSQL_Connector_INCLUDED

View File

@ -21,10 +21,8 @@
#include "Poco/Data/PostgreSQL/PostgreSQL.h"
#include "Poco/Data/PostgreSQL/PostgreSQLTypes.h"
#include "Poco/Data/PostgreSQL/StatementExecutor.h"
#include "Poco/Data/AbstractExtractor.h"
#include "Poco/Data/LOB.h"
#include "Poco/Types.h"
#include "Poco/Any.h"
#include "Poco/DynamicAny.h"
@ -32,11 +30,6 @@
namespace Poco {
//namespace Dynamic {
// class Var;
//}
namespace Data {
namespace PostgreSQL {
@ -46,7 +39,7 @@ class PostgreSQL_API Extractor: public Poco::Data::AbstractExtractor
/// If NULL is received, the incoming val value is not changed and false is returned
{
public:
typedef SharedPtr<Extractor> Ptr;
using Ptr = SharedPtr<Extractor>;
Extractor(StatementExecutor& st);
/// Creates the Extractor.
@ -56,28 +49,28 @@ public:
virtual bool extract(std::size_t pos, Poco::Int8& val);
/// Extracts an Int8.
virtual bool extract(std::size_t pos, Poco::UInt8& val);
/// Extracts an UInt8.
virtual bool extract(std::size_t pos, Poco::Int16& val);
/// Extracts an Int16.
virtual bool extract(std::size_t pos, Poco::UInt16& val);
/// Extracts an UInt16.
virtual bool extract(std::size_t pos, Poco::Int32& val);
/// Extracts an Int32.
virtual bool extract(std::size_t pos, Poco::UInt32& val);
/// Extracts an UInt32.
virtual bool extract(std::size_t pos, Poco::Int64& val);
/// Extracts an Int64.
virtual bool extract(std::size_t pos, Poco::UInt64& val);
/// Extracts an UInt64.
#ifndef POCO_INT64_IS_LONG
virtual bool extract(std::size_t pos, long& val);
/// Extracts a long. Returns false if null was received.
@ -88,10 +81,10 @@ public:
virtual bool extract(std::size_t pos, bool& val);
/// Extracts a boolean.
virtual bool extract(std::size_t pos, float& val);
/// Extracts a float.
virtual bool extract(std::size_t pos, double& val);
/// Extracts a double.
@ -131,7 +124,7 @@ public:
////////////
// Not implemented extract functions
////////////
virtual bool extract(std::size_t pos, std::vector<Poco::Int8>& val);
/// Extracts an Int8 vector.
@ -324,14 +317,12 @@ public:
/// Extracts a Dynamic::Var list.
private:
const OutputParameter& extractPreamble(std::size_t aPosition) const;
bool isColumnNull(const OutputParameter& anOutputParameter) const;
template <typename T>
bool extractStringImpl(std::size_t pos, T& val)
/// Utility function for extraction of Any and DynamicAny.
/// Utility function for extraction of Any and DynamicAny.
{
OutputParameter outputParameter = extractPreamble(pos);
@ -357,7 +348,6 @@ private:
Extractor& operator=(const Extractor&);
private:
StatementExecutor& _statementExecutor;
};

View File

@ -17,25 +17,23 @@
#ifndef SQL_PostgreSQL_PostgreSQLException_INCLUDED
#define SQL_PostgreSQL_PostgreSQLException_INCLUDED
#include "Poco/Data/PostgreSQL/PostgreSQL.h"
#include "Poco/Data/DataException.h"
#include <typeinfo>
#include <string>
namespace Poco {
namespace Data {
namespace PostgreSQL {
// End-user include this file and use in code ConnectionException/StatementException
// So it need not know
class PostgreSQL_API PostgreSQLException: public Poco::Data::DataException
/// Base class for all PostgreSQL exceptions
{
public:
PostgreSQLException(const std::string& aMessage);
explicit PostgreSQLException(const std::string& aMessage);
/// Creates PostgreSQLException.
PostgreSQLException(const PostgreSQLException& exc);
@ -44,7 +42,7 @@ public:
~PostgreSQLException() noexcept;
/// Destroys PostgreSQLexception.
PostgreSQLException& operator=(const PostgreSQLException& exc);
PostgreSQLException& operator = (const PostgreSQLException& exc);
/// Assignment operator.
const char* name() const noexcept;
@ -68,32 +66,28 @@ public:
};
class ConnectionException : public PostgreSQLException
class ConnectionException: public PostgreSQLException
/// ConnectionException
{
public:
ConnectionException(const std::string& aMessage);
/// Creates ConnectionException from string.
};
class TransactionException : public ConnectionException
class TransactionException: public ConnectionException
/// TrabsactionException
{
public:
TransactionException(const std::string& aMessage);
/// Creates TransactionException from string.
};
class StatementException : public PostgreSQLException
class StatementException: public PostgreSQLException
/// StatementException
{
public:
StatementException(const std::string& aMessage);
/// Creates StatementException from string.
};
@ -103,9 +97,10 @@ public:
// inlines
//
inline PostgreSQLException& PostgreSQLException::operator=(const PostgreSQLException& exc)
inline PostgreSQLException& PostgreSQLException::operator = (const PostgreSQLException& exc)
{
Poco::Data::DataException::operator=(exc);
Poco::Data::DataException::operator = (exc);
return *this;
}
@ -136,4 +131,5 @@ inline void PostgreSQLException::rethrow() const
} } } // namespace Poco::Data::PostgreSQL
#endif //SQL_PostgreSQL_PostgreSQLException_INCLUDED

View File

@ -17,6 +17,7 @@
#ifndef SQL_PostgreSQL_PostgreSQLStatementImpl_INCLUDED
#define SQL_PostgreSQL_PostgreSQLStatementImpl_INCLUDED
#include "Poco/Data/PostgreSQL/PostgreSQL.h"
#include "Poco/Data/PostgreSQL/SessionImpl.h"
#include "Poco/Data/PostgreSQL/Binder.h"
@ -43,7 +44,6 @@ public:
/// Destroys the PostgreSQLStatementImpl.
protected:
virtual std::size_t columnsReturned() const;
/// Returns number of columns returned by query.

View File

@ -13,22 +13,25 @@
// SPDX-License-Identifier: BSL-1.0
//
#ifndef SQL_PostgreSQL_Types_INCLUDED
#define SQL_PostgreSQL_Types_INCLUDED
#include "Poco/Data/MetaColumn.h"
#include <vector>
#include <libpq-fe.h>
namespace Poco {
namespace Data {
namespace PostgreSQL {
/// Oid constants duplicated from PostgreSQL "include/postgresql/server/catalog/pg_type.h"
/// because PostgreSQL compile time definitions are too onerous to reproduce for this module
const Oid BOOLOID = 16;
const Oid INT2OID = 21;
@ -59,23 +62,25 @@ const Oid CASHOID = 790;
const Oid MACADDROID = 829;
const Oid UUIDOID = 2950;
Poco::Data::MetaColumn::ColumnDataType oidToColumnDataType(const Oid anOID);
class InputParameter
/// PostgreSQL class to record values for input parameters to SQL statements
{
public:
typedef Poco::Data::MetaColumn::ColumnDataType CDT;
using CDT = Poco::Data::MetaColumn::ColumnDataType;
explicit InputParameter(CDT fieldType, const void* dataPtr, std::size_t dataLength);
explicit InputParameter();
InputParameter(CDT fieldType, const void* dataPtr, std::size_t dataLength);
InputParameter();
~InputParameter();
CDT fieldType() const;
CDT fieldType() const;
const void* pData() const;
std::size_t size() const;
bool isBinary() const;
bool isBinary() const;
void setStringVersionRepresentation(const std::string& aString);
void setNonStringVersionRepresentation(const void* aPtr, std::size_t theSize);
@ -91,14 +96,15 @@ private:
void* _pNonStringVersionRepresentation;
};
typedef std::vector <InputParameter> InputParameterVector;
using InputParameterVector = std::vector <InputParameter>;
class OutputParameter
/// PostgreSQL class to record values for output parameters to capture the results
{
public:
typedef Poco::Data::MetaColumn::ColumnDataType CDT;
using CDT = Poco::Data::MetaColumn::ColumnDataType;
OutputParameter(CDT aFieldType, Oid internalFieldType, std::size_t rowNumber,
const char* dataPtr, std::size_t size, bool isNull);
@ -109,16 +115,14 @@ public:
void setValues(CDT fieldType, Oid internalFieldType, std::size_t rowNumber,
const char* dataPtr, std::size_t size, bool isNull);
CDT fieldType() const;
Oid internalFieldType() const;
CDT fieldType() const;
Oid internalFieldType() const;
std::size_t rowNumber() const;
const char* pData() const;
std::size_t size() const;
bool isNull() const;
bool isNull() const;
private:
CDT _fieldType;
Oid _internalFieldType;
std::size_t _rowNumber;
@ -127,7 +131,8 @@ private:
bool _isNull;
};
typedef std::vector <OutputParameter> OutputParameterVector;
using OutputParameterVector = std::vector <OutputParameter>;
class PQConnectionInfoOptionsFree
@ -138,23 +143,24 @@ public:
~PQConnectionInfoOptionsFree();
private:
PQConnectionInfoOptionsFree (const PQConnectionInfoOptionsFree&);
PQConnectionInfoOptionsFree& operator= (const PQConnectionInfoOptionsFree&);
PQConnectionInfoOptionsFree(const PQConnectionInfoOptionsFree&);
PQConnectionInfoOptionsFree& operator = (const PQConnectionInfoOptionsFree&);
private:
PQconninfoOption* _pConnectionInfoOption;
};
class PQResultClear
/// PostgreSQL statement result free (RAII)
{
public:
explicit PQResultClear(PGresult * aPQResultPtr);
explicit PQResultClear(PGresult* aPQResultPtr);
~PQResultClear();
private:
PQResultClear (const PQResultClear&);
PQResultClear& operator= (const PQResultClear&);
PQResultClear(const PQResultClear&);
PQResultClear& operator = (const PQResultClear&);
private:
PGresult* _pPQResult;
@ -165,12 +171,12 @@ class PGCancelFree
/// PostgreSQL Cancel Info Options free (RAII)
{
public:
explicit PGCancelFree(PGcancel * aStatementCancelPtr);
explicit PGCancelFree(PGcancel* aStatementCancelPtr);
~PGCancelFree();
private:
PGCancelFree (const PGCancelFree&);
PGCancelFree& operator= (const PGCancelFree&);
PGCancelFree(const PGCancelFree&);
PGCancelFree& operator = (const PGCancelFree&);
private:
PGcancel* _pPGCancel;
@ -181,20 +187,14 @@ private:
// inlines
//
// InputParameter
inline InputParameter::InputParameter(Poco::Data::MetaColumn::ColumnDataType aFieldType,
const void* aDataPtr, std::size_t theSize): _fieldType(aFieldType),
inline InputParameter::InputParameter(Poco::Data::MetaColumn::ColumnDataType fieldType,
const void* aDataPtr, std::size_t theSize):
_fieldType(fieldType),
_pData(aDataPtr),
_size(theSize),
_isBinary(false),
_isBinary(Poco::Data::MetaColumn::FDT_BLOB == _fieldType || Poco::Data::MetaColumn::FDT_CLOB == _fieldType),
_pNonStringVersionRepresentation(0)
{
if (Poco::Data::MetaColumn::FDT_BLOB == _fieldType
|| Poco::Data::MetaColumn::FDT_CLOB == _fieldType)
{
_isBinary = true;
}
}
@ -283,30 +283,29 @@ inline const void* InputParameter::pInternalRepresentation() const
}
// OutputParameter
inline OutputParameter::OutputParameter(Poco::Data::MetaColumn::ColumnDataType aFieldType,
Oid anInternalFieldType,
std::size_t aRowNumber,
const char* aDataPtr,
std::size_t theSize,
bool anIsNull): _fieldType(aFieldType),
_internalFieldType(anInternalFieldType),
_rowNumber(aRowNumber),
_pData(aDataPtr),
_size(theSize),
_isNull(anIsNull)
bool anIsNull):
_fieldType(aFieldType),
_internalFieldType(anInternalFieldType),
_rowNumber(aRowNumber),
_pData(aDataPtr),
_size(theSize),
_isNull(anIsNull)
{
}
inline OutputParameter::OutputParameter()
: _fieldType (Poco::Data::MetaColumn::FDT_UNKNOWN),
_internalFieldType (static_cast<Oid>(-1)),
_rowNumber (0),
_pData (0),
_size (0),
_isNull (true)
inline OutputParameter::OutputParameter():
_fieldType(Poco::Data::MetaColumn::FDT_UNKNOWN),
_internalFieldType(static_cast<Oid>(-1)),
_rowNumber(0),
_pData(0),
_size(0),
_isNull(true)
{
}
@ -368,10 +367,8 @@ inline bool OutputParameter::isNull() const
}
// PQConnectionInfoOptionsFree
inline PQConnectionInfoOptionsFree::PQConnectionInfoOptionsFree(PQconninfoOption* aConnectionInfoOptionPtr)
: _pConnectionInfoOption(aConnectionInfoOptionPtr)
inline PQConnectionInfoOptionsFree::PQConnectionInfoOptionsFree(PQconninfoOption* aConnectionInfoOptionPtr):
_pConnectionInfoOption(aConnectionInfoOptionPtr)
{
}
@ -386,10 +383,8 @@ inline PQConnectionInfoOptionsFree::~PQConnectionInfoOptionsFree()
}
// PQResultClear
inline PQResultClear::PQResultClear(PGresult* aPQResultPtr)
: _pPQResult(aPQResultPtr)
inline PQResultClear::PQResultClear(PGresult* aPQResultPtr):
_pPQResult(aPQResultPtr)
{
}
@ -406,8 +401,8 @@ inline PQResultClear::~PQResultClear()
// PGCancelFree
inline PGCancelFree::PGCancelFree(PGcancel* aStatementCancelPtr)
: _pPGCancel(aStatementCancelPtr)
inline PGCancelFree::PGCancelFree(PGcancel* aStatementCancelPtr):
_pPGCancel(aStatementCancelPtr)
{
}
@ -422,6 +417,7 @@ inline PGCancelFree::~PGCancelFree()
}
}}}
} } } // namespace Poco::Data::PostgreSQL
#endif // SQL_PostgreSQL_Types_INCLUDED

View File

@ -13,27 +13,30 @@
// SPDX-License-Identifier: BSL-1.0
//
#ifndef SQL_PostgreSQL_SessionHandle_INCLUDED
#define SQL_PostgreSQL_SessionHandle_INCLUDED
#include "Poco/Mutex.h"
#include "Poco/Types.h"
#include <map>
#include <string>
#include <vector>
#include <libpq-fe.h>
namespace Poco {
namespace Data {
namespace PostgreSQL {
class SessionParameters
{
/// PostgreSQL session parameters
{
public:
enum HOW_TO_DISPLAY {
enum HowToDisplay
{
HTD_ASIS, // as is
HTD_HIDE, // do not display (e.g. passwords)
HID_DEBUG // debug use only
@ -49,32 +52,32 @@ public:
~SessionParameters();
std::string keyword()const;
std::string enviromentVariable() const;
std::string compiledDefault()const;
std::string currentValue() const;
std::string displayLabel() const;
HOW_TO_DISPLAY howToDisplay() const;
int displaySize()const;
std::string keyword() const;
std::string enviromentVariable() const;
std::string compiledDefault() const;
std::string currentValue() const;
std::string displayLabel() const;
HowToDisplay howToDisplay() const;
int displaySize() const;
private:
std::string _keyword;// The keyword of the option
std::string _environmentVariable;// Fallback environment variable name
std::string _compiledDefault;// Fallback compiled in default value
std::string _currentValue; // Option's current value, or NULL
std::string _displayLabel; // Label for field in a connect dialog
HOW_TO_DISPLAY _howToDisplay; // Indicates how to display this field
int _displaySize;// Field size in characters for connect dialog
std::string _keyword; // The keyword of the option
std::string _environmentVariable; // Fallback environment variable name
std::string _compiledDefault; // Fallback compiled in default value
std::string _currentValue; // Option's current value, or NULL
std::string _displayLabel; // Label for field in a connect dialog
HowToDisplay _howToDisplay; // Indicates how to display this field
int _displaySize; // Field size in characters for connect dialog
};
typedef std::map<std::string, SessionParameters> SessionParametersMap;
using SessionParametersMap = std::map<std::string, SessionParameters>;
class SessionHandle
/// PostgreSQL connection(session) handle
{
public:
explicit SessionHandle();
/// Creates session handle
@ -140,7 +143,7 @@ public:
void deallocatePreparedStatement(const std::string& aPreparedStatementToDeAllocate);
/// deallocates a previously prepared statement
int serverVersion() const;
/// remote server version
@ -180,12 +183,10 @@ private:
bool isConnectedNoLock() const;
std::string lastErrorNoLock() const;
SessionHandle(const SessionHandle&);
SessionHandle& operator= (const SessionHandle&);
private:
mutable Poco::FastMutex _sessionMutex;
PGconn* _pConnection;
std::string _connectionString;
@ -206,7 +207,6 @@ private:
// inlines
//
// SessionParameters
inline SessionParameters::SessionParameters(const std::string& aKeyword,
const std::string& anEnvironmentVariable,
@ -269,7 +269,7 @@ inline std::string SessionParameters::displayLabel() const
}
inline SessionParameters::HOW_TO_DISPLAY SessionParameters::howToDisplay() const
inline SessionParameters::HowToDisplay SessionParameters::howToDisplay() const
{
return _howToDisplay;
}
@ -280,8 +280,6 @@ inline int SessionParameters::displaySize() const
}
// SessionHandle
inline SessionHandle::operator PGconn * ()
{
return _pConnection;
@ -318,7 +316,7 @@ inline bool SessionHandle::isAsynchronousCommit()
}
}}} // namespace Poco::Data::PostgreSQL
} } } // namespace Poco::Data::PostgreSQL
#endif // SQL_PostgreSQL_SessionHandle_INCLUDED

View File

@ -22,9 +22,9 @@
#include "Poco/Data/PostgreSQL/SessionHandle.h"
#include "Poco/Data/AbstractSessionImpl.h"
#include "Poco/Data/StatementImpl.h"
#include <string>
namespace Poco {
namespace Data {
namespace PostgreSQL {
@ -34,7 +34,6 @@ class PostgreSQL_API SessionImpl: public Poco::Data::AbstractSessionImpl<Session
/// Implements SessionImpl interface
{
public:
SessionImpl(const std::string& aConnectionString,
std::size_t aLoginTimeout = LOGIN_TIMEOUT_DEFAULT);
/// Creates the SessionImpl. Opens a connection to the database
@ -129,6 +128,7 @@ private:
// inlines
//
inline bool SessionImpl::canTransact() const
{
return true;

View File

@ -17,16 +17,16 @@
#ifndef SQL_PostgreSQL_StatementExecutor_INCLUDED
#define SQL_PostgreSQL_StatementExecutor_INCLUDED
#include "Poco/Data/PostgreSQL/PostgreSQLException.h"
#include "Poco/Data/PostgreSQL/PostgreSQLTypes.h"
#include "Poco/Data/PostgreSQL/SessionHandle.h"
#include "Poco/Data/MetaColumn.h"
#include <libpq-fe.h>
#include <string>
#include <vector>
namespace Poco {
namespace Data {
namespace PostgreSQL {
@ -81,9 +81,8 @@ public:
/// Cast operator to native result handle type.
private:
void clearResults();
StatementExecutor(const StatementExecutor&);
StatementExecutor& operator= (const StatementExecutor&);
@ -109,11 +108,14 @@ private:
// inlines
//
inline StatementExecutor::operator PGresult* ()
{
return _pResultHandle;
}
}}}
} } } // namespace Poco::Data::PostgreSQL
#endif // SQL_PostgreSQL_StatementExecutor_INCLUDED

View File

@ -32,7 +32,6 @@ class PostgreSQL_API Utility
/// Various utility functions for PostgreSQL.
{
public:
static std::string serverInfo(SessionHandle* aHandlePtr);
/// Returns server info.

View File

@ -110,7 +110,7 @@ void Binder::bind(std::size_t pos, const bool& val, Direction dir)
realBind(pos, Poco::Data::MetaColumn::FDT_BOOL, &val, sizeof(bool));
}
void Binder::bind(std::size_t pos, const float& val, Direction dir)
{
poco_assert(dir == PD_IN);
@ -302,10 +302,6 @@ void Binder::updateBindVectorToCurrentValues()
}
//
// Private
//
void Binder::realBind(std::size_t aPosition, Poco::Data::MetaColumn::ColumnDataType aFieldType, const void* aBufferPtr, std::size_t aLength)
{
try

View File

@ -17,14 +17,12 @@
#include "Poco/Data/SessionFactory.h"
const PostgreSQLConnectorRegistrator pocoPostgreSQLConnectorRegistrator;
namespace Poco {
namespace Data {
namespace PostgreSQL {
std::string Connector::KEY = POCO_DATA_POSTGRESQL_CONNECTOR_NAME;
const std::string Connector::KEY("postgresql");
Connector::Connector()
@ -36,28 +34,29 @@ Connector::~Connector()
{
}
const std::string&
Connector::name() const
const std::string& Connector::name() const
{
static const std::string n(POCO_DATA_POSTGRESQL_CONNECTOR_NAME);
return n;
return KEY;
}
SessionImpl::Ptr Connector::createSession(const std::string& aConnectionString, std::size_t aTimeout)
{
return Poco::AutoPtr<Poco::Data::SessionImpl>(new SessionImpl(aConnectionString, aTimeout));
}
void Connector::registerConnector()
{
Poco::Data::SessionFactory::instance().add(new Connector());
}
void Connector::unregisterConnector()
{
Poco::Data::SessionFactory::instance().remove(POCO_DATA_POSTGRESQL_CONNECTOR_NAME);
Poco::Data::SessionFactory::instance().remove(KEY);
}
} } } // namespace Poco::Data::PostgreSQL

View File

@ -25,8 +25,8 @@ namespace Data {
namespace PostgreSQL {
Extractor::Extractor(StatementExecutor& st /*, ResultMetadata& md */)
: _statementExecutor (st)
Extractor::Extractor(StatementExecutor& st /*, ResultMetadata& md */):
_statementExecutor (st)
{
}
@ -354,6 +354,7 @@ bool Extractor::extract(std::size_t pos, Poco::Data::CLOB& val)
return true;
}
bool Extractor::extract(std::size_t pos, DateTime& val)
{
OutputParameter outputParameter = extractPreamble(pos);
@ -502,8 +503,8 @@ bool Extractor::extract(std::size_t , std::list<Poco::Int8>&)
{
throw NotImplementedException("std::list extractor must be implemented.");
}
bool Extractor::extract(std::size_t , std::vector<Poco::UInt8>&)
{
throw NotImplementedException("std::vector extractor must be implemented.");

View File

@ -14,19 +14,20 @@
#include "Poco/Data/PostgreSQL/PostgreSQLException.h"
namespace Poco {
namespace Data {
namespace PostgreSQL {
PostgreSQLException::PostgreSQLException(const std::string& aMessage)
: Poco::Data::DataException(std::string("[PostgreSQL]: ") + aMessage)
PostgreSQLException::PostgreSQLException(const std::string& aMessage):
Poco::Data::DataException(std::string("[PostgreSQL]: ") + aMessage)
{
}
PostgreSQLException::PostgreSQLException(const PostgreSQLException& anException)
: Poco::Data::DataException(anException)
PostgreSQLException::PostgreSQLException(const PostgreSQLException& anException):
Poco::Data::DataException(anException)
{
}
@ -41,8 +42,8 @@ PostgreSQLException::~PostgreSQLException() throw()
//
ConnectionException::ConnectionException(const std::string& aMessage)
: PostgreSQLException(aMessage)
ConnectionException::ConnectionException(const std::string& aMessage):
PostgreSQLException(aMessage)
{
}
@ -51,8 +52,8 @@ ConnectionException::ConnectionException(const std::string& aMessage)
// TransactionException
//
TransactionException::TransactionException(const std::string& aMessage)
: ConnectionException(aMessage)
TransactionException::TransactionException(const std::string& aMessage):
ConnectionException(aMessage)
{
}
@ -62,8 +63,8 @@ TransactionException::TransactionException(const std::string& aMessage)
//
StatementException::StatementException(const std::string& aMessage)
: PostgreSQLException(aMessage)
StatementException::StatementException(const std::string& aMessage):
PostgreSQLException(aMessage)
{
}

View File

@ -14,12 +14,14 @@
#include "Poco/Data/PostgreSQL/PostgreSQLStatementImpl.h"
namespace Poco {
namespace Data {
namespace PostgreSQL {
PostgreSQLStatementImpl::PostgreSQLStatementImpl(SessionImpl& aSessionImpl): Poco::Data::StatementImpl(aSessionImpl),
PostgreSQLStatementImpl::PostgreSQLStatementImpl(SessionImpl& aSessionImpl):
Poco::Data::StatementImpl(aSessionImpl),
_statementExecutor(aSessionImpl.handle()),
_pBinder(new Binder),
_pExtractor(new Extractor (_statementExecutor)),
@ -69,11 +71,10 @@ bool PostgreSQLStatementImpl::hasNext()
_hasNext = NEXT_FALSE;
return false;
}
else
if (NEXT_TRUE == _hasNext)
{
return true;
}
else if (NEXT_TRUE == _hasNext)
{
return true;
}
return false;
}
@ -88,7 +89,7 @@ std::size_t PostgreSQLStatementImpl::next()
Poco::Data::AbstractExtractionVec::iterator it= extractions().begin();
Poco::Data::AbstractExtractionVec::iterator itEnd = extractions().end();
std::size_t position = 0;
for (; it != itEnd; ++it)
@ -108,7 +109,7 @@ bool PostgreSQLStatementImpl::canBind() const
bool ret = false;
if ((_statementExecutor.state() >= StatementExecutor::STMT_COMPILED)
&& ! bindings().empty())
&& !bindings().empty())
{
ret = (*bindings().begin())->canBind();
}

View File

@ -14,14 +14,16 @@
#include "Poco/Data/PostgreSQL/PostgreSQLTypes.h"
namespace Poco {
namespace Data {
namespace PostgreSQL {
Poco::Data::MetaColumn::ColumnDataType oidToColumnDataType(const Oid anOID)
{
Poco::Data::MetaColumn::ColumnDataType cdt = Poco::Data::MetaColumn::FDT_UNKNOWN;
switch (anOID)
{
// bool
@ -101,5 +103,5 @@ Poco::Data::MetaColumn::ColumnDataType oidToColumnDataType(const Oid anOID)
return cdt;
}
} } } // namespace Poco::Data::PostgreSQL
} } } // namespace Poco::Data::PostgreSQL

View File

@ -33,7 +33,8 @@ const std::string SessionHandle::POSTGRESQL_REPEATABLE_READ = "REPEATABLE READ";
const std::string SessionHandle::POSTGRESQL_SERIALIZABLE = "SERIALIZABLE";
SessionHandle::SessionHandle(): _pConnection(0),
SessionHandle::SessionHandle():
_pConnection(0),
_inTransaction(false),
_isAutoCommit(true),
_isAsynchronousCommit(false),
@ -41,6 +42,7 @@ SessionHandle::SessionHandle(): _pConnection(0),
{
}
SessionHandle::~SessionHandle()
{
try
@ -65,12 +67,10 @@ bool SessionHandle::isConnectedNoLock() const
{
// DO NOT ACQUIRE THE MUTEX IN PRIVATE METHODS
if (_pConnection
&& PQstatus(_pConnection) == CONNECTION_OK)
if (_pConnection && PQstatus(_pConnection) == CONNECTION_OK)
{
return true;
}
return false;
}
@ -86,7 +86,6 @@ void SessionHandle::connect(const std::string& aConnectionString)
_pConnection = PQconnectdb(aConnectionString.c_str());
if (! isConnectedNoLock())
{
throw ConnectionFailedException(std::string("Connection Error: ") + lastErrorNoLock());
@ -376,8 +375,7 @@ void SessionHandle::setTransactionIsolation(Poco::UInt32 aTI)
}
Poco::UInt32
SessionHandle::transactionIsolation()
Poco::UInt32 SessionHandle::transactionIsolation()
{
return _tranactionIsolationLevel;
}
@ -420,9 +418,9 @@ void SessionHandle::deallocatePreparedStatement(const std::string& aPreparedStat
void SessionHandle::deallocatePreparedStatementNoLock(const std::string& aPreparedStatementToDeAllocate)
{
PGresult* pPQResult = PQexec(_pConnection, (std::string("DEALLOCATE ") + aPreparedStatementToDeAllocate).c_str());
PQResultClear resultClearer(pPQResult);
if (PQresultStatus(pPQResult) != PGRES_COMMAND_OK)
{
throw StatementException(std::string("DEALLOCATE statement failed: ") + lastErrorNoLock());
@ -562,4 +560,4 @@ SessionParametersMap SessionHandle::connectionParameters() const
}
}}} // Poco::Data::PostgreSQL
} } } // Poco::Data::PostgreSQL

View File

@ -19,9 +19,9 @@
#include "Poco/Data/Session.h"
#include "Poco/NumberParser.h"
#include "Poco/String.h"
#include <map>
namespace
{
std::string copyStripped(std::string::const_iterator aFromStringCItr, std::string::const_iterator aToStringCItr)
@ -187,7 +187,7 @@ void SessionImpl::begin()
}
void SessionImpl::commit()
void SessionImpl::commit()
{
// Not an error to issue a COMMIT without a preceding BEGIN
_sessionHandle.commit();
@ -243,4 +243,4 @@ bool SessionImpl::hasTransactionIsolation(Poco::UInt32 aTI) const
}
}}} // namespace Poco::Data::PostgreSQL
} } } // namespace Poco::Data::PostgreSQL

View File

@ -19,8 +19,7 @@
#include "Poco/UUIDGenerator.h"
#include "Poco/NumberParser.h"
#include "Poco/NumberParser.h"
#include "Poco/RegularExpression.h" // TODO: remove after C++ 11 implementation
//#include <regex> // saved for C++ 11 implementation
#include "Poco/RegularExpression.h"
#include <algorithm>
#include <set>
@ -29,62 +28,42 @@ namespace
{
std::size_t countOfPlaceHoldersInSQLStatement(const std::string& aSQLStatement)
{
// Find unique placeholders.
// Unique placeholders allow the same placeholder to be used multiple times in the same statement.
// Find unique placeholders.
// Unique placeholders allow the same placeholder to be used multiple times in the same statement.
// NON C++11 implementation
// NON C++11 implementation
//if (aSQLStatement.empty())
//{
//return 0;
//}
//if (aSQLStatement.empty())
//{
//return 0;
//}
// set to hold the unique placeholders ($1, $2, $3, etc.).
// A set is used because the same placeholder can be used muliple times
std::set<std::string> placeholderSet;
// set to hold the unique placeholders ($1, $2, $3, etc.).
// A set is used because the same placeholder can be used muliple times
std::set<std::string> placeholderSet;
Poco::RegularExpression placeholderRE("[$][0-9]+");
Poco::RegularExpression::Match match = { 0 , 0 }; // Match is a struct, not a class :-(
Poco::RegularExpression placeholderRE("[$][0-9]+");
Poco::RegularExpression::Match match = { 0 , 0 }; // Match is a struct, not a class :-(
std::size_t startingPosition = 0;
std::size_t startingPosition = 0;
while (match.offset != std::string::npos)
{
try
while (match.offset != std::string::npos)
{
if (placeholderRE.match(aSQLStatement, startingPosition, match))
try
{
placeholderSet.insert(aSQLStatement.substr(match.offset, match.length));
startingPosition = match.offset + match.length;
if (placeholderRE.match(aSQLStatement, startingPosition, match))
{
placeholderSet.insert(aSQLStatement.substr(match.offset, match.length));
startingPosition = match.offset + match.length;
}
}
catch (Poco::RegularExpressionException &)
{
break;
}
}
catch (Poco::RegularExpressionException &)
{
break;
}
}
/* C++ 11 implementation
std::regex const expression("[$][0-9]+"); // match literal dollar signs followed directly by one or more digits
std::sregex_iterator itr(aSQLStatement.begin(), aSQLStatement.end(), expression);
std::sregex_iterator eItr;
// set to hold the unique placeholders ($1, $2, $3, etc.).
// A set is used because the same placeholder can be used muliple times
std::set<std::string> placeholderSet;
while (itr != eItr)
{
placeholderSet.insert(itr->str());
++itr;
}
*/
return placeholderSet.size();
return placeholderSet.size();
}
} // namespace
@ -94,7 +73,8 @@ namespace Data {
namespace PostgreSQL {
StatementExecutor::StatementExecutor(SessionHandle& sessionHandle):_sessionHandle(sessionHandle),
StatementExecutor::StatementExecutor(SessionHandle& sessionHandle):
_sessionHandle(sessionHandle),
_state(STMT_INITED),
_pResultHandle(0),
_countPlaceholdersInSQLStatement(0),
@ -116,7 +96,9 @@ StatementExecutor::~StatementExecutor()
PQResultClear resultClearer(_pResultHandle);
}
catch (...) { }
catch (...)
{
}
}
@ -366,7 +348,7 @@ bool StatementExecutor::fetch()
for (int i = 0; i < countColumns; ++i)
{
int fieldLength = PQgetlength(_pResultHandle, static_cast<int> (_currentRow), static_cast<int> (i));
Oid columnInternalDataType = PQftype(_pResultHandle, i); // Oid of column
_outputParameterVector.at(i).setValues(oidToColumnDataType(columnInternalDataType), // Poco::Data::MetaData version of the Column Data Type
@ -429,4 +411,4 @@ void StatementExecutor::clearResults()
}
}}} // Poco::Data::PostgreSQL
} } } // Poco::Data::PostgreSQL

View File

@ -13,6 +13,7 @@
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/Data/PostgreSQL/Utility.h"
#include "Poco/Data/PostgreSQL/SessionImpl.h"
#include "Poco/NumberFormatter.h"