mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-24 00:49:46 +02:00
merge pg binary extraction support
This commit is contained in:
1071
Data/PostgreSQL/src/BinaryExtractor.cpp
Normal file
1071
Data/PostgreSQL/src/BinaryExtractor.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@@ -28,7 +28,7 @@ namespace PostgreSQL {
|
||||
|
||||
|
||||
Extractor::Extractor(StatementExecutor& st /*, ResultMetadata& md */):
|
||||
_statementExecutor (st)
|
||||
_statementExecutor(st)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -40,8 +40,7 @@ Extractor::~Extractor()
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::Int8& val)
|
||||
{
|
||||
|
||||
OutputParameter outputParameter = extractPreamble(pos);
|
||||
const OutputParameter& outputParameter = extractPreamble(pos);
|
||||
|
||||
int tempVal = 0;
|
||||
if (isColumnNull(outputParameter) || !Poco::NumberParser::tryParse(outputParameter.pData(), tempVal))
|
||||
@@ -56,7 +55,7 @@ bool Extractor::extract(std::size_t pos, Poco::Int8& val)
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::UInt8& val)
|
||||
{
|
||||
OutputParameter outputParameter = extractPreamble(pos);
|
||||
const OutputParameter& outputParameter = extractPreamble(pos);
|
||||
|
||||
unsigned int tempVal = 0;
|
||||
if (isColumnNull(outputParameter)|| !Poco::NumberParser::tryParseUnsigned(outputParameter.pData(), tempVal))
|
||||
@@ -71,7 +70,7 @@ bool Extractor::extract(std::size_t pos, Poco::UInt8& val)
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::Int16& val)
|
||||
{
|
||||
OutputParameter outputParameter = extractPreamble(pos);
|
||||
const OutputParameter& outputParameter = extractPreamble(pos);
|
||||
|
||||
int tempVal = 0;
|
||||
if (isColumnNull(outputParameter) || !Poco::NumberParser::tryParse(outputParameter.pData(), tempVal))
|
||||
@@ -86,7 +85,7 @@ bool Extractor::extract(std::size_t pos, Poco::Int16& val)
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::UInt16& val)
|
||||
{
|
||||
OutputParameter outputParameter = extractPreamble(pos);
|
||||
const OutputParameter& outputParameter = extractPreamble(pos);
|
||||
|
||||
unsigned int tempVal = 0;
|
||||
if (isColumnNull(outputParameter) || !Poco::NumberParser::tryParseUnsigned(outputParameter.pData(), tempVal))
|
||||
@@ -101,7 +100,7 @@ bool Extractor::extract(std::size_t pos, Poco::UInt16& val)
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::Int32& val)
|
||||
{
|
||||
OutputParameter outputParameter = extractPreamble(pos);
|
||||
const OutputParameter& outputParameter = extractPreamble(pos);
|
||||
|
||||
if (isColumnNull(outputParameter) || !Poco::NumberParser::tryParse(outputParameter.pData(), val))
|
||||
{
|
||||
@@ -114,7 +113,7 @@ bool Extractor::extract(std::size_t pos, Poco::Int32& val)
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::UInt32& val)
|
||||
{
|
||||
OutputParameter outputParameter = extractPreamble(pos);
|
||||
const OutputParameter& outputParameter = extractPreamble(pos);
|
||||
|
||||
if (isColumnNull(outputParameter) || !Poco::NumberParser::tryParseUnsigned(outputParameter.pData(), val))
|
||||
{
|
||||
@@ -127,7 +126,7 @@ bool Extractor::extract(std::size_t pos, Poco::UInt32& val)
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::Int64& val)
|
||||
{
|
||||
OutputParameter outputParameter = extractPreamble(pos);
|
||||
const OutputParameter& outputParameter = extractPreamble(pos);
|
||||
|
||||
if (isColumnNull(outputParameter) || !Poco::NumberParser::tryParse64(outputParameter.pData(), val))
|
||||
{
|
||||
@@ -140,7 +139,7 @@ bool Extractor::extract(std::size_t pos, Poco::Int64& val)
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::UInt64& val)
|
||||
{
|
||||
OutputParameter outputParameter = extractPreamble(pos);
|
||||
const OutputParameter& outputParameter = extractPreamble(pos);
|
||||
|
||||
if (isColumnNull(outputParameter) || !Poco::NumberParser::tryParseUnsigned64(outputParameter.pData(), val))
|
||||
{
|
||||
@@ -154,7 +153,7 @@ bool Extractor::extract(std::size_t pos, Poco::UInt64& val)
|
||||
#ifndef POCO_INT64_IS_LONG
|
||||
bool Extractor::extract(std::size_t pos, long& val)
|
||||
{
|
||||
OutputParameter outputParameter = extractPreamble(pos);
|
||||
const OutputParameter& outputParameter = extractPreamble(pos);
|
||||
|
||||
Poco::Int64 tempVal = 0;
|
||||
if (isColumnNull(outputParameter) || !Poco::NumberParser::tryParse64(outputParameter.pData(), tempVal))
|
||||
@@ -169,7 +168,7 @@ bool Extractor::extract(std::size_t pos, long& val)
|
||||
|
||||
bool Extractor::extract(std::size_t pos, unsigned long& val)
|
||||
{
|
||||
OutputParameter outputParameter = extractPreamble(pos);
|
||||
const OutputParameter& outputParameter = extractPreamble(pos);
|
||||
|
||||
Poco::UInt64 tempVal = 0;
|
||||
if (isColumnNull(outputParameter) || !Poco::NumberParser::tryParseUnsigned64(outputParameter.pData(), tempVal))
|
||||
@@ -185,7 +184,7 @@ bool Extractor::extract(std::size_t pos, unsigned long& val)
|
||||
|
||||
bool Extractor::extract(std::size_t pos, bool& val)
|
||||
{
|
||||
OutputParameter outputParameter = extractPreamble(pos);
|
||||
const OutputParameter& outputParameter = extractPreamble(pos);
|
||||
|
||||
if (isColumnNull(outputParameter))
|
||||
{
|
||||
@@ -200,7 +199,7 @@ bool Extractor::extract(std::size_t pos, bool& val)
|
||||
|
||||
bool Extractor::extract(std::size_t pos, float& val)
|
||||
{
|
||||
OutputParameter outputParameter = extractPreamble(pos);
|
||||
const OutputParameter& outputParameter = extractPreamble(pos);
|
||||
|
||||
double tempVal = 0.0;
|
||||
if (isColumnNull(outputParameter) || !Poco::NumberParser::tryParseFloat(outputParameter.pData(), tempVal))
|
||||
@@ -215,7 +214,7 @@ bool Extractor::extract(std::size_t pos, float& val)
|
||||
|
||||
bool Extractor::extract(std::size_t pos, double& val)
|
||||
{
|
||||
OutputParameter outputParameter = extractPreamble(pos);
|
||||
const OutputParameter& outputParameter = extractPreamble(pos);
|
||||
|
||||
if (isColumnNull(outputParameter) || !Poco::NumberParser::tryParseFloat(outputParameter.pData(), val))
|
||||
{
|
||||
@@ -228,7 +227,7 @@ bool Extractor::extract(std::size_t pos, double& val)
|
||||
|
||||
bool Extractor::extract(std::size_t pos, char& val)
|
||||
{
|
||||
OutputParameter outputParameter = extractPreamble(pos);
|
||||
const OutputParameter& outputParameter = extractPreamble(pos);
|
||||
|
||||
if (isColumnNull(outputParameter))
|
||||
{
|
||||
@@ -242,7 +241,7 @@ bool Extractor::extract(std::size_t pos, char& val)
|
||||
|
||||
bool Extractor::extract(std::size_t pos, std::string& val)
|
||||
{
|
||||
OutputParameter outputParameter = extractPreamble(pos);
|
||||
const OutputParameter& outputParameter = extractPreamble(pos);
|
||||
|
||||
if (isColumnNull(outputParameter))
|
||||
{
|
||||
@@ -256,7 +255,7 @@ bool Extractor::extract(std::size_t pos, std::string& val)
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::Data::BLOB& val)
|
||||
{
|
||||
OutputParameter outputParameter = extractPreamble(pos);
|
||||
const OutputParameter& outputParameter = extractPreamble(pos);
|
||||
|
||||
if (isColumnNull(outputParameter))
|
||||
{
|
||||
@@ -291,7 +290,7 @@ bool Extractor::extract(std::size_t pos, Poco::Data::BLOB& val)
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::Data::CLOB& val)
|
||||
{
|
||||
OutputParameter outputParameter = extractPreamble(pos);
|
||||
const OutputParameter& outputParameter = extractPreamble(pos);
|
||||
|
||||
if (isColumnNull(outputParameter))
|
||||
{
|
||||
@@ -305,7 +304,7 @@ bool Extractor::extract(std::size_t pos, Poco::Data::CLOB& val)
|
||||
|
||||
bool Extractor::extract(std::size_t pos, DateTime& val)
|
||||
{
|
||||
OutputParameter outputParameter = extractPreamble(pos);
|
||||
const OutputParameter& outputParameter = extractPreamble(pos);
|
||||
|
||||
if (isColumnNull(outputParameter))
|
||||
{
|
||||
@@ -314,7 +313,7 @@ bool Extractor::extract(std::size_t pos, DateTime& val)
|
||||
|
||||
int tzd = -1;
|
||||
DateTime dateTime;
|
||||
if (!DateTimeParser::tryParse("%Y-%m-%d %H:%M:%s", outputParameter.pData(), dateTime, tzd))
|
||||
if (!DateTimeParser::tryParse(outputParameter.pData(), dateTime, tzd))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -327,7 +326,7 @@ bool Extractor::extract(std::size_t pos, DateTime& val)
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Date& val)
|
||||
{
|
||||
OutputParameter outputParameter = extractPreamble(pos);
|
||||
const OutputParameter& outputParameter = extractPreamble(pos);
|
||||
|
||||
if (isColumnNull(outputParameter))
|
||||
{
|
||||
@@ -348,7 +347,7 @@ bool Extractor::extract(std::size_t pos, Date& val)
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Time& val)
|
||||
{
|
||||
OutputParameter outputParameter = extractPreamble(pos);
|
||||
const OutputParameter& outputParameter = extractPreamble(pos);
|
||||
|
||||
if (isColumnNull(outputParameter))
|
||||
{
|
||||
@@ -372,7 +371,7 @@ bool Extractor::extract(std::size_t pos, Time& val)
|
||||
|
||||
bool Extractor::extract(std::size_t pos, UUID& val)
|
||||
{
|
||||
OutputParameter outputParameter = extractPreamble(pos);
|
||||
const OutputParameter& outputParameter = extractPreamble(pos);
|
||||
|
||||
if (isColumnNull(outputParameter))
|
||||
{
|
||||
@@ -397,7 +396,7 @@ bool Extractor::extract(std::size_t pos, Dynamic::Var& val)
|
||||
|
||||
bool Extractor::isNull(std::size_t col, std::size_t /*row*/)
|
||||
{
|
||||
OutputParameter outputParameter = extractPreamble(col);
|
||||
const OutputParameter& outputParameter = extractPreamble(col);
|
||||
|
||||
if (isColumnNull(outputParameter))
|
||||
{
|
||||
@@ -425,15 +424,9 @@ const OutputParameter& Extractor::extractPreamble(std::size_t aPosition) const
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::isColumnNull(const OutputParameter& anOutputParameter) const
|
||||
{
|
||||
return anOutputParameter.isNull() || 0 == anOutputParameter.pData();
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extractToDynamic(std::size_t pos, Dynamic::Var& val)
|
||||
{
|
||||
OutputParameter outputParameter = _statementExecutor.resultColumn(pos);
|
||||
const OutputParameter& outputParameter = _statementExecutor.resultColumn(pos);
|
||||
|
||||
if (isColumnNull(outputParameter))
|
||||
{
|
||||
@@ -525,7 +518,7 @@ bool Extractor::extractToDynamic(std::size_t pos, Dynamic::Var& val)
|
||||
}
|
||||
//timestamp
|
||||
case TIMESTAMPOID:
|
||||
case TIMESTAMPZOID:
|
||||
case TIMESTAMPTZOID:
|
||||
{
|
||||
DateTime dt;
|
||||
success = extract(pos, dt);
|
||||
|
@@ -13,7 +13,8 @@
|
||||
|
||||
|
||||
#include "Poco/Data/PostgreSQL/PostgreSQLStatementImpl.h"
|
||||
|
||||
#include "Poco/Data/PostgreSQL/Extractor.h"
|
||||
#include "Poco/Data/PostgreSQL/BinaryExtractor.h"
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
@@ -22,11 +23,14 @@ namespace PostgreSQL {
|
||||
|
||||
PostgreSQLStatementImpl::PostgreSQLStatementImpl(SessionImpl& aSessionImpl):
|
||||
Poco::Data::StatementImpl(aSessionImpl),
|
||||
_statementExecutor(aSessionImpl.handle()),
|
||||
_statementExecutor(aSessionImpl.handle(), aSessionImpl.isBinaryExtraction()),
|
||||
_pBinder(new Binder),
|
||||
_pExtractor(new Extractor (_statementExecutor)),
|
||||
_hasNext(NEXT_DONTKNOW)
|
||||
{
|
||||
if (aSessionImpl.isBinaryExtraction())
|
||||
_pExtractor = new BinaryExtractor(_statementExecutor);
|
||||
else
|
||||
_pExtractor = new Extractor(_statementExecutor);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -90,7 +90,7 @@ Poco::Data::MetaColumn::ColumnDataType oidToColumnDataType(const Oid anOID)
|
||||
case TIMESTAMPOID:
|
||||
cdt = Poco::Data::MetaColumn::FDT_TIMESTAMP;
|
||||
break;
|
||||
case TIMESTAMPZOID:
|
||||
case TIMESTAMPTZOID:
|
||||
cdt = Poco::Data::MetaColumn::FDT_TIMESTAMP;
|
||||
break;
|
||||
|
||||
|
@@ -493,6 +493,23 @@ std::string SessionHandle::clientEncoding() const
|
||||
}
|
||||
|
||||
|
||||
std::string SessionHandle::parameterStatus(const std::string& param) const
|
||||
{
|
||||
Poco::FastMutex::ScopedLock mutexLocker(_sessionMutex);
|
||||
|
||||
if (!isConnectedNoLock())
|
||||
{
|
||||
throw NotConnectedException();
|
||||
}
|
||||
|
||||
const char* pValue = PQparameterStatus(_pConnection, param.c_str());
|
||||
if (pValue)
|
||||
return std::string(pValue);
|
||||
else
|
||||
return std::string();
|
||||
}
|
||||
|
||||
|
||||
int SessionHandle::libpqVersion() const
|
||||
{
|
||||
return PQlibVersion();
|
||||
|
@@ -99,7 +99,7 @@ void SessionImpl::open(const std::string& aConnectionString)
|
||||
}
|
||||
}
|
||||
|
||||
poco_assert_dbg (! connectionString().empty());
|
||||
poco_assert_dbg (!connectionString().empty());
|
||||
|
||||
unsigned int timeout = static_cast<unsigned int>(getLoginTimeout());
|
||||
|
||||
@@ -140,6 +140,10 @@ void SessionImpl::open(const std::string& aConnectionString)
|
||||
addFeature("asynchronousCommit",
|
||||
&SessionImpl::setAutoCommit,
|
||||
&SessionImpl::isAutoCommit);
|
||||
|
||||
addFeature("binaryExtraction",
|
||||
&SessionImpl::setBinaryExtraction,
|
||||
&SessionImpl::isBinaryExtraction);
|
||||
}
|
||||
|
||||
|
||||
@@ -244,4 +248,13 @@ bool SessionImpl::hasTransactionIsolation(Poco::UInt32 aTI) const
|
||||
}
|
||||
|
||||
|
||||
void SessionImpl::setBinaryExtraction(const std::string& feature, bool enabled)
|
||||
{
|
||||
if (enabled && _sessionHandle.parameterStatus("integer_datetimes") != "on")
|
||||
throw PostgreSQLException("binary extraction is not supported with this server (ingeger_datetimes must be enabled on the server)");
|
||||
|
||||
_binaryExtraction = enabled;
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::PostgreSQL
|
||||
|
@@ -72,8 +72,9 @@ namespace Data {
|
||||
namespace PostgreSQL {
|
||||
|
||||
|
||||
StatementExecutor::StatementExecutor(SessionHandle& sessionHandle):
|
||||
StatementExecutor::StatementExecutor(SessionHandle& sessionHandle, bool binaryExtraction):
|
||||
_sessionHandle(sessionHandle),
|
||||
_binaryExtraction(binaryExtraction),
|
||||
_state(STMT_INITED),
|
||||
_pResultHandle(0),
|
||||
_countPlaceholdersInSQLStatement(0),
|
||||
@@ -248,11 +249,12 @@ void StatementExecutor::execute()
|
||||
{
|
||||
Poco::FastMutex::ScopedLock mutexLocker(_sessionHandle.mutex());
|
||||
|
||||
ptrPGResult = PQexecPrepared (_sessionHandle,
|
||||
ptrPGResult = PQexecPrepared(_sessionHandle,
|
||||
_preparedStatementName.c_str(), (int)_countPlaceholdersInSQLStatement,
|
||||
_inputParameterVector.size() != 0 ? &pParameterVector[ 0 ] : 0,
|
||||
_inputParameterVector.size() != 0 ? ¶meterLengthVector[ 0 ] : 0,
|
||||
_inputParameterVector.size() != 0 ? ¶meterFormatVector[ 0 ] : 0, 0);
|
||||
_inputParameterVector.size() != 0 ? ¶meterFormatVector[ 0 ] : 0,
|
||||
_binaryExtraction ? 1 : 0);
|
||||
}
|
||||
|
||||
// Don't setup to auto clear the result (ptrPGResult). It is required to retrieve the results later.
|
||||
|
Reference in New Issue
Block a user