Skip to content

Commit 3240394

Browse files
committed
added a TODO comment to address review comments
1 parent 5181a0e commit 3240394

2 files changed

Lines changed: 7 additions & 8 deletions

File tree

mssql_python/connection.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ def __init__(self, connection_str: str = "", autocommit: bool = False, attrs_bef
5959
self._attrs_before = attrs_before or {}
6060
self._conn = ddbc_bindings.Connection(self.connection_str, autocommit)
6161
self._conn.connect(self._attrs_before)
62-
self._autocommit = autocommit
6362
self.setautocommit(autocommit)
6463

6564
def _construct_connection_string(self, connection_str: str = "", **kwargs) -> str:
@@ -133,7 +132,6 @@ def setautocommit(self, value: bool = True) -> None:
133132
DatabaseError: If there is an error while setting the autocommit mode.
134133
"""
135134
self._conn.set_autocommit(value)
136-
self._autocommit = value
137135

138136
def cursor(self) -> Cursor:
139137
"""

mssql_python/pybind/connection/connection.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ void Connection::disconnect() {
7878
}
7979
}
8080

81+
// TODO: Add an exception class in C++ for error handling, DB spec compliant
8182
void 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

8990
void 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

9899
void 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

107108
void 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

118119
bool 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

130131
SqlHandlePtr 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

Comments
 (0)