From 89157491cad3f990b95377d3c537b98fc6441bc9 Mon Sep 17 00:00:00 2001 From: Artemkin Pavel Date: Wed, 26 Apr 2017 17:25:40 +0500 Subject: [PATCH] SqlException class --- driver/attr.cpp | 2 +- driver/diagnostics.cpp | 8 ++++++-- driver/diagnostics.h | 20 ++++++++++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/driver/attr.cpp b/driver/attr.cpp index c66e92427..aea7aab80 100644 --- a/driver/attr.cpp +++ b/driver/attr.cpp @@ -110,7 +110,7 @@ impl_SQLSetConnectAttr(SQLHDBC connection_handle, SQLINTEGER attribute, return SQL_SUCCESS; default: - throw std::runtime_error("Unsupported connection attribute."); + throw SqlException("Unsupported connection attribute.", "HY092"); } }); } diff --git a/driver/diagnostics.cpp b/driver/diagnostics.cpp index 0ce90f9a2..5c138e670 100644 --- a/driver/diagnostics.cpp +++ b/driver/diagnostics.cpp @@ -1,7 +1,5 @@ #include "diagnostics.h" -#include - DiagnosticRecord::DiagnosticRecord() { reset(); @@ -13,6 +11,12 @@ void DiagnosticRecord::fromException() { throw; } + catch (const SqlException & e) + { + message = e.what(); + native_error_code = 1; + sql_state = e.sqlState(); + } catch (const std::exception & e) { message = e.what(); diff --git a/driver/diagnostics.h b/driver/diagnostics.h index b3f0a556a..5a2f14b93 100644 --- a/driver/diagnostics.h +++ b/driver/diagnostics.h @@ -3,6 +3,26 @@ #include "log.h" #include "platform.h" +#include + +class SqlException : public std::runtime_error +{ +public: + SqlException(const std::string & message_, const std::string & state_ = "HY000") + : std::runtime_error(message_) + , state(state_) + { + } + + std::string sqlState() const + { + return state; + } + +private: + const std::string state; +}; + struct DiagnosticRecord { SQLINTEGER native_error_code;