@@ -78,6 +78,7 @@ void Connection::disconnect() {
7878 }
7979}
8080
81+ // TODO: Add an exception class in C++ for error handling, DB spec compliant
8182void Connection::checkError (SQLRETURN ret) const {
8283 if (!SQL_SUCCEEDED (ret)) {
8384 ErrorInfo err = SQLCheckError_Wrap (SQL_HANDLE_DBC, _dbcHandle, ret);
@@ -88,7 +89,7 @@ void Connection::checkError(SQLRETURN ret) const{
8889
8990void Connection::commit () {
9091 if (!_dbcHandle) {
91- throw std::runtime_error (" Connection handle not allocated" );
92+ ThrowStdException (" Connection handle not allocated" );
9293 }
9394 LOG (" Committing transaction" );
9495 SQLRETURN ret = SQLEndTran_ptr (SQL_HANDLE_DBC, _dbcHandle->get (), SQL_COMMIT);
@@ -97,7 +98,7 @@ void Connection::commit() {
9798
9899void Connection::rollback () {
99100 if (!_dbcHandle) {
100- throw std::runtime_error (" Connection handle not allocated" );
101+ ThrowStdException (" Connection handle not allocated" );
101102 }
102103 LOG (" Rolling back transaction" );
103104 SQLRETURN ret = SQLEndTran_ptr (SQL_HANDLE_DBC, _dbcHandle->get (), SQL_ROLLBACK);
@@ -106,7 +107,7 @@ void Connection::rollback() {
106107
107108void Connection::setAutocommit (bool enable) {
108109 if (!_dbcHandle) {
109- throw std::runtime_error (" Connection handle not allocated" );
110+ ThrowStdException (" Connection handle not allocated" );
110111 }
111112 SQLINTEGER value = enable ? SQL_AUTOCOMMIT_ON : SQL_AUTOCOMMIT_OFF;
112113 LOG (" Set SQL Connection Attribute" );
@@ -117,7 +118,7 @@ void Connection::setAutocommit(bool enable) {
117118
118119bool Connection::getAutocommit () const {
119120 if (!_dbcHandle) {
120- throw std::runtime_error (" Connection handle not allocated" );
121+ ThrowStdException (" Connection handle not allocated" );
121122 }
122123 LOG (" Get SQL Connection Attribute" );
123124 SQLINTEGER value;
@@ -129,7 +130,7 @@ bool Connection::getAutocommit() const {
129130
130131SqlHandlePtr Connection::allocStatementHandle () {
131132 if (!_dbcHandle) {
132- throw std::runtime_error (" Connection handle not allocated" );
133+ ThrowStdException (" Connection handle not allocated" );
133134 }
134135 LOG (" Allocating statement handle" );
135136 SQLHANDLE stmt = nullptr ;
@@ -180,7 +181,7 @@ void Connection::applyAttrsBefore(const py::dict& attrs) {
180181 if (key == SQL_COPT_SS_ACCESS_TOKEN) {
181182 SQLRETURN ret = setAttribute (key, py::reinterpret_borrow<py::object>(item.second ));
182183 if (!SQL_SUCCEEDED (ret)) {
183- throw std::runtime_error (" Failed to set access token before connect" );
184+ ThrowStdException (" Failed to set access token before connect" );
184185 }
185186 }
186187 }
0 commit comments