Skip to content

Commit

Permalink
SqlException class
Browse files Browse the repository at this point in the history
  • Loading branch information
artpaul committed Apr 26, 2017
1 parent be39186 commit 8915749
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion driver/attr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
});
}
Expand Down
8 changes: 6 additions & 2 deletions driver/diagnostics.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "diagnostics.h"

#include <stdexcept>

DiagnosticRecord::DiagnosticRecord()
{
reset();
Expand All @@ -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();
Expand Down
20 changes: 20 additions & 0 deletions driver/diagnostics.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,26 @@
#include "log.h"
#include "platform.h"

#include <stdexcept>

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;
Expand Down

0 comments on commit 8915749

Please sign in to comment.