1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-08-08 09:01:48 +02:00

Update POCO to 1.11.0

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

View File

@@ -56,9 +56,6 @@ else ifeq (0, $(shell test -e $(POCO_ODBC_LIB)/libiodbc$(LIBLINKEXT); echo $$?))
SYSLIBS += -liodbc -liodbcinst
COMMONFLAGS += -DPOCO_IODBC -I/usr/include/iodbc
# TODO: OSX >= 10.8 deprecated non-Unicode ODBC API functions, silence warnings until iODBC Unicode support
COMMONFLAGS += -Wno-deprecated-declarations
else
$(error No ODBC library found. Please install unixODBC or iODBC or specify POCO_ODBC_LIB and try again)
endif

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;

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);
}

View File

@@ -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="");

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);

View File

@@ -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

View File

@@ -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
}

View File

@@ -80,6 +80,10 @@ void Binder::freeMemory()
UTF16CharPtrVec::iterator endUTF16Chr = _utf16CharPtrs.end();
for (; itUTF16Chr != endUTF16Chr; ++itUTF16Chr) std::free(*itUTF16Chr);
UUIDMap::iterator itUUID = _uuids.begin();
UUIDMap::iterator itUUIDEnd = _uuids.end();
for(; itUUID != itUUIDEnd; ++itUUID) std::free(itUUID->first);
BoolPtrVec::iterator itBool = _boolPtrs.begin();
BoolPtrVec::iterator endBool = _boolPtrs.end();
for (; itBool != endBool; ++itBool) delete [] *itBool;
@@ -129,15 +133,15 @@ void Binder::bind(std::size_t pos, const std::string& val, Direction dir)
_lengthIndicator.push_back(pLenIn);
if (Utility::isError(SQLBindParameter(_rStmt,
(SQLUSMALLINT) pos + 1,
toODBCDirection(dir),
SQL_C_CHAR,
Connector::stringBoundToLongVarChar() ? SQL_LONGVARCHAR : SQL_VARCHAR,
if (Utility::isError(SQLBindParameter(_rStmt,
(SQLUSMALLINT) pos + 1,
toODBCDirection(dir),
SQL_C_CHAR,
Connector::stringBoundToLongVarChar() ? SQL_LONGVARCHAR : SQL_VARCHAR,
(SQLUINTEGER) colSize,
0,
pVal,
(SQLINTEGER) size,
pVal,
(SQLINTEGER) size,
_lengthIndicator.back())))
{
throw StatementException(_rStmt, "SQLBindParameter(std::string)");
@@ -206,22 +210,22 @@ void Binder::bind(std::size_t pos, const Date& val, Direction dir)
SQL_DATE_STRUCT* pDS = new SQL_DATE_STRUCT;
Utility::dateSync(*pDS, val);
_dates.insert(DateMap::value_type(pDS, const_cast<Date*>(&val)));
SQLINTEGER colSize = 0;
SQLSMALLINT decDigits = 0;
getColSizeAndPrecision(pos, SQL_TYPE_DATE, colSize, decDigits);
if (Utility::isError(SQLBindParameter(_rStmt,
(SQLUSMALLINT) pos + 1,
toODBCDirection(dir),
SQL_C_TYPE_DATE,
SQL_TYPE_DATE,
if (Utility::isError(SQLBindParameter(_rStmt,
(SQLUSMALLINT) pos + 1,
toODBCDirection(dir),
SQL_C_TYPE_DATE,
SQL_TYPE_DATE,
colSize,
decDigits,
(SQLPOINTER) pDS,
0,
(SQLPOINTER) pDS,
0,
_lengthIndicator.back())))
{
throw StatementException(_rStmt, "SQLBindParameter(Date)");
@@ -239,22 +243,22 @@ void Binder::bind(std::size_t pos, const Time& val, Direction dir)
SQL_TIME_STRUCT* pTS = new SQL_TIME_STRUCT;
Utility::timeSync(*pTS, val);
_times.insert(TimeMap::value_type(pTS, const_cast<Time*>(&val)));
SQLINTEGER colSize = 0;
SQLSMALLINT decDigits = 0;
getColSizeAndPrecision(pos, SQL_TYPE_TIME, colSize, decDigits);
if (Utility::isError(SQLBindParameter(_rStmt,
(SQLUSMALLINT) pos + 1,
toODBCDirection(dir),
SQL_C_TYPE_TIME,
SQL_TYPE_TIME,
if (Utility::isError(SQLBindParameter(_rStmt,
(SQLUSMALLINT) pos + 1,
toODBCDirection(dir),
SQL_C_TYPE_TIME,
SQL_TYPE_TIME,
colSize,
decDigits,
(SQLPOINTER) pTS,
0,
(SQLPOINTER) pTS,
0,
_lengthIndicator.back())))
{
throw StatementException(_rStmt, "SQLBindParameter(Time)");
@@ -279,15 +283,15 @@ void Binder::bind(std::size_t pos, const Poco::DateTime& val, Direction dir)
SQLSMALLINT decDigits = 0;
getColSizeAndPrecision(pos, SQL_TYPE_TIMESTAMP, colSize, decDigits);
if (Utility::isError(SQLBindParameter(_rStmt,
(SQLUSMALLINT) pos + 1,
toODBCDirection(dir),
SQL_C_TYPE_TIMESTAMP,
SQL_TYPE_TIMESTAMP,
if (Utility::isError(SQLBindParameter(_rStmt,
(SQLUSMALLINT) pos + 1,
toODBCDirection(dir),
SQL_C_TYPE_TIMESTAMP,
SQL_TYPE_TIMESTAMP,
colSize,
decDigits,
(SQLPOINTER) pTS,
0,
(SQLPOINTER) pTS,
0,
_lengthIndicator.back())))
{
throw StatementException(_rStmt, "SQLBindParameter(DateTime)");
@@ -295,6 +299,38 @@ void Binder::bind(std::size_t pos, const Poco::DateTime& val, Direction dir)
}
void Binder::bind(std::size_t pos, const UUID& val, Direction dir)
{
SQLINTEGER size = (SQLINTEGER) 16;
SQLLEN* pLenIn = new SQLLEN;
*pLenIn = size;
_lengthIndicator.push_back(pLenIn);
char* pUUID = new char[16];
val.copyTo(pUUID);
_uuids.insert(UUIDMap::value_type(pUUID, const_cast<UUID*>(&val)));
SQLINTEGER colSize = 0;
SQLSMALLINT decDigits = 0;
if (Utility::isError(SQLBindParameter(_rStmt,
(SQLUSMALLINT) pos + 1,
toODBCDirection(dir),
SQL_C_BINARY,
SQL_GUID,
colSize,
decDigits,
(SQLPOINTER) pUUID,
0,
_lengthIndicator.back())))
{
throw StatementException(_rStmt, "SQLBindParameter(UUID)");
}
}
void Binder::bind(std::size_t pos, const NullData& val, Direction dir)
{
if (isOutBound(dir) || !isInBound(dir))
@@ -311,15 +347,15 @@ void Binder::bind(std::size_t pos, const NullData& val, Direction dir)
SQLSMALLINT decDigits = 0;
getColSizeAndPrecision(pos, SQL_C_STINYINT, colSize, decDigits);
if (Utility::isError(SQLBindParameter(_rStmt,
(SQLUSMALLINT) pos + 1,
SQL_PARAM_INPUT,
SQL_C_STINYINT,
Utility::sqlDataType(SQL_C_STINYINT),
if (Utility::isError(SQLBindParameter(_rStmt,
(SQLUSMALLINT) pos + 1,
SQL_PARAM_INPUT,
SQL_C_STINYINT,
Utility::sqlDataType(SQL_C_STINYINT),
colSize,
decDigits,
0,
0,
0,
0,
_lengthIndicator.back())))
{
throw StatementException(_rStmt, "SQLBindParameter()");
@@ -334,7 +370,7 @@ std::size_t Binder::parameterSize(SQLPOINTER pAddr) const
it = _outParams.find(pAddr);
if (it != _outParams.end()) return it->second;
throw NotFoundException("Requested data size not found.");
}
@@ -350,7 +386,7 @@ SQLSMALLINT Binder::toODBCDirection(Direction dir) const
bool in = isInBound(dir);
bool out = isOutBound(dir);
SQLSMALLINT ioType = SQL_PARAM_TYPE_UNKNOWN;
if (in && out) ioType = SQL_PARAM_INPUT_OUTPUT;
if (in && out) ioType = SQL_PARAM_INPUT_OUTPUT;
else if(in) ioType = SQL_PARAM_INPUT;
else if(out) ioType = SQL_PARAM_OUTPUT;
else throw Poco::IllegalStateException("Binder not bound (must be [in] OR [out]).");
@@ -365,7 +401,7 @@ void Binder::synchronize()
{
DateMap::iterator it = _dates.begin();
DateMap::iterator end = _dates.end();
for(; it != end; ++it)
for(; it != end; ++it)
Utility::dateSync(*it->second, *it->first);
}
@@ -373,7 +409,7 @@ void Binder::synchronize()
{
TimeMap::iterator it = _times.begin();
TimeMap::iterator end = _times.end();
for(; it != end; ++it)
for(; it != end; ++it)
Utility::timeSync(*it->second, *it->first);
}
@@ -381,7 +417,7 @@ void Binder::synchronize()
{
TimestampMap::iterator it = _timestamps.begin();
TimestampMap::iterator end = _timestamps.end();
for(; it != end; ++it)
for(; it != end; ++it)
Utility::dateTimeSync(*it->second, *it->first);
}
@@ -392,6 +428,14 @@ void Binder::synchronize()
for(; it != end; ++it)
it->second->assign(it->first, std::strlen(it->first));
}
if (_uuids.size())
{
UUIDMap::iterator it = _uuids.begin();
UUIDMap::iterator end = _uuids.end();
for(; it != end; ++it)
it->second->copyFrom(it->first);
}
}
@@ -405,6 +449,7 @@ void Binder::reset()
_times.clear();
_timestamps.clear();
_strings.clear();
_uuids.clear();
_dateVecVec.clear();
_timeVecVec.clear();
_dateTimeVecVec.clear();
@@ -415,9 +460,9 @@ void Binder::reset()
}
void Binder::getColSizeAndPrecision(std::size_t pos,
SQLSMALLINT cDataType,
SQLINTEGER& colSize,
void Binder::getColSizeAndPrecision(std::size_t pos,
SQLSMALLINT cDataType,
SQLINTEGER& colSize,
SQLSMALLINT& decDigits,
std::size_t actualSize)
{
@@ -448,9 +493,9 @@ void Binder::getColSizeAndPrecision(std::size_t pos,
colSize = (SQLINTEGER) p.columnSize();
decDigits = (SQLSMALLINT) p.decimalDigits();
return;
}
}
catch (StatementException&)
{
{
}
try
@@ -459,9 +504,9 @@ void Binder::getColSizeAndPrecision(std::size_t pos,
colSize = (SQLINTEGER) c.length();
decDigits = (SQLSMALLINT) c.precision();
return;
}
catch (StatementException&)
{
}
catch (StatementException&)
{
}
// last check, just in case
@@ -505,7 +550,7 @@ void Binder::getColumnOrParameterSize(std::size_t pos, SQLINTEGER& size)
if (!Utility::isError(SQLGetStmtAttr(_rStmt, SQL_ATTR_IMP_PARAM_DESC, &hIPD, SQL_IS_POINTER, 0)))
{
SQLUINTEGER sz = 0;
if (!Utility::isError(SQLGetDescField(hIPD, (SQLSMALLINT) pos + 1, SQL_DESC_LENGTH, &sz, SQL_IS_UINTEGER, 0)) &&
if (!Utility::isError(SQLGetDescField(hIPD, (SQLSMALLINT) pos + 1, SQL_DESC_LENGTH, &sz, SQL_IS_UINTEGER, 0)) &&
sz > 0)
{
size = sz;
@@ -529,7 +574,7 @@ void Binder::setParamSetSize(std::size_t length)
{
if (0 == _paramSetSize)
{
if (Utility::isError(Poco::Data::ODBC::SQLSetStmtAttr(_rStmt, SQL_ATTR_PARAM_BIND_TYPE, SQL_PARAM_BIND_BY_COLUMN, SQL_IS_UINTEGER)) ||
if (Utility::isError(Poco::Data::ODBC::SQLSetStmtAttr(_rStmt, SQL_ATTR_PARAM_BIND_TYPE, SQL_PARAM_BIND_BY_COLUMN, SQL_IS_UINTEGER)) ||
Utility::isError(Poco::Data::ODBC::SQLSetStmtAttr(_rStmt, SQL_ATTR_PARAMSET_SIZE, (SQLPOINTER) length, SQL_IS_UINTEGER)))
throw StatementException(_rStmt, "SQLSetStmtAttr()");

View File

@@ -12,13 +12,13 @@
//
#include "Poco/Data/ODBC/ODBC.h"
#include "Poco/Data/ODBC/Extractor.h"
#include "Poco/Data/ODBC/ODBCMetaColumn.h"
#include "Poco/Data/ODBC/Utility.h"
#include "Poco/Data/ODBC/ODBCException.h"
#include "Poco/Data/LOB.h"
#include "Poco/Buffer.h"
#include "Poco/Exception.h"
#include <typeinfo>
@@ -33,11 +33,15 @@ const std::string Extractor::FLD_SIZE_EXCEEDED_FMT = "Specified data size (%z by
"to increase the maximum allowed data size\n";
Extractor::Extractor(const StatementHandle& rStmt,
Preparator::Ptr pPreparator):
_rStmt(rStmt),
Extractor::Extractor(const StatementHandle& rStmt,
Preparator::Ptr pPreparator,
TextEncoding::Ptr pDBEncoding):
_rStmt(rStmt),
_pPreparator(pPreparator),
_dataExtraction(pPreparator->getDataExtraction())
_dataExtraction(pPreparator->getDataExtraction()),
_pDBEncoding(pDBEncoding),
_transcode(_pDBEncoding && !_pDBEncoding->isA("UTF-8")),
_pToEncoding(_transcode ? Poco::TextEncoding::find("UTF-8") : nullptr)
{
}
@@ -106,7 +110,7 @@ bool Extractor::extractBoundImpl<Poco::Data::Date>(std::size_t pos, Poco::Data::
template<>
bool Extractor::extractBoundImplContainer<std::vector<Poco::Data::Date> >(std::size_t pos,
bool Extractor::extractBoundImplContainer<std::vector<Poco::Data::Date> >(std::size_t pos,
std::vector<Poco::Data::Date>& val)
{
std::vector<SQL_DATE_STRUCT>& ds = RefAnyCast<std::vector<SQL_DATE_STRUCT> >(_pPreparator->at(pos));
@@ -116,7 +120,7 @@ bool Extractor::extractBoundImplContainer<std::vector<Poco::Data::Date> >(std::s
template<>
bool Extractor::extractBoundImplContainer<std::deque<Poco::Data::Date> >(std::size_t pos,
bool Extractor::extractBoundImplContainer<std::deque<Poco::Data::Date> >(std::size_t pos,
std::deque<Poco::Data::Date>& val)
{
std::vector<SQL_DATE_STRUCT>& ds = RefAnyCast<std::vector<SQL_DATE_STRUCT> >(_pPreparator->at(pos));
@@ -126,7 +130,7 @@ bool Extractor::extractBoundImplContainer<std::deque<Poco::Data::Date> >(std::si
template<>
bool Extractor::extractBoundImplContainer<std::list<Poco::Data::Date> >(std::size_t pos,
bool Extractor::extractBoundImplContainer<std::list<Poco::Data::Date> >(std::size_t pos,
std::list<Poco::Data::Date>& val)
{
std::vector<SQL_DATE_STRUCT>& ds = RefAnyCast<std::vector<SQL_DATE_STRUCT> >(_pPreparator->at(pos));
@@ -150,7 +154,7 @@ bool Extractor::extractBoundImpl<Poco::Data::Time>(std::size_t pos, Poco::Data::
template<>
bool Extractor::extractBoundImplContainer<std::vector<Poco::Data::Time> >(std::size_t pos,
bool Extractor::extractBoundImplContainer<std::vector<Poco::Data::Time> >(std::size_t pos,
std::vector<Poco::Data::Time>& val)
{
std::vector<SQL_TIME_STRUCT>& ds = RefAnyCast<std::vector<SQL_TIME_STRUCT> >(_pPreparator->at(pos));
@@ -160,7 +164,7 @@ bool Extractor::extractBoundImplContainer<std::vector<Poco::Data::Time> >(std::s
template<>
bool Extractor::extractBoundImplContainer<std::deque<Poco::Data::Time> >(std::size_t pos,
bool Extractor::extractBoundImplContainer<std::deque<Poco::Data::Time> >(std::size_t pos,
std::deque<Poco::Data::Time>& val)
{
std::vector<SQL_TIME_STRUCT>& ds = RefAnyCast<std::vector<SQL_TIME_STRUCT> >(_pPreparator->at(pos));
@@ -170,7 +174,7 @@ bool Extractor::extractBoundImplContainer<std::deque<Poco::Data::Time> >(std::si
template<>
bool Extractor::extractBoundImplContainer<std::list<Poco::Data::Time> >(std::size_t pos,
bool Extractor::extractBoundImplContainer<std::list<Poco::Data::Time> >(std::size_t pos,
std::list<Poco::Data::Time>& val)
{
std::vector<SQL_TIME_STRUCT>& ds = RefAnyCast<std::vector<SQL_TIME_STRUCT> >(_pPreparator->at(pos));
@@ -194,7 +198,7 @@ bool Extractor::extractBoundImpl<Poco::DateTime>(std::size_t pos, Poco::DateTime
template<>
bool Extractor::extractBoundImplContainer<std::vector<Poco::DateTime> >(std::size_t pos,
bool Extractor::extractBoundImplContainer<std::vector<Poco::DateTime> >(std::size_t pos,
std::vector<Poco::DateTime>& val)
{
std::vector<SQL_TIMESTAMP_STRUCT>& ds = RefAnyCast<std::vector<SQL_TIMESTAMP_STRUCT> >(_pPreparator->at(pos));
@@ -204,7 +208,7 @@ bool Extractor::extractBoundImplContainer<std::vector<Poco::DateTime> >(std::siz
template<>
bool Extractor::extractBoundImplContainer<std::deque<Poco::DateTime> >(std::size_t pos,
bool Extractor::extractBoundImplContainer<std::deque<Poco::DateTime> >(std::size_t pos,
std::deque<Poco::DateTime>& val)
{
std::vector<SQL_TIMESTAMP_STRUCT>& ds = RefAnyCast<std::vector<SQL_TIMESTAMP_STRUCT> >(_pPreparator->at(pos));
@@ -214,7 +218,7 @@ bool Extractor::extractBoundImplContainer<std::deque<Poco::DateTime> >(std::size
template<>
bool Extractor::extractBoundImplContainer<std::list<Poco::DateTime> >(std::size_t pos,
bool Extractor::extractBoundImplContainer<std::list<Poco::DateTime> >(std::size_t pos,
std::list<Poco::DateTime>& val)
{
std::vector<SQL_TIMESTAMP_STRUCT>& ds = RefAnyCast<std::vector<SQL_TIMESTAMP_STRUCT> >(_pPreparator->at(pos));
@@ -224,7 +228,21 @@ bool Extractor::extractBoundImplContainer<std::list<Poco::DateTime> >(std::size_
template<>
bool Extractor::extractBoundImplContainer<std::vector<bool> >(std::size_t pos,
bool Extractor::extractBoundImpl<Poco::UUID>(std::size_t pos, Poco::UUID& val)
{
if (isNull(pos)) return false;
std::size_t dataSize = _pPreparator->actualDataSize(pos);
checkDataSize(dataSize);
char* pBuffer = *AnyCast<char*>(&_pPreparator->at(pos));
val.copyFrom(pBuffer);
return true;
}
template<>
bool Extractor::extractBoundImplContainer<std::vector<bool> >(std::size_t pos,
std::vector<bool>& val)
{
std::size_t length = _pPreparator->getLength();
@@ -235,7 +253,7 @@ bool Extractor::extractBoundImplContainer<std::vector<bool> >(std::size_t pos,
template<>
bool Extractor::extractBoundImplContainer<std::deque<bool> >(std::size_t pos,
bool Extractor::extractBoundImplContainer<std::deque<bool> >(std::size_t pos,
std::deque<bool>& val)
{
std::size_t length = _pPreparator->getLength();
@@ -246,7 +264,7 @@ bool Extractor::extractBoundImplContainer<std::deque<bool> >(std::size_t pos,
template<>
bool Extractor::extractBoundImplContainer<std::list<bool> >(std::size_t pos,
bool Extractor::extractBoundImplContainer<std::list<bool> >(std::size_t pos,
std::list<bool>& val)
{
std::size_t length = _pPreparator->getLength();
@@ -262,13 +280,13 @@ bool Extractor::extractManualImpl<std::string>(std::size_t pos, std::string& val
std::size_t maxSize = _pPreparator->getMaxFieldSize();
std::size_t fetchedSize = 0;
std::size_t totalSize = 0;
SQLLEN len;
const int bufSize = CHUNK_SIZE;
Poco::Buffer<char> apChar(bufSize);
char* pChar = apChar.begin();
SQLRETURN rc = 0;
val.clear();
resizeLengths(pos);
@@ -276,8 +294,8 @@ bool Extractor::extractManualImpl<std::string>(std::size_t pos, std::string& val
{
std::memset(pChar, 0, bufSize);
len = 0;
rc = SQLGetData(_rStmt,
(SQLUSMALLINT) pos + 1,
rc = SQLGetData(_rStmt,
(SQLUSMALLINT) pos + 1,
cType, //C data type
pChar, //returned value
bufSize, //buffer length
@@ -301,9 +319,9 @@ bool Extractor::extractManualImpl<std::string>(std::size_t pos, std::string& val
_lengths[pos] += len;
fetchedSize = _lengths[pos] > CHUNK_SIZE ? CHUNK_SIZE : _lengths[pos];
totalSize += fetchedSize;
if (totalSize <= maxSize)
if (totalSize <= maxSize)
val.append(pChar, fetchedSize);
else
else
throw DataException(format(FLD_SIZE_EXCEEDED_FMT, fetchedSize, maxSize));
}while (true);
@@ -367,8 +385,8 @@ bool Extractor::extractManualImpl<UTF16String>(std::size_t pos, UTF16String& val
template<>
bool Extractor::extractManualImpl<Poco::Data::CLOB>(std::size_t pos,
Poco::Data::CLOB& val,
bool Extractor::extractManualImpl<Poco::Data::CLOB>(std::size_t pos,
Poco::Data::CLOB& val,
SQLSMALLINT cType)
{
std::size_t maxSize = _pPreparator->getMaxFieldSize();
@@ -380,7 +398,7 @@ bool Extractor::extractManualImpl<Poco::Data::CLOB>(std::size_t pos,
Poco::Buffer<char> apChar(bufSize);
char* pChar = apChar.begin();
SQLRETURN rc = 0;
val.clear();
resizeLengths(pos);
@@ -388,13 +406,13 @@ bool Extractor::extractManualImpl<Poco::Data::CLOB>(std::size_t pos,
{
std::memset(pChar, 0, bufSize);
len = 0;
rc = SQLGetData(_rStmt,
(SQLUSMALLINT) pos + 1,
rc = SQLGetData(_rStmt,
(SQLUSMALLINT) pos + 1,
cType, //C data type
pChar, //returned value
bufSize, //buffer length
&len); //length indicator
_lengths[pos] += len;
if (SQL_NO_DATA != rc && Utility::isError(rc))
@@ -411,9 +429,9 @@ bool Extractor::extractManualImpl<Poco::Data::CLOB>(std::size_t pos,
fetchedSize = len > CHUNK_SIZE ? CHUNK_SIZE : len;
totalSize += fetchedSize;
if (totalSize <= maxSize)
if (totalSize <= maxSize)
val.appendRaw(pChar, fetchedSize);
else
else
throw DataException(format(FLD_SIZE_EXCEEDED_FMT, fetchedSize, maxSize));
}while (true);
@@ -423,26 +441,26 @@ bool Extractor::extractManualImpl<Poco::Data::CLOB>(std::size_t pos,
template<>
bool Extractor::extractManualImpl<Poco::Data::Date>(std::size_t pos,
Poco::Data::Date& val,
bool Extractor::extractManualImpl<Poco::Data::Date>(std::size_t pos,
Poco::Data::Date& val,
SQLSMALLINT cType)
{
SQL_DATE_STRUCT ds;
resizeLengths(pos);
SQLRETURN rc = SQLGetData(_rStmt,
(SQLUSMALLINT) pos + 1,
SQLRETURN rc = SQLGetData(_rStmt,
(SQLUSMALLINT) pos + 1,
cType, //C data type
&ds, //returned value
sizeof(ds), //buffer length
&_lengths[pos]); //length indicator
if (Utility::isError(rc))
throw StatementException(_rStmt, "SQLGetData()");
if (isNullLengthIndicator(_lengths[pos]))
if (isNullLengthIndicator(_lengths[pos]))
return false;
else
else
Utility::dateSync(val, ds);
return true;
@@ -450,26 +468,26 @@ bool Extractor::extractManualImpl<Poco::Data::Date>(std::size_t pos,
template<>
bool Extractor::extractManualImpl<Poco::Data::Time>(std::size_t pos,
Poco::Data::Time& val,
bool Extractor::extractManualImpl<Poco::Data::Time>(std::size_t pos,
Poco::Data::Time& val,
SQLSMALLINT cType)
{
SQL_TIME_STRUCT ts;
resizeLengths(pos);
SQLRETURN rc = SQLGetData(_rStmt,
(SQLUSMALLINT) pos + 1,
SQLRETURN rc = SQLGetData(_rStmt,
(SQLUSMALLINT) pos + 1,
cType, //C data type
&ts, //returned value
sizeof(ts), //buffer length
&_lengths[pos]); //length indicator
if (Utility::isError(rc))
throw StatementException(_rStmt, "SQLGetData()");
if (isNullLengthIndicator(_lengths[pos]))
if (isNullLengthIndicator(_lengths[pos]))
return false;
else
else
Utility::timeSync(val, ts);
return true;
@@ -477,32 +495,59 @@ bool Extractor::extractManualImpl<Poco::Data::Time>(std::size_t pos,
template<>
bool Extractor::extractManualImpl<Poco::DateTime>(std::size_t pos,
Poco::DateTime& val,
bool Extractor::extractManualImpl<Poco::DateTime>(std::size_t pos,
Poco::DateTime& val,
SQLSMALLINT cType)
{
SQL_TIMESTAMP_STRUCT ts;
resizeLengths(pos);
SQLRETURN rc = SQLGetData(_rStmt,
(SQLUSMALLINT) pos + 1,
SQLRETURN rc = SQLGetData(_rStmt,
(SQLUSMALLINT) pos + 1,
cType, //C data type
&ts, //returned value
sizeof(ts), //buffer length
&_lengths[pos]); //length indicator
if (Utility::isError(rc))
throw StatementException(_rStmt, "SQLGetData()");
if (isNullLengthIndicator(_lengths[pos]))
if (isNullLengthIndicator(_lengths[pos]))
return false;
else
else
Utility::dateTimeSync(val, ts);
return true;
}
template<>
bool Extractor::extractManualImpl<Poco::UUID>(std::size_t pos,
Poco::UUID& val,
SQLSMALLINT cType)
{
char buffer[16];
resizeLengths(pos);
SQLRETURN rc = SQLGetData(_rStmt,
(SQLUSMALLINT) pos + 1,
cType, //C data type
&buffer, //returned value
sizeof(buffer), //buffer length
&_lengths[pos]); //length indicator
if (Utility::isError(rc))
throw StatementException(_rStmt, "SQLGetData()");
if (isNullLengthIndicator(_lengths[pos]))
return false;
else
val.copyFrom(buffer);
return true;
}
bool Extractor::extract(std::size_t pos, Poco::Int32& val)
{
if (Preparator::DE_MANUAL == _dataExtraction)
@@ -660,37 +705,45 @@ bool Extractor::extract(std::size_t pos, std::list<double>& val)
bool Extractor::extract(std::size_t pos, std::string& val)
{
if (Preparator::DE_MANUAL == _dataExtraction)
return extractManualImpl(pos, val, SQL_C_CHAR);
bool ret = false;
if (!_transcode)
{
if (Preparator::DE_MANUAL == _dataExtraction)
ret = extractManualImpl(pos, val, SQL_C_CHAR);
else
ret = extractBoundImpl(pos, val);
}
else
return extractBoundImpl(pos, val);
{
std::string result;
if (Preparator::DE_MANUAL == _dataExtraction)
ret = extractManualImpl(pos, result, SQL_C_CHAR);
else
ret = extractBoundImpl(pos, result);
Poco::TextConverter converter(*_pDBEncoding, *_pToEncoding);
converter.convert(result, val);
}
return ret;
}
bool Extractor::extract(std::size_t pos, std::vector<std::string>& val)
{
if (Preparator::DE_BOUND == _dataExtraction)
return extractBoundImplContainer(pos, val);
else
throw InvalidAccessException("Direct container extraction only allowed for bound mode.");
return stringContainerExtract(pos, val);
}
bool Extractor::extract(std::size_t pos, std::deque<std::string>& val)
{
if (Preparator::DE_BOUND == _dataExtraction)
return extractBoundImplContainer(pos, val);
else
throw InvalidAccessException("Direct container extraction only allowed for bound mode.");
return stringContainerExtract(pos, val);
}
bool Extractor::extract(std::size_t pos, std::list<std::string>& val)
{
if (Preparator::DE_BOUND == _dataExtraction)
return extractBoundImplContainer(pos, val);
else
throw InvalidAccessException("Direct container extraction only allowed for bound mode.");
return stringContainerExtract(pos, val);
}
@@ -910,6 +963,15 @@ bool Extractor::extract(std::size_t pos, std::list<Poco::DateTime>& val)
}
bool Extractor::extract(std::size_t pos, Poco::UUID& val)
{
if (Preparator::DE_MANUAL == _dataExtraction)
return extractManualImpl(pos, val, SQL_C_BINARY);
else
return extractBoundImpl(pos, val);
}
bool Extractor::extract(std::size_t pos, Poco::Int8& val)
{
if (Preparator::DE_MANUAL == _dataExtraction)
@@ -1307,10 +1369,10 @@ bool Extractor::isNull(std::size_t col, std::size_t row)
try
{
return isNullLengthIndicator(_lengths.at(col));
}
}
catch (std::out_of_range& ex)
{
throw RangeException(ex.what());
throw RangeException(ex.what());
}
}
else

View File

@@ -102,9 +102,6 @@ void ODBCMetaColumn::init()
case SQL_CHAR:
case SQL_VARCHAR:
case SQL_LONGVARCHAR:
#ifdef SQL_GUID
case SQL_GUID:
#endif
setType(MetaColumn::FDT_STRING); break;
case SQL_WCHAR:
@@ -168,6 +165,9 @@ void ODBCMetaColumn::init()
case SQL_TYPE_TIMESTAMP:
setType(MetaColumn::FDT_TIMESTAMP); break;
case SQL_GUID:
setType(MetaColumn::FDT_UUID); break;
default:
throw DataFormatException("Unsupported data type.");
}

View File

@@ -145,7 +145,8 @@ void ODBCStatementImpl::addPreparator()
else
_preparations.push_back(new Preparator(*_preparations[0]));
_extractors.push_back(new Extractor(_stmt, _preparations.back()));
_extractors.push_back(new Extractor(_stmt, _preparations.back(),
TextEncoding::find(Poco::RefAnyCast<std::string>(session().getProperty("dbEncoding")))));
}

View File

@@ -25,10 +25,10 @@ namespace Data {
namespace ODBC {
Preparator::Preparator(const StatementHandle& rStmt,
const std::string& statement,
Preparator::Preparator(const StatementHandle& rStmt,
const std::string& statement,
std::size_t maxFieldSize,
DataExtraction dataExtraction):
DataExtraction dataExtraction):
_rStmt(rStmt),
_maxFieldSize(maxFieldSize),
_dataExtraction(dataExtraction)
@@ -39,7 +39,7 @@ Preparator::Preparator(const StatementHandle& rStmt,
}
Preparator::Preparator(const Preparator& other):
Preparator::Preparator(const Preparator& other):
_rStmt(other._rStmt),
_maxFieldSize(other._maxFieldSize),
_dataExtraction(other._dataExtraction)
@@ -151,14 +151,14 @@ std::size_t Preparator::maxDataSize(std::size_t pos) const
std::size_t sz = 0;
std::size_t maxsz = getMaxFieldSize();
try
try
{
ODBCMetaColumn mc(_rStmt, pos);
sz = mc.length();
// accomodate for terminating zero (non-bulk only!)
MetaColumn::ColumnDataType type = mc.type();
if (!isBulk() && ((ODBCMetaColumn::FDT_WSTRING == type) || (ODBCMetaColumn::FDT_STRING == type))) ++sz;
if (sz && !isBulk() && ((ODBCMetaColumn::FDT_WSTRING == type) || (ODBCMetaColumn::FDT_STRING == type))) ++sz;
}
catch (StatementException&) { }
@@ -194,11 +194,11 @@ void Preparator::prepareBoolArray(std::size_t pos, SQLSMALLINT valueType, std::s
_lenLengths[pos].resize(length);
_varLengthArrays.insert(IndexMap::value_type(pos, DT_BOOL_ARRAY));
if (Utility::isError(SQLBindCol(_rStmt,
(SQLUSMALLINT) pos + 1,
valueType,
(SQLPOINTER) pArray,
(SQLINTEGER) sizeof(bool),
if (Utility::isError(SQLBindCol(_rStmt,
(SQLUSMALLINT) pos + 1,
valueType,
(SQLPOINTER) pArray,
(SQLINTEGER) sizeof(bool),
&_lenLengths[pos][0])))
{
throw StatementException(_rStmt, "SQLBindCol()");

View File

@@ -39,7 +39,8 @@ SessionImpl::SessionImpl(const std::string& connect,
_autoExtract(autoExtract),
_canTransact(ODBC_TXN_CAPABILITY_UNKNOWN),
_inTransaction(false),
_queryTimeout(-1)
_queryTimeout(-1),
_dbEncoding("UTF-8")
{
setFeature("bulk", true);
open();
@@ -58,7 +59,8 @@ SessionImpl::SessionImpl(const std::string& connect,
_autoExtract(autoExtract),
_canTransact(ODBC_TXN_CAPABILITY_UNKNOWN),
_inTransaction(false),
_queryTimeout(-1)
_queryTimeout(-1),
_dbEncoding("UTF-8")
{
setFeature("bulk", true);
open();
@@ -158,12 +160,24 @@ void SessionImpl::open(const std::string& connect)
&SessionImpl::setQueryTimeout,
&SessionImpl::getQueryTimeout);
addProperty("dbEncoding",
&SessionImpl::setDBEncoding,
&SessionImpl::getDBEncoding);
Poco::Data::ODBC::SQLSetConnectAttr(_db, SQL_ATTR_QUIET_MODE, 0, 0);
if (!canTransact()) autoCommit("", true);
}
void SessionImpl::setDBEncoding(const std::string&, const Poco::Any& value)
{
const std::string& enc = Poco::RefAnyCast<std::string>(value);
Poco::TextEncoding::byName(enc); // throws if not found
_dbEncoding = enc;
}
bool SessionImpl::isConnected() const
{
SQLULEN value = 0;

View File

@@ -612,6 +612,15 @@ void ODBCSQLServerTest::recreateFloatsTable()
}
void ODBCSQLServerTest::recreateUUIDsTable()
{
dropObject("TABLE", "Strings");
try { session() << "CREATE TABLE Strings (str UNIQUEIDENTIFIER)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateUUIDsTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateUUIDsTable()"); }
}
void ODBCSQLServerTest::recreateTuplesTable()
{
dropObject("TABLE", "Tuples");
@@ -787,6 +796,7 @@ CppUnit::Test* ODBCSQLServerTest::suite()
CppUnit_addTest(pSuite, ODBCSQLServerTest, testDateTime);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testFloat);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testDouble);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testUUID);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testTuple);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testTupleVector);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testStoredProcedure);

View File

@@ -64,6 +64,7 @@ private:
void recreateStringsTable();
void recreateIntsTable();
void recreateFloatsTable();
void recreateUUIDsTable();
void recreateTuplesTable();
void recreateVectorTable();
void recreateVectorsTable();

View File

@@ -917,6 +917,21 @@ void ODBCTest::testDouble()
}
void ODBCTest::testUUID()
{
if (!_pSession) fail ("Test not available.");
for (int i = 0; i < 8;)
{
recreateUUIDsTable();
_pSession->setFeature("autoBind", bindValue(i));
_pSession->setFeature("autoExtract", bindValue(i+1));
_pExecutor->uuids();
i += 2;
}
}
void ODBCTest::testTuple()
{
if (!_pSession) fail ("Test not available.");

View File

@@ -113,6 +113,8 @@ public:
virtual void testFloat();
virtual void testDouble();
virtual void testUUID();
virtual void testTuple();
virtual void testTupleVector();
@@ -166,6 +168,7 @@ protected:
virtual void recreateStringsTable();
virtual void recreateIntsTable();
virtual void recreateFloatsTable();
virtual void recreateUUIDsTable();
virtual void recreateTuplesTable();
virtual void recreateVectorsTable();
virtual void recreateAnysTable();
@@ -317,6 +320,12 @@ inline void ODBCTest::recreateFloatsTable()
}
inline void ODBCTest::recreateUUIDsTable()
{
throw Poco::NotImplementedException("ODBCTest::recreateUUIDsTable()");
}
inline void ODBCTest::recreateTuplesTable()
{
throw Poco::NotImplementedException("ODBCTest::recreateTuplesTable()");

View File

@@ -1540,6 +1540,29 @@ void SQLExecutor::doubles()
}
void SQLExecutor::uuids()
{
std::string funct = "uuids()";
Poco::UUID data("49cf6461-9b62-4163-9659-5472ef73153d");
Poco::UUID ret;
try { session() << "INSERT INTO Strings VALUES (?)", use(data), now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (funct); }
int count = 0;
try { session() << "SELECT COUNT(*) FROM Strings", into(count), now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (funct); }
assertTrue (count == 1);
try { session() << "SELECT str FROM Strings", into(ret), now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (funct); }
assertTrue (ret == data);
}
void SQLExecutor::insertSingleBulkVec()
{
std::string funct = "insertSingleBulkVec()";

View File

@@ -469,6 +469,7 @@ public:
void time();
void floats();
void doubles();
void uuids();
void tuples();
void tupleVector();