Files
poco/Data/ODBC/src/ODBCMetaColumn.cpp
Matej Kenda 8a4a2955d5 Use nullptr in C++ code (solves #4348) (#5043)
* chore(CppParser): 0, NULL --> nullptr

* chore(Crypto): 0, NULL --> nullptr

* chore(DNSSD): 0, NULL --> nullptr

* chore(Encodings): 0, NULL --> nullptr

* chore(CppUnit): Correct indentation.

* chore(Foundation): 0, NULL --> nullptr

* chore(CMake): Always warn about wrong nullptr usage when compiling with GCC or CLang

* chore(Net): 0, NULL --> nullptr

* chore(Foundation): 0, NULL --> nullptr

* chore(Data): 0, NULL --> nullptr

* chore(macOS): 0, NULL --> nullptr

* chore(XML): 0, NULL --> nullptr

* chore(Zip): 0, NULL --> nullptr

* chore(Util): 0, NULL --> nullptr

* chore(Net/NetSSL): 0, NULL --> nullptr

* chore(Bonjour): 0, NULL --> nullptr

* chore(MongoDB, Redis): 0, NULL --> nullptr

* chore(Poco): 0, NULL --> nullptr

* chore(Win32): 0, NULL --> nullptr

* chore(CMake): Only warn about nullptr when verbose warnings are enabled.

* Potential fix for code scanning alert no. 1634: Guarded Free

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>

* chore(Net): Fix warning reported by gitlab.

* chore(gitlab CI): attempt to clean to gain disk space on the runner.

* chore(gitlab CI): Run build with  --parallel 4, correct docker cleanup.

---------

Co-authored-by: Aleksandar Fabijanic <aleks-f@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
2025-10-30 15:20:53 +01:00

165 lines
3.4 KiB
C++

//
// ODBCMetaColumn.cpp
//
// Library: Data/ODBC
// Package: ODBC
// Module: ODBCMetaColumn
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/Data/ODBC/ODBCMetaColumn.h"
#include "Poco/Data/ODBC/Utility.h"
namespace Poco {
namespace Data {
namespace ODBC {
ODBCMetaColumn::ODBCMetaColumn(const StatementHandle& rStmt, std::size_t position) :
MetaColumn(position),
_rStmt(rStmt)
{
init();
}
ODBCMetaColumn::~ODBCMetaColumn()
{
}
void ODBCMetaColumn::getDescription()
{
std::memset(_columnDesc.name, 0, NAME_BUFFER_LENGTH);
_columnDesc.nameBufferLength = 0;
_columnDesc.dataType = 0;
_columnDesc.size = 0;
_columnDesc.decimalDigits = 0;
_columnDesc.isNullable = 0;
if (Utility::isError(Poco::Data::ODBC::SQLDescribeCol(_rStmt,
(SQLUSMALLINT) position() + 1, // ODBC columns are 1-based
_columnDesc.name,
NAME_BUFFER_LENGTH,
&_columnDesc.nameBufferLength,
&_columnDesc.dataType,
&_columnDesc.size,
&_columnDesc.decimalDigits,
&_columnDesc.isNullable)))
{
throw StatementException(_rStmt, "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,
nullptr,
0,
nullptr,
&val)))
{
throw StatementException(_rStmt, "ODBCMetaColumn::isUnsigned()");
}
return (val == SQL_TRUE);
}
void ODBCMetaColumn::init()
{
getDescription();
if (Utility::isError(Poco::Data::ODBC::SQLColAttribute(_rStmt,
(SQLUSMALLINT) position() + 1, // ODBC columns are 1-based
SQL_DESC_LENGTH,
nullptr,
0,
nullptr,
&_dataLength)))
{
throw StatementException(_rStmt, "ODBCMetaColumn::init()");
}
setName(std::string((char*) _columnDesc.name));
setLength(_columnDesc.size);
setPrecision(_columnDesc.decimalDigits);
setNullable(SQL_NULLABLE == _columnDesc.isNullable);
switch(_columnDesc.dataType)
{
case SQL_BIT:
setType(MetaColumn::FDT_BOOL); break;
case SQL_CHAR:
case SQL_VARCHAR:
case SQL_LONGVARCHAR:
setType(MetaColumn::FDT_STRING); break;
case SQL_WCHAR:
case SQL_WVARCHAR:
case SQL_WLONGVARCHAR:
setType(MetaColumn::FDT_WSTRING); break;
case SQL_TINYINT:
setType(isUnsigned() ? MetaColumn::FDT_UINT8 : MetaColumn::FDT_INT8);
break;
case SQL_SMALLINT:
setType(isUnsigned() ? MetaColumn::FDT_UINT16 : MetaColumn::FDT_INT16);
break;
case SQL_INTEGER:
setType(isUnsigned() ? MetaColumn::FDT_UINT32 : MetaColumn::FDT_INT32);
break;
case SQL_BIGINT:
setType(isUnsigned() ? MetaColumn::FDT_UINT64 : MetaColumn::FDT_INT64);
break;
case SQL_DOUBLE:
case SQL_FLOAT:
case SQL_NUMERIC:
case SQL_DECIMAL:
setType(MetaColumn::FDT_DOUBLE); break;
case SQL_REAL:
setType(MetaColumn::FDT_FLOAT); break;
case SQL_BINARY:
case SQL_VARBINARY:
case SQL_LONGVARBINARY:
case -98:// IBM DB2 non-standard type
setType(MetaColumn::FDT_BLOB); break;
case SQL_TYPE_DATE:
setType(MetaColumn::FDT_DATE); break;
case SQL_TYPE_TIME:
#ifdef POCO_DATA_ODBC_HAVE_SQL_SERVER_EXT
case SQL_SS_TIME2: // MS SQL Server custom type
#endif
setType(MetaColumn::FDT_TIME); break;
case SQL_TYPE_TIMESTAMP:
setType(MetaColumn::FDT_TIMESTAMP); break;
case SQL_GUID:
setType(MetaColumn::FDT_UUID); break;
default:
throw DataFormatException("Unsupported data type.");
}
}
} } } // namespace Poco::Data::ODBC