poco/Data/ODBC/src/EnvironmentHandle.cpp
Aleksandar Fabijanic 5131fe1c15
fix(Poco::Data): fixes and improvements #4198 (#4199)
* fix(Poco::Data): fixes and improvements #4198

* chore: remove inadvertently commited garbage file

* fix(SQLite): SQLChannel tests #4198

* fix(Data::SessionPool): Improve Data::SessionPool thread safety #4206
2023-10-22 12:53:54 +02:00

65 lines
1.3 KiB
C++

//
// EnvironmentHandle.cpp
//
// Library: Data/ODBC
// Package: ODBC
// Module: EnvironmentHandle
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/Data/ODBC/EnvironmentHandle.h"
#include "Poco/Data/ODBC/Utility.h"
#include "Poco/Data/ODBC/ODBCException.h"
#include "Poco/Error.h"
#include "Poco/Debugger.h"
namespace Poco {
namespace Data {
namespace ODBC {
EnvironmentHandle::EnvironmentHandle(): _henv(SQL_NULL_HENV)
{
SQLRETURN rc = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &_henv);
if (Utility::isError(rc))
throw ODBCException("EnvironmentHandle: Could not initialize ODBC environment.");
rc = SQLSetEnvAttr(_henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER) SQL_OV_ODBC3, 0);
if (Utility::isError(rc))
{
EnvironmentError err(_henv);
throw ODBCException(err.toString());
}
}
EnvironmentHandle::~EnvironmentHandle()
{
try
{
#if defined(_DEBUG)
SQLRETURN rc = SQLFreeHandle(SQL_HANDLE_ENV, _henv);
if (Utility::isError(rc))
{
EnvironmentError err(_henv);
Debugger::enter(err.toString(), __FILE__, __LINE__);
}
#else
SQLFreeHandle(SQL_HANDLE_ENV, _henv);
#endif
}
catch (...)
{
poco_unexpected();
}
}
} } } // namespace Poco::Data::ODBC