--- a/src/SqlException.cpp Mon Jun 01 00:14:40 2020 +0200
+++ b/src/SqlException.cpp Mon Jun 01 17:14:22 2020 +0200
@@ -24,6 +24,7 @@
#include <sqlext.h>
#include "SqlException.h"
+#include "OdbcCommon.h"
namespace relpipe {
namespace tr {
@@ -32,7 +33,7 @@
SqlException::SqlException(std::wstring message) : message(message) {
}
-SqlException::SqlException(std::wstring message, SQLRETURN resultCode, SQLSMALLINT handleType, SQLHANDLE handle) : message(message), resultCode(resultCode) {
+SqlException::SqlException(std::wstring message, SQLRETURN resultCode, SQLSMALLINT handleType, SQLHANDLE handle, bool freeHandle) : message(message), resultCode(resultCode) {
std::wstring_convert < std::codecvt_utf8<wchar_t>> convertor; // TODO: support also other encodings
SQLCHAR buffer[SQL_MAX_MESSAGE_LENGTH + 1];
SQLCHAR sqlstate[SQL_SQLSTATE_SIZE + 1];
@@ -43,6 +44,7 @@
for (SQLSMALLINT i = 1; SQLGetDiagRec(handleType, handle, i, sqlstate, &sqlcode, buffer, SQL_MAX_MESSAGE_LENGTH + 1, &length) == SQL_SUCCESS; i++) {
diagnostics.push_back({convertor.from_bytes((char*) sqlstate), sqlcode, convertor.from_bytes((char*) buffer)});
}
+ if (freeHandle) OdbcCommon::freeHandle(handleType, handle);
}
std::vector<SqlException::SqlDiagnosticsRecord> SqlException::getDiagnostics() const {