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 #ifndef SQL_PostgreSQL_Binder_INCLUDED
#define SQL_PostgreSQL_Binder_INCLUDED #define SQL_PostgreSQL_Binder_INCLUDED
#include "Poco/Data/PostgreSQL/PostgreSQL.h" #include "Poco/Data/PostgreSQL/PostgreSQL.h"
#include "Poco/Data/PostgreSQL/PostgreSQLTypes.h" #include "Poco/Data/PostgreSQL/PostgreSQLTypes.h"
#include "Poco/Data/PostgreSQL/PostgreSQLException.h" #include "Poco/Data/PostgreSQL/PostgreSQLException.h"
#include "Poco/Data/AbstractBinder.h" #include "Poco/Data/AbstractBinder.h"
#include "Poco/Data/MetaColumn.h" #include "Poco/Data/MetaColumn.h"
#include "Poco/Data/LOB.h" #include "Poco/Data/LOB.h"
#include "Poco/Types.h" #include "Poco/Types.h"
#include <libpq-fe.h> #include <libpq-fe.h>
namespace Poco { namespace Poco {
namespace Data { namespace Data {
namespace PostgreSQL { namespace PostgreSQL {
@@ -38,7 +38,7 @@ class PostgreSQL_API Binder: public Poco::Data::AbstractBinder
/// Allows data type mapping at statement execution time. /// Allows data type mapping at statement execution time.
{ {
public: public:
typedef SharedPtr<Binder> Ptr; using Ptr = SharedPtr<Binder>;
Binder(); Binder();
/// Creates the Binder. /// Creates the Binder.
@@ -249,7 +249,6 @@ private:
/// Common bind implementation /// Common bind implementation
private: private:
InputParameterVector _bindVector; InputParameterVector _bindVector;
}; };

View File

@@ -13,33 +13,28 @@
// SPDX-License-Identifier: BSL-1.0 // SPDX-License-Identifier: BSL-1.0
// //
#ifndef SQL_PostgreSQL_Connector_INCLUDED #ifndef SQL_PostgreSQL_Connector_INCLUDED
#define SQL_PostgreSQL_Connector_INCLUDED #define SQL_PostgreSQL_Connector_INCLUDED
#include "Poco/Data/PostgreSQL/PostgreSQL.h" #include "Poco/Data/PostgreSQL/PostgreSQL.h"
#include "Poco/Data/SessionImpl.h" #include "Poco/Data/SessionImpl.h"
#include "Poco/Data/Connector.h" #include "Poco/Data/Connector.h"
#include "Poco/AutoPtr.h" #include "Poco/AutoPtr.h"
#include <string> #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 Poco {
namespace Data { namespace Data {
namespace PostgreSQL { namespace PostgreSQL {
class PostgreSQL_API Connector: public Poco::Data::Connector class PostgreSQL_API Connector: public Poco::Data::Connector
/// Connector instantiates PostgreSQL SessionImpl objects. /// Connector instantiates PostgreSQL SessionImpl objects.
{ {
public: public:
static const std::string KEY;
static std::string KEY;
Connector(); Connector();
/// Creates the Connector. /// Creates the Connector.
@@ -65,55 +60,4 @@ public:
} } } // namespace Poco::Data::PostgreSQL } } } // 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 #endif // Data_PostgreSQL_Connector_INCLUDED

View File

@@ -21,10 +21,8 @@
#include "Poco/Data/PostgreSQL/PostgreSQL.h" #include "Poco/Data/PostgreSQL/PostgreSQL.h"
#include "Poco/Data/PostgreSQL/PostgreSQLTypes.h" #include "Poco/Data/PostgreSQL/PostgreSQLTypes.h"
#include "Poco/Data/PostgreSQL/StatementExecutor.h" #include "Poco/Data/PostgreSQL/StatementExecutor.h"
#include "Poco/Data/AbstractExtractor.h" #include "Poco/Data/AbstractExtractor.h"
#include "Poco/Data/LOB.h" #include "Poco/Data/LOB.h"
#include "Poco/Types.h" #include "Poco/Types.h"
#include "Poco/Any.h" #include "Poco/Any.h"
#include "Poco/DynamicAny.h" #include "Poco/DynamicAny.h"
@@ -32,11 +30,6 @@
namespace Poco { namespace Poco {
//namespace Dynamic {
// class Var;
//}
namespace Data { namespace Data {
namespace PostgreSQL { 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 /// If NULL is received, the incoming val value is not changed and false is returned
{ {
public: public:
typedef SharedPtr<Extractor> Ptr; using Ptr = SharedPtr<Extractor>;
Extractor(StatementExecutor& st); Extractor(StatementExecutor& st);
/// Creates the Extractor. /// Creates the Extractor.
@@ -324,9 +317,7 @@ public:
/// Extracts a Dynamic::Var list. /// Extracts a Dynamic::Var list.
private: private:
const OutputParameter& extractPreamble(std::size_t aPosition) const; const OutputParameter& extractPreamble(std::size_t aPosition) const;
bool isColumnNull(const OutputParameter& anOutputParameter) const; bool isColumnNull(const OutputParameter& anOutputParameter) const;
template <typename T> template <typename T>
@@ -357,7 +348,6 @@ private:
Extractor& operator=(const Extractor&); Extractor& operator=(const Extractor&);
private: private:
StatementExecutor& _statementExecutor; StatementExecutor& _statementExecutor;
}; };

View File

@@ -17,25 +17,23 @@
#ifndef SQL_PostgreSQL_PostgreSQLException_INCLUDED #ifndef SQL_PostgreSQL_PostgreSQLException_INCLUDED
#define SQL_PostgreSQL_PostgreSQLException_INCLUDED #define SQL_PostgreSQL_PostgreSQLException_INCLUDED
#include "Poco/Data/PostgreSQL/PostgreSQL.h" #include "Poco/Data/PostgreSQL/PostgreSQL.h"
#include "Poco/Data/DataException.h" #include "Poco/Data/DataException.h"
#include <typeinfo> #include <typeinfo>
#include <string> #include <string>
namespace Poco { namespace Poco {
namespace Data { namespace Data {
namespace PostgreSQL { 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 class PostgreSQL_API PostgreSQLException: public Poco::Data::DataException
/// Base class for all PostgreSQL exceptions /// Base class for all PostgreSQL exceptions
{ {
public: public:
explicit PostgreSQLException(const std::string& aMessage);
PostgreSQLException(const std::string& aMessage);
/// Creates PostgreSQLException. /// Creates PostgreSQLException.
PostgreSQLException(const PostgreSQLException& exc); PostgreSQLException(const PostgreSQLException& exc);
@@ -72,10 +70,8 @@ class ConnectionException : public PostgreSQLException
/// ConnectionException /// ConnectionException
{ {
public: public:
ConnectionException(const std::string& aMessage); ConnectionException(const std::string& aMessage);
/// Creates ConnectionException from string. /// Creates ConnectionException from string.
}; };
@@ -83,7 +79,6 @@ class TransactionException : public ConnectionException
/// TrabsactionException /// TrabsactionException
{ {
public: public:
TransactionException(const std::string& aMessage); TransactionException(const std::string& aMessage);
/// Creates TransactionException from string. /// Creates TransactionException from string.
}; };
@@ -93,7 +88,6 @@ class StatementException : public PostgreSQLException
/// StatementException /// StatementException
{ {
public: public:
StatementException(const std::string& aMessage); StatementException(const std::string& aMessage);
/// Creates StatementException from string. /// Creates StatementException from string.
}; };
@@ -103,6 +97,7 @@ public:
// inlines // 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);
@@ -136,4 +131,5 @@ inline void PostgreSQLException::rethrow() const
} } } // namespace Poco::Data::PostgreSQL } } } // namespace Poco::Data::PostgreSQL
#endif //SQL_PostgreSQL_PostgreSQLException_INCLUDED #endif //SQL_PostgreSQL_PostgreSQLException_INCLUDED

View File

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

View File

@@ -13,22 +13,25 @@
// SPDX-License-Identifier: BSL-1.0 // SPDX-License-Identifier: BSL-1.0
// //
#ifndef SQL_PostgreSQL_Types_INCLUDED #ifndef SQL_PostgreSQL_Types_INCLUDED
#define SQL_PostgreSQL_Types_INCLUDED #define SQL_PostgreSQL_Types_INCLUDED
#include "Poco/Data/MetaColumn.h" #include "Poco/Data/MetaColumn.h"
#include <vector> #include <vector>
#include <libpq-fe.h> #include <libpq-fe.h>
namespace Poco { namespace Poco {
namespace Data { namespace Data {
namespace PostgreSQL { namespace PostgreSQL {
/// Oid constants duplicated from PostgreSQL "include/postgresql/server/catalog/pg_type.h" /// 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 /// because PostgreSQL compile time definitions are too onerous to reproduce for this module
const Oid BOOLOID = 16; const Oid BOOLOID = 16;
const Oid INT2OID = 21; const Oid INT2OID = 21;
@@ -59,16 +62,18 @@ const Oid CASHOID = 790;
const Oid MACADDROID = 829; const Oid MACADDROID = 829;
const Oid UUIDOID = 2950; const Oid UUIDOID = 2950;
Poco::Data::MetaColumn::ColumnDataType oidToColumnDataType(const Oid anOID); Poco::Data::MetaColumn::ColumnDataType oidToColumnDataType(const Oid anOID);
class InputParameter class InputParameter
/// PostgreSQL class to record values for input parameters to SQL statements /// PostgreSQL class to record values for input parameters to SQL statements
{ {
public: public:
typedef Poco::Data::MetaColumn::ColumnDataType CDT; using CDT = Poco::Data::MetaColumn::ColumnDataType;
explicit InputParameter(CDT fieldType, const void* dataPtr, std::size_t dataLength); InputParameter(CDT fieldType, const void* dataPtr, std::size_t dataLength);
explicit InputParameter(); InputParameter();
~InputParameter(); ~InputParameter();
@@ -91,14 +96,15 @@ private:
void* _pNonStringVersionRepresentation; void* _pNonStringVersionRepresentation;
}; };
typedef std::vector <InputParameter> InputParameterVector;
using InputParameterVector = std::vector <InputParameter>;
class OutputParameter class OutputParameter
/// PostgreSQL class to record values for output parameters to capture the results /// PostgreSQL class to record values for output parameters to capture the results
{ {
public: public:
typedef Poco::Data::MetaColumn::ColumnDataType CDT; using CDT = Poco::Data::MetaColumn::ColumnDataType;
OutputParameter(CDT aFieldType, Oid internalFieldType, std::size_t rowNumber, OutputParameter(CDT aFieldType, Oid internalFieldType, std::size_t rowNumber,
const char* dataPtr, std::size_t size, bool isNull); const char* dataPtr, std::size_t size, bool isNull);
@@ -117,8 +123,6 @@ public:
bool isNull() const; bool isNull() const;
private: private:
CDT _fieldType; CDT _fieldType;
Oid _internalFieldType; Oid _internalFieldType;
std::size_t _rowNumber; std::size_t _rowNumber;
@@ -127,7 +131,8 @@ private:
bool _isNull; bool _isNull;
}; };
typedef std::vector <OutputParameter> OutputParameterVector;
using OutputParameterVector = std::vector <OutputParameter>;
class PQConnectionInfoOptionsFree class PQConnectionInfoOptionsFree
@@ -145,6 +150,7 @@ private:
PQconninfoOption* _pConnectionInfoOption; PQconninfoOption* _pConnectionInfoOption;
}; };
class PQResultClear class PQResultClear
/// PostgreSQL statement result free (RAII) /// PostgreSQL statement result free (RAII)
{ {
@@ -181,20 +187,14 @@ private:
// inlines // inlines
// //
// InputParameter inline InputParameter::InputParameter(Poco::Data::MetaColumn::ColumnDataType fieldType,
const void* aDataPtr, std::size_t theSize):
inline InputParameter::InputParameter(Poco::Data::MetaColumn::ColumnDataType aFieldType, _fieldType(fieldType),
const void* aDataPtr, std::size_t theSize): _fieldType(aFieldType),
_pData(aDataPtr), _pData(aDataPtr),
_size(theSize), _size(theSize),
_isBinary(false), _isBinary(Poco::Data::MetaColumn::FDT_BLOB == _fieldType || Poco::Data::MetaColumn::FDT_CLOB == _fieldType),
_pNonStringVersionRepresentation(0) _pNonStringVersionRepresentation(0)
{ {
if (Poco::Data::MetaColumn::FDT_BLOB == _fieldType
|| Poco::Data::MetaColumn::FDT_CLOB == _fieldType)
{
_isBinary = true;
}
} }
@@ -283,14 +283,13 @@ inline const void* InputParameter::pInternalRepresentation() const
} }
// OutputParameter
inline OutputParameter::OutputParameter(Poco::Data::MetaColumn::ColumnDataType aFieldType, inline OutputParameter::OutputParameter(Poco::Data::MetaColumn::ColumnDataType aFieldType,
Oid anInternalFieldType, Oid anInternalFieldType,
std::size_t aRowNumber, std::size_t aRowNumber,
const char* aDataPtr, const char* aDataPtr,
std::size_t theSize, std::size_t theSize,
bool anIsNull): _fieldType(aFieldType), bool anIsNull):
_fieldType(aFieldType),
_internalFieldType(anInternalFieldType), _internalFieldType(anInternalFieldType),
_rowNumber(aRowNumber), _rowNumber(aRowNumber),
_pData(aDataPtr), _pData(aDataPtr),
@@ -300,8 +299,8 @@ inline OutputParameter::OutputParameter(Poco::Data::MetaColumn::ColumnDataType a
} }
inline OutputParameter::OutputParameter() inline OutputParameter::OutputParameter():
: _fieldType (Poco::Data::MetaColumn::FDT_UNKNOWN), _fieldType(Poco::Data::MetaColumn::FDT_UNKNOWN),
_internalFieldType(static_cast<Oid>(-1)), _internalFieldType(static_cast<Oid>(-1)),
_rowNumber(0), _rowNumber(0),
_pData(0), _pData(0),
@@ -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 // PGCancelFree
inline PGCancelFree::PGCancelFree(PGcancel* aStatementCancelPtr) inline PGCancelFree::PGCancelFree(PGcancel* aStatementCancelPtr):
: _pPGCancel(aStatementCancelPtr) _pPGCancel(aStatementCancelPtr)
{ {
} }
@@ -422,6 +417,7 @@ inline PGCancelFree::~PGCancelFree()
} }
}}} } } } // namespace Poco::Data::PostgreSQL
#endif // SQL_PostgreSQL_Types_INCLUDED #endif // SQL_PostgreSQL_Types_INCLUDED

View File

@@ -13,27 +13,30 @@
// SPDX-License-Identifier: BSL-1.0 // SPDX-License-Identifier: BSL-1.0
// //
#ifndef SQL_PostgreSQL_SessionHandle_INCLUDED #ifndef SQL_PostgreSQL_SessionHandle_INCLUDED
#define SQL_PostgreSQL_SessionHandle_INCLUDED #define SQL_PostgreSQL_SessionHandle_INCLUDED
#include "Poco/Mutex.h" #include "Poco/Mutex.h"
#include "Poco/Types.h" #include "Poco/Types.h"
#include <map> #include <map>
#include <string> #include <string>
#include <vector> #include <vector>
#include <libpq-fe.h> #include <libpq-fe.h>
namespace Poco { namespace Poco {
namespace Data { namespace Data {
namespace PostgreSQL { namespace PostgreSQL {
class SessionParameters class SessionParameters
{
/// PostgreSQL session parameters /// PostgreSQL session parameters
{
public: public:
enum HOW_TO_DISPLAY { enum HowToDisplay
{
HTD_ASIS, // as is HTD_ASIS, // as is
HTD_HIDE, // do not display (e.g. passwords) HTD_HIDE, // do not display (e.g. passwords)
HID_DEBUG // debug use only HID_DEBUG // debug use only
@@ -54,7 +57,7 @@ public:
std::string compiledDefault() const; std::string compiledDefault() const;
std::string currentValue() const; std::string currentValue() const;
std::string displayLabel() const; std::string displayLabel() const;
HOW_TO_DISPLAY howToDisplay() const; HowToDisplay howToDisplay() const;
int displaySize() const; int displaySize() const;
private: private:
@@ -63,18 +66,18 @@ private:
std::string _compiledDefault; // Fallback compiled in default value std::string _compiledDefault; // Fallback compiled in default value
std::string _currentValue; // Option's current value, or NULL std::string _currentValue; // Option's current value, or NULL
std::string _displayLabel; // Label for field in a connect dialog std::string _displayLabel; // Label for field in a connect dialog
HOW_TO_DISPLAY _howToDisplay; // Indicates how to display this field HowToDisplay _howToDisplay; // Indicates how to display this field
int _displaySize; // Field size in characters for connect dialog 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 class SessionHandle
/// PostgreSQL connection(session) handle /// PostgreSQL connection(session) handle
{ {
public: public:
explicit SessionHandle(); explicit SessionHandle();
/// Creates session handle /// Creates session handle
@@ -180,12 +183,10 @@ private:
bool isConnectedNoLock() const; bool isConnectedNoLock() const;
std::string lastErrorNoLock() const; std::string lastErrorNoLock() const;
SessionHandle(const SessionHandle&); SessionHandle(const SessionHandle&);
SessionHandle& operator= (const SessionHandle&); SessionHandle& operator= (const SessionHandle&);
private: private:
mutable Poco::FastMutex _sessionMutex; mutable Poco::FastMutex _sessionMutex;
PGconn* _pConnection; PGconn* _pConnection;
std::string _connectionString; std::string _connectionString;
@@ -206,7 +207,6 @@ private:
// inlines // inlines
// //
// SessionParameters
inline SessionParameters::SessionParameters(const std::string& aKeyword, inline SessionParameters::SessionParameters(const std::string& aKeyword,
const std::string& anEnvironmentVariable, 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; return _howToDisplay;
} }
@@ -280,8 +280,6 @@ inline int SessionParameters::displaySize() const
} }
// SessionHandle
inline SessionHandle::operator PGconn * () inline SessionHandle::operator PGconn * ()
{ {
return _pConnection; return _pConnection;

View File

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

View File

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

View File

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

View File

@@ -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) void Binder::realBind(std::size_t aPosition, Poco::Data::MetaColumn::ColumnDataType aFieldType, const void* aBufferPtr, std::size_t aLength)
{ {
try try

View File

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

View File

@@ -25,8 +25,8 @@ namespace Data {
namespace PostgreSQL { namespace PostgreSQL {
Extractor::Extractor(StatementExecutor& st /*, ResultMetadata& md */) Extractor::Extractor(StatementExecutor& st /*, ResultMetadata& md */):
: _statementExecutor (st) _statementExecutor (st)
{ {
} }
@@ -354,6 +354,7 @@ bool Extractor::extract(std::size_t pos, Poco::Data::CLOB& val)
return true; return true;
} }
bool Extractor::extract(std::size_t pos, DateTime& val) bool Extractor::extract(std::size_t pos, DateTime& val)
{ {
OutputParameter outputParameter = extractPreamble(pos); OutputParameter outputParameter = extractPreamble(pos);

View File

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

View File

@@ -14,12 +14,14 @@
#include "Poco/Data/PostgreSQL/PostgreSQLStatementImpl.h" #include "Poco/Data/PostgreSQL/PostgreSQLStatementImpl.h"
namespace Poco { namespace Poco {
namespace Data { namespace Data {
namespace PostgreSQL { namespace PostgreSQL {
PostgreSQLStatementImpl::PostgreSQLStatementImpl(SessionImpl& aSessionImpl): Poco::Data::StatementImpl(aSessionImpl), PostgreSQLStatementImpl::PostgreSQLStatementImpl(SessionImpl& aSessionImpl):
Poco::Data::StatementImpl(aSessionImpl),
_statementExecutor(aSessionImpl.handle()), _statementExecutor(aSessionImpl.handle()),
_pBinder(new Binder), _pBinder(new Binder),
_pExtractor(new Extractor (_statementExecutor)), _pExtractor(new Extractor (_statementExecutor)),
@@ -69,8 +71,7 @@ bool PostgreSQLStatementImpl::hasNext()
_hasNext = NEXT_FALSE; _hasNext = NEXT_FALSE;
return false; return false;
} }
else else if (NEXT_TRUE == _hasNext)
if (NEXT_TRUE == _hasNext)
{ {
return true; return true;
} }

View File

@@ -14,10 +14,12 @@
#include "Poco/Data/PostgreSQL/PostgreSQLTypes.h" #include "Poco/Data/PostgreSQL/PostgreSQLTypes.h"
namespace Poco { namespace Poco {
namespace Data { namespace Data {
namespace PostgreSQL { namespace PostgreSQL {
Poco::Data::MetaColumn::ColumnDataType oidToColumnDataType(const Oid anOID) Poco::Data::MetaColumn::ColumnDataType oidToColumnDataType(const Oid anOID)
{ {
Poco::Data::MetaColumn::ColumnDataType cdt = Poco::Data::MetaColumn::FDT_UNKNOWN; Poco::Data::MetaColumn::ColumnDataType cdt = Poco::Data::MetaColumn::FDT_UNKNOWN;
@@ -101,5 +103,5 @@ Poco::Data::MetaColumn::ColumnDataType oidToColumnDataType(const Oid anOID)
return cdt; 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"; const std::string SessionHandle::POSTGRESQL_SERIALIZABLE = "SERIALIZABLE";
SessionHandle::SessionHandle(): _pConnection(0), SessionHandle::SessionHandle():
_pConnection(0),
_inTransaction(false), _inTransaction(false),
_isAutoCommit(true), _isAutoCommit(true),
_isAsynchronousCommit(false), _isAsynchronousCommit(false),
@@ -41,6 +42,7 @@ SessionHandle::SessionHandle(): _pConnection(0),
{ {
} }
SessionHandle::~SessionHandle() SessionHandle::~SessionHandle()
{ {
try try
@@ -65,12 +67,10 @@ bool SessionHandle::isConnectedNoLock() const
{ {
// DO NOT ACQUIRE THE MUTEX IN PRIVATE METHODS // DO NOT ACQUIRE THE MUTEX IN PRIVATE METHODS
if (_pConnection if (_pConnection && PQstatus(_pConnection) == CONNECTION_OK)
&& PQstatus(_pConnection) == CONNECTION_OK)
{ {
return true; return true;
} }
return false; return false;
} }
@@ -86,7 +86,6 @@ void SessionHandle::connect(const std::string& aConnectionString)
_pConnection = PQconnectdb(aConnectionString.c_str()); _pConnection = PQconnectdb(aConnectionString.c_str());
if (! isConnectedNoLock()) if (! isConnectedNoLock())
{ {
throw ConnectionFailedException(std::string("Connection Error: ") + lastErrorNoLock()); throw ConnectionFailedException(std::string("Connection Error: ") + lastErrorNoLock());
@@ -376,8 +375,7 @@ void SessionHandle::setTransactionIsolation(Poco::UInt32 aTI)
} }
Poco::UInt32 Poco::UInt32 SessionHandle::transactionIsolation()
SessionHandle::transactionIsolation()
{ {
return _tranactionIsolationLevel; return _tranactionIsolationLevel;
} }

View File

@@ -19,9 +19,9 @@
#include "Poco/Data/Session.h" #include "Poco/Data/Session.h"
#include "Poco/NumberParser.h" #include "Poco/NumberParser.h"
#include "Poco/String.h" #include "Poco/String.h"
#include <map> #include <map>
namespace namespace
{ {
std::string copyStripped(std::string::const_iterator aFromStringCItr, std::string::const_iterator aToStringCItr) std::string copyStripped(std::string::const_iterator aFromStringCItr, std::string::const_iterator aToStringCItr)

View File

@@ -19,8 +19,7 @@
#include "Poco/UUIDGenerator.h" #include "Poco/UUIDGenerator.h"
#include "Poco/NumberParser.h" #include "Poco/NumberParser.h"
#include "Poco/NumberParser.h" #include "Poco/NumberParser.h"
#include "Poco/RegularExpression.h" // TODO: remove after C++ 11 implementation #include "Poco/RegularExpression.h"
//#include <regex> // saved for C++ 11 implementation
#include <algorithm> #include <algorithm>
#include <set> #include <set>
@@ -29,7 +28,6 @@ namespace
{ {
std::size_t countOfPlaceHoldersInSQLStatement(const std::string& aSQLStatement) std::size_t countOfPlaceHoldersInSQLStatement(const std::string& aSQLStatement)
{ {
// Find unique placeholders. // Find unique placeholders.
// Unique placeholders allow the same placeholder to be used multiple times in the same statement. // Unique placeholders allow the same placeholder to be used multiple times in the same statement.
@@ -63,27 +61,8 @@ namespace
{ {
break; 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 } // namespace
@@ -94,7 +73,8 @@ namespace Data {
namespace PostgreSQL { namespace PostgreSQL {
StatementExecutor::StatementExecutor(SessionHandle& sessionHandle):_sessionHandle(sessionHandle), StatementExecutor::StatementExecutor(SessionHandle& sessionHandle):
_sessionHandle(sessionHandle),
_state(STMT_INITED), _state(STMT_INITED),
_pResultHandle(0), _pResultHandle(0),
_countPlaceholdersInSQLStatement(0), _countPlaceholdersInSQLStatement(0),
@@ -116,7 +96,9 @@ StatementExecutor::~StatementExecutor()
PQResultClear resultClearer(_pResultHandle); PQResultClear resultClearer(_pResultHandle);
} }
catch (...) { } catch (...)
{
}
} }

View File

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