mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-24 00:49:46 +02:00
code cleanup
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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.");
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user