1 | // |
---|---|
2 | // ConnectionHandle.cpp |
3 | // |
4 | // Library: Data/ODBC |
5 | // Package: ODBC |
6 | // Module: ConnectionHandle |
7 | // |
8 | // Copyright (c) 2006, Applied Informatics Software Engineering GmbH |
9 | // and Contributors. |
10 | // |
11 | // SPDX-License-Identifier: BSL-1.0 |
12 | // |
13 | |
14 | |
15 | #include "Poco/Data/ODBC/ConnectionHandle.h" |
16 | #include "Poco/Data/ODBC/Utility.h" |
17 | #include "Poco/Data/ODBC/ODBCException.h" |
18 | |
19 | |
20 | namespace Poco { |
21 | namespace Data { |
22 | namespace ODBC { |
23 | |
24 | |
25 | ConnectionHandle::ConnectionHandle(EnvironmentHandle* pEnvironment): |
26 | _environment(pEnvironment ? &pEnvironment->handle() : 0), |
27 | _hdbc(SQL_NULL_HDBC) |
28 | { |
29 | if (Utility::isError(SQLAllocHandle(SQL_HANDLE_DBC, |
30 | _environment.handle(), |
31 | &_hdbc))) |
32 | { |
33 | throw ODBCException("Could not allocate connection handle."); |
34 | } |
35 | } |
36 | |
37 | |
38 | ConnectionHandle::~ConnectionHandle() |
39 | { |
40 | try |
41 | { |
42 | if (_hdbc != SQL_NULL_HDBC) |
43 | { |
44 | SQLDisconnect(_hdbc); |
45 | SQLRETURN rc = SQLFreeHandle(SQL_HANDLE_DBC, _hdbc); |
46 | _hdbc = SQL_NULL_HDBC; |
47 | |
48 | poco_assert(!Utility::isError(rc)); |
49 | } |
50 | } |
51 | catch (...) |
52 | { |
53 | poco_unexpected(); |
54 | } |
55 | } |
56 | |
57 | |
58 | } } } // namespace Poco::Data::ODBC |
59 |