Skip to content

Commit

Permalink
Poco::Data ODBC impl doesn't bind to unsigned numeric types properly #…
Browse files Browse the repository at this point in the history
  • Loading branch information
aleks-f committed Oct 21, 2017
1 parent 4cc043e commit 3fb4c34
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
3 changes: 3 additions & 0 deletions Data/ODBC/include/Poco/Data/ODBC/ODBCMetaColumn.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class ODBC_API ODBCMetaColumn: public MetaColumn
/// null-termination byte that ends the character string.
/// This information is returned from the SQL_DESC_LENGTH record field of the IRD.

bool isUnsigned() const;
/// Returns true if column is unsigned or a non-numeric data type.

private:
ODBCMetaColumn();

Expand Down
33 changes: 27 additions & 6 deletions Data/ODBC/src/ODBCMetaColumn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ namespace Data {
namespace ODBC {


ODBCMetaColumn::ODBCMetaColumn(const StatementHandle& rStmt, std::size_t position) :
ODBCMetaColumn::ODBCMetaColumn(const StatementHandle& rStmt, std::size_t position) :
MetaColumn(position),
_rStmt(rStmt)
{
init();
}


ODBCMetaColumn::~ODBCMetaColumn()
{
}
Expand Down Expand Up @@ -58,6 +58,23 @@ void ODBCMetaColumn::getDescription()
}


bool ODBCMetaColumn::isUnsigned() const
{
SQLLEN val = 0;
if (Utility::isError(Poco::Data::ODBC::SQLColAttribute(_rStmt,
(SQLUSMALLINT)position() + 1, // ODBC columns are 1-based
SQL_DESC_UNSIGNED,
0,
0,
0,
&val)))
{
throw StatementException(_rStmt);
}
return (val == SQL_TRUE);
}


void ODBCMetaColumn::init()
{
getDescription();
Expand Down Expand Up @@ -97,16 +114,20 @@ void ODBCMetaColumn::init()
setType(MetaColumn::FDT_WSTRING); break;

case SQL_TINYINT:
setType(MetaColumn::FDT_INT8); break;
setType(isUnsigned() ? MetaColumn::FDT_UINT8 : MetaColumn::FDT_INT8);
break;

case SQL_SMALLINT:
setType(MetaColumn::FDT_INT16); break;
setType(isUnsigned() ? MetaColumn::FDT_UINT16 : MetaColumn::FDT_INT16);
break;

case SQL_INTEGER:
setType(MetaColumn::FDT_INT32); break;
setType(isUnsigned() ? MetaColumn::FDT_UINT32 : MetaColumn::FDT_INT32);
break;

case SQL_BIGINT:
setType(MetaColumn::FDT_INT64); break;
setType(isUnsigned() ? MetaColumn::FDT_UINT64 : MetaColumn::FDT_INT64);
break;

case SQL_DOUBLE:
case SQL_FLOAT:
Expand Down
4 changes: 4 additions & 0 deletions Data/ODBC/src/SessionImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,11 @@ bool SessionImpl::canTransact()

void SessionImpl::setTransactionIsolation(Poco::UInt32 ti)
{
#if POCO_PTR_IS_64_BIT
Poco::UInt64 isolation = 0;
#else
Poco::UInt32 isolation = 0;
#endif

if (ti & Session::TRANSACTION_READ_UNCOMMITTED)
isolation |= SQL_TXN_READ_UNCOMMITTED;
Expand Down
2 changes: 1 addition & 1 deletion Foundation/src/ThreadPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ void PooledThread::activate()
void PooledThread::release()
{
const long JOIN_TIMEOUT = 10000;

_mutex.lock();
_pTarget = 0;
_mutex.unlock();
Expand Down

0 comments on commit 3fb4c34

Please sign in to comment.