Skip to content

Commit 8915749

Browse files
committed
SqlException class
1 parent be39186 commit 8915749

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

driver/attr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl_SQLSetConnectAttr(SQLHDBC connection_handle, SQLINTEGER attribute,
110110
return SQL_SUCCESS;
111111

112112
default:
113-
throw std::runtime_error("Unsupported connection attribute.");
113+
throw SqlException("Unsupported connection attribute.", "HY092");
114114
}
115115
});
116116
}

driver/diagnostics.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#include "diagnostics.h"
22

3-
#include <stdexcept>
4-
53
DiagnosticRecord::DiagnosticRecord()
64
{
75
reset();
@@ -13,6 +11,12 @@ void DiagnosticRecord::fromException()
1311
{
1412
throw;
1513
}
14+
catch (const SqlException & e)
15+
{
16+
message = e.what();
17+
native_error_code = 1;
18+
sql_state = e.sqlState();
19+
}
1620
catch (const std::exception & e)
1721
{
1822
message = e.what();

driver/diagnostics.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,26 @@
33
#include "log.h"
44
#include "platform.h"
55

6+
#include <stdexcept>
7+
8+
class SqlException : public std::runtime_error
9+
{
10+
public:
11+
SqlException(const std::string & message_, const std::string & state_ = "HY000")
12+
: std::runtime_error(message_)
13+
, state(state_)
14+
{
15+
}
16+
17+
std::string sqlState() const
18+
{
19+
return state;
20+
}
21+
22+
private:
23+
const std::string state;
24+
};
25+
626
struct DiagnosticRecord
727
{
828
SQLINTEGER native_error_code;

0 commit comments

Comments
 (0)