Update POCO to 1.11.0

This commit is contained in:
Sandu Liviu Catalin committed 2021-08-22 18:07:06 +03:00
1 parent 151077c799
commit 7a3d92d1d1
450 files changed
+25219 -6528

No files matched your search

+5
View File
@@ -322,6 +322,9 @@ public:
void bind(std::size_t pos, const std::list<DateTime>& val, Direction dir);
/// Binds a DateTime list.
void bind(std::size_t pos, const UUID& val, Direction dir);
/// Binds a UUID.
void bind(std::size_t pos, const NullData& val, Direction dir);
/// Binds a null. In-bound only.
@@ -367,6 +370,7 @@ private:
typedef std::vector<AnyVec> AnyVecVec;
typedef std::map<char*, std::string*> StringMap;
typedef std::map<UTF16String::value_type*, UTF16String*> UTF16StringMap;
typedef std::map<char*, UUID*> UUIDMap;
typedef std::map<SQL_DATE_STRUCT*, Date*> DateMap;
typedef std::map<SQL_TIME_STRUCT*, Time*> TimeMap;
typedef std::map<SQL_TIMESTAMP_STRUCT*, DateTime*> TimestampMap;
@@ -998,6 +1002,7 @@ private:
TimestampMap _timestamps;
StringMap _strings;
UTF16StringMap _utf16Strings;
UUIDMap _uuids;
DateVecVec _dateVecVec;
TimeVecVec _timeVecVec;
+70 -24
View File
@@ -18,13 +18,13 @@
#define Data_ODBC_Extractor_INCLUDED
#include "Poco/Data/Constants.h"
#include "Poco/Data/ODBC/ODBC.h"
#include "Poco/Data/AbstractExtractor.h"
#include "Poco/Data/ODBC/Preparator.h"
#include "Poco/Data/ODBC/ODBCMetaColumn.h"
#include "Poco/Data/ODBC/Error.h"
#include "Poco/Data/ODBC/Utility.h"
#include "Poco/Data/AbstractExtractor.h"
#include "Poco/Data/Constants.h"
#include "Poco/Data/Date.h"
#include "Poco/Data/Time.h"
#include "Poco/DateTime.h"
@@ -32,6 +32,8 @@
#include "Poco/Dynamic/Var.h"
#include "Poco/Nullable.h"
#include "Poco/UTFString.h"
#include "Poco/TextEncoding.h"
#include "Poco/TextConverter.h"
#include "Poco/Exception.h"
#include <map>
#ifdef POCO_OS_FAMILY_WINDOWS
@@ -52,8 +54,9 @@ class ODBC_API Extractor: public Poco::Data::AbstractExtractor
public:
typedef Preparator::Ptr PreparatorPtr;
Extractor(const StatementHandle& rStmt,
Preparator::Ptr pPreparator);
Extractor(const StatementHandle& rStmt,
Preparator::Ptr pPreparator,
Poco::TextEncoding::Ptr pDBEncoding = nullptr);
/// Creates the Extractor.
~Extractor();
@@ -304,7 +307,10 @@ public:
bool extract(std::size_t pos, std::list<Poco::DateTime>& val);
/// Extracts a DateTime list.
bool extract(std::size_t pos, Poco::UUID& val);
/// Extracts a UUID.
bool extract(std::size_t pos, Poco::Any& val);
/// Extracts an Any.
@@ -339,7 +345,7 @@ public:
/// Returns true if the value at [col,row] is null.
void reset();
/// Resets the internally cached length indicators.
/// Resets the internally cached length indicators.
private:
static const int CHUNK_SIZE = 1024;
@@ -365,7 +371,7 @@ private:
{
if (isNull(pos)) return false;
poco_assert_dbg (typeid(T) == _pPreparator->at(pos).type());
val = *AnyCast<T>(&_pPreparator->at(pos));
val = *AnyCast<T>(&_pPreparator->at(pos));
return true;
}
@@ -384,7 +390,7 @@ private:
bool extractBoundImplContainer(std::size_t pos, std::vector<std::string>& values);
bool extractBoundImplContainer(std::size_t pos, std::deque<std::string>& values);
bool extractBoundImplContainer(std::size_t pos, std::list<std::string>& values);
bool extractBoundImplContainer(std::size_t pos, std::list<std::string>& values);
bool extractBoundImplContainer(std::size_t pos, std::vector<Poco::UTF16String>& values);
bool extractBoundImplContainer(std::size_t pos, std::deque<Poco::UTF16String>& values);
bool extractBoundImplContainer(std::size_t pos, std::list<Poco::UTF16String>& values);
@@ -462,12 +468,12 @@ private:
bool extractManualImpl(std::size_t pos, T& val, SQLSMALLINT cType)
{
SQLRETURN rc = 0;
T value = (T) 0;
T value{};
resizeLengths(pos);
rc = SQLGetData(_rStmt,
(SQLUSMALLINT) pos + 1,
rc = SQLGetData(_rStmt,
(SQLUSMALLINT) pos + 1,
cType, //C data type
&value, //returned value
0, //buffer length (ignored)
@@ -475,10 +481,10 @@ private:
if (Utility::isError(rc))
throw StatementException(_rStmt, "SQLGetData()");
if (isNullLengthIndicator(_lengths[pos]))
if (isNullLengthIndicator(_lengths[pos]))
return false;
else
else
{
//for fixed-length data, buffer must be large enough
//otherwise, driver may write past the end
@@ -567,16 +573,53 @@ private:
case MetaColumn::FDT_TIMESTAMP:
{ return extAny<T, Poco::DateTime>(pos, val); }
default:
case MetaColumn::FDT_UUID:
{ return extAny<T, Poco::UUID>(pos, val); }
default:
throw DataFormatException("Unsupported data type.");
}
return false;
}
template <typename C>
bool stringContainerExtractConvert(std::size_t pos, C& val)
{
bool ret = false;
C res;
ret = extractBoundImplContainer(pos, res);
val.clear();
if (ret)
{
Poco::TextConverter conv(*_pDBEncoding, *_pToEncoding);
val.resize(res.size());
typename C::iterator vIt = val.begin();
typename C::iterator it = res.begin();
for (; it != res.end(); ++it, ++vIt) conv.convert(*it, *vIt);
}
return ret;
}
template <typename C>
bool stringContainerExtract(std::size_t pos, C& val)
{
bool ret = false;
if (Preparator::DE_BOUND == _dataExtraction)
{
if (!_transcode)
ret = extractBoundImplContainer(pos, val);
else
ret = stringContainerExtractConvert(pos, val);
}
else
throw InvalidAccessException("Direct container extraction only allowed for bound mode.");
return ret;
}
bool isNullLengthIndicator(SQLLEN val) const;
/// The reason for this utility wrapper are platforms where
/// SQLLEN macro (a.k.a. SQLINTEGER) yields 64-bit value,
/// The reason for this utility wrapper are platforms where
/// SQLLEN macro (a.k.a. SQLINTEGER) yields 64-bit value,
/// while SQL_NULL_DATA (#define'd as -1 literal) remains 32-bit.
SQLINTEGER columnSize(std::size_t pos) const;
@@ -585,6 +628,9 @@ private:
PreparatorPtr _pPreparator;
Preparator::DataExtraction _dataExtraction;
std::vector<SQLLEN> _lengths;
Poco::TextEncoding::Ptr _pDBEncoding;
bool _transcode;
Poco::TextEncoding::Ptr _pToEncoding;
};
@@ -640,42 +686,42 @@ inline bool Extractor::extractBoundImplContainer(std::size_t pos, std::list<Poco
}
inline bool Extractor::extractBoundImplContainer(std::size_t pos,
inline bool Extractor::extractBoundImplContainer(std::size_t pos,
std::vector<Poco::Data::CLOB>& values)
{
return extractBoundImplContainerLOB(pos, values);
}
inline bool Extractor::extractBoundImplContainer(std::size_t pos,
inline bool Extractor::extractBoundImplContainer(std::size_t pos,
std::deque<Poco::Data::CLOB>& values)
{
return extractBoundImplContainerLOB(pos, values);
}
inline bool Extractor::extractBoundImplContainer(std::size_t pos,
inline bool Extractor::extractBoundImplContainer(std::size_t pos,
std::list<Poco::Data::CLOB>& values)
{
return extractBoundImplContainerLOB(pos, values);
}
inline bool Extractor::extractBoundImplContainer(std::size_t pos,
inline bool Extractor::extractBoundImplContainer(std::size_t pos,
std::vector<Poco::Data::BLOB>& values)
{
return extractBoundImplContainerLOB(pos, values);
}
inline bool Extractor::extractBoundImplContainer(std::size_t pos,
inline bool Extractor::extractBoundImplContainer(std::size_t pos,
std::deque<Poco::Data::BLOB>& values)
{
return extractBoundImplContainerLOB(pos, values);
}
inline bool Extractor::extractBoundImplContainer(std::size_t pos,
inline bool Extractor::extractBoundImplContainer(std::size_t pos,
std::list<Poco::Data::BLOB>& values)
{
return extractBoundImplContainerLOB(pos, values);
@@ -702,7 +748,7 @@ inline void Extractor::reset()
inline void Extractor::resizeLengths(std::size_t pos)
{
if (pos >= _lengths.size())
if (pos >= _lengths.size())
_lengths.resize(pos + 1, (SQLLEN) 0);
}
@@ -136,8 +136,6 @@ private:
/// Called whenever SQLExecute returns SQL_NEED_DATA. This is expected
/// behavior for PB_AT_EXEC binding mode.
void getData();
void addPreparator();
void fillColumns();
void checkError(SQLRETURN rc, const std::string& msg="");
+51 -36
View File
@@ -18,12 +18,12 @@
#define Data_ODBC_Preparator_INCLUDED
#include "Poco/Data/Constants.h"
#include "Poco/Data/ODBC/ODBC.h"
#include "Poco/Data/ODBC/Handle.h"
#include "Poco/Data/ODBC/ODBCMetaColumn.h"
#include "Poco/Data/ODBC/Utility.h"
#include "Poco/Data/AbstractPreparator.h"
#include "Poco/Data/Constants.h"
#include "Poco/Data/LOB.h"
#include "Poco/Any.h"
#include "Poco/DynamicAny.h"
@@ -49,13 +49,13 @@ namespace ODBC {
class ODBC_API Preparator : public AbstractPreparator
/// Class used for database preparation where we first have to register all data types
/// with respective memory output locations before extracting data.
/// Class used for database preparation where we first have to register all data types
/// with respective memory output locations before extracting data.
/// Extraction works in two-phases: first prepare is called once, then extract n-times.
/// In ODBC, SQLBindCol/SQLFetch is the preferred method of data retrieval (SQLGetData is available,
/// however with numerous driver implementation dependent limitations and inferior performance).
/// In order to fit this functionality into Poco DataConnectors framework, every ODBC SQL statement
/// instantiates its own Preparator object.
/// In ODBC, SQLBindCol/SQLFetch is the preferred method of data retrieval (SQLGetData is available,
/// however with numerous driver implementation dependent limitations and inferior performance).
/// In order to fit this functionality into Poco DataConnectors framework, every ODBC SQL statement
/// instantiates its own Preparator object.
/// This is done once per statement execution (from StatementImpl::bindImpl()).
///
/// Preparator object is used to :
@@ -69,7 +69,7 @@ class ODBC_API Preparator : public AbstractPreparator
/// - Value datatypes in this interface prepare() calls serve only for the purpose of type distinction.
/// - Preparator keeps its own std::vector<Any> buffer for fetched data to be later retrieved by Extractor.
/// - prepare() methods should not be called when extraction mode is DE_MANUAL
///
///
{
public:
typedef std::vector<char*> CharArray;
@@ -96,8 +96,8 @@ public:
DT_DATETIME
};
Preparator(const StatementHandle& rStmt,
const std::string& statement,
Preparator(const StatementHandle& rStmt,
const std::string& statement,
std::size_t maxFieldSize,
DataExtraction dataExtraction = DE_BOUND);
/// Creates the Preparator.
@@ -353,6 +353,9 @@ public:
void prepare(std::size_t pos, const std::list<Poco::DateTime>& val);
/// Prepares a DateTime list.
void prepare(std::size_t pos, const Poco::UUID& val);
/// Prepares a UUID.
void prepare(std::size_t pos, const Poco::Any& val);
/// Prepares an Any.
@@ -395,12 +398,12 @@ public:
std::size_t maxDataSize(std::size_t pos) const;
/// Returns max supported size for column at position pos.
/// Returned length for variable length fields is the one
/// Returned length for variable length fields is the one
/// supported by this implementation, not the underlying DB.
std::size_t actualDataSize(std::size_t col, std::size_t row = POCO_DATA_INVALID_ROW) const;
/// Returns the returned length for the column and row specified.
/// This is usually equal to the column size, except for
/// Returns the returned length for the column and row specified.
/// This is usually equal to the column size, except for
/// variable length fields (BLOB and variable length strings).
/// For null values, the return value is -1 (SQL_NO_DATA)
@@ -435,7 +438,7 @@ private:
if (pVal)
return prepareFixedSize<Poco::Int8>(pos, SQL_C_STINYINT, pVal->size());
else
return prepareFixedSize<Poco::Int8>(pos, SQL_C_STINYINT);
return prepareFixedSize<Poco::Int8>(pos, SQL_C_STINYINT);
case MetaColumn::FDT_UINT8:
if (pVal)
@@ -548,7 +551,13 @@ private:
else
return prepareFixedSize<DateTime>(pos, SQL_C_TYPE_TIMESTAMP);
default:
case MetaColumn::FDT_UUID:
if (pVal)
return prepareFixedSize<DateTime>(pos, SQL_C_BINARY, 16);
else
return prepareFixedSize<DateTime>(pos, SQL_C_BINARY);
default:
throw DataFormatException("Unsupported data type.");
}
}
@@ -567,11 +576,11 @@ private:
_values[pos] = Poco::Any(T());
T* pVal = AnyCast<T>(&_values[pos]);
if (Utility::isError(SQLBindCol(_rStmt,
(SQLUSMALLINT) pos + 1,
valueType,
(SQLPOINTER) pVal,
(SQLINTEGER) dataSize,
if (Utility::isError(SQLBindCol(_rStmt,
(SQLUSMALLINT) pos + 1,
valueType,
(SQLPOINTER) pVal,
(SQLINTEGER) dataSize,
&_lengths[pos])))
{
throw StatementException(_rStmt, "SQLBindCol()");
@@ -596,11 +605,11 @@ private:
std::vector<T>& cache = RefAnyCast<std::vector<T> >(_values[pos]);
cache.resize(length);
if (Utility::isError(SQLBindCol(_rStmt,
(SQLUSMALLINT) pos + 1,
valueType,
(SQLPOINTER) &cache[0],
(SQLINTEGER) dataSize,
if (Utility::isError(SQLBindCol(_rStmt,
(SQLUSMALLINT) pos + 1,
valueType,
(SQLPOINTER) &cache[0],
(SQLINTEGER) dataSize,
&_lenLengths[pos][0])))
{
throw StatementException(_rStmt, "SQLBindCol()");
@@ -614,18 +623,18 @@ private:
poco_assert (DE_BOUND == _dataExtraction);
poco_assert (pos < _values.size());
T* pCache = new T[size];
T* pCache = new T[size];
std::memset(pCache, 0, size);
_values[pos] = Any(pCache);
_lengths[pos] = (SQLLEN) size;
_varLengthArrays.insert(IndexMap::value_type(pos, dt));
if (Utility::isError(SQLBindCol(_rStmt,
(SQLUSMALLINT) pos + 1,
valueType,
(SQLPOINTER) pCache,
(SQLINTEGER) size*sizeof(T),
if (Utility::isError(SQLBindCol(_rStmt,
(SQLUSMALLINT) pos + 1,
valueType,
(SQLPOINTER) pCache,
(SQLINTEGER) size*sizeof(T),
&_lengths[pos])))
{
throw StatementException(_rStmt, "SQLBindCol()");
@@ -648,11 +657,11 @@ private:
_lenLengths[pos].resize(length);
_varLengthArrays.insert(IndexMap::value_type(pos, DT));
if (Utility::isError(SQLBindCol(_rStmt,
(SQLUSMALLINT) pos + 1,
valueType,
(SQLPOINTER) pArray,
(SQLINTEGER) size,
if (Utility::isError(SQLBindCol(_rStmt,
(SQLUSMALLINT) pos + 1,
valueType,
(SQLPOINTER) pArray,
(SQLINTEGER) size,
&_lenLengths[pos][0])))
{
throw StatementException(_rStmt, "SQLBindCol()");
@@ -1173,6 +1182,12 @@ inline void Preparator::prepare(std::size_t pos, const std::list<Poco::DateTime>
}
inline void Preparator::prepare(std::size_t pos, const Poco::UUID&)
{
prepareCharArray<char, DT_CHAR_ARRAY>(pos, SQL_C_BINARY, 16, 16);
}
inline void Preparator::prepare(std::size_t pos, const Poco::Any& val)
{
prepareImpl<std::vector<Poco::Any> >(pos);
@@ -25,6 +25,7 @@
#include "Poco/Data/ODBC/Handle.h"
#include "Poco/Data/ODBC/ODBCException.h"
#include "Poco/Data/AbstractSessionImpl.h"
#include "Poco/TextEncoding.h"
#include "Poco/SharedPtr.h"
#include "Poco/Mutex.h"
#ifdef POCO_OS_FAMILY_WINDOWS
@@ -162,6 +163,16 @@ public:
/// Returns the timeout (in seconds) for queries,
/// or -1 if no timeout has been set.
void setDBEncoding(const std::string&, const Poco::Any& value);
/// Sets the database encoding.
/// Value must be of type std::string.
Poco::Any getDBEncoding(const std::string&) const;
/// Returns the database encoding.
const std::string& dbEncoding() const;
/// Returns the database encoding.
const ConnectionHandle& dbc() const;
/// Returns the connection handle.
@@ -193,6 +204,7 @@ private:
mutable char _canTransact;
bool _inTransaction;
int _queryTimeout;
std::string _dbEncoding;
Poco::FastMutex _mutex;
};
@@ -291,6 +303,18 @@ inline int SessionImpl::queryTimeout() const
}
inline Poco::Any SessionImpl::getDBEncoding(const std::string&) const
{
return _dbEncoding;
}
inline const std::string& SessionImpl::dbEncoding() const
{
return _dbEncoding;
}
} } } // namespace Poco::Data::ODBC
@@ -47,7 +47,14 @@ inline void makeUTF8(Poco::Buffer<wchar_t>& buffer, SQLINTEGER length, SQLPOINTE
UnicodeConverter::toUTF8(buffer.begin(), length, result);
std::memset(pTarget, 0, targetLength);
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable:4996) // deprecation warnings
#endif
std::strncpy((char*) pTarget, result.c_str(), result.size() < targetLength ? result.size() : targetLength);
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
}