Skip to content

Commit be946d0

Browse files
Saumya Garggargsaumya
authored andcommitted
cleanup free() in sqlhandle
1 parent 65d19a8 commit be946d0

2 files changed

Lines changed: 10 additions & 14 deletions

File tree

mssql_python/pybind/ddbc_bindings.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -633,17 +633,7 @@ SqlHandle::SqlHandle(SQLSMALLINT type, SQLHANDLE rawHandle)
633633
// Native ODBC handles must be explicitly released by calling `free()` directly from Python.
634634
// This avoids nondeterministic crashes during GC or shutdown during pytest.
635635
// Read the documentation for more details (https://aka.ms/CPPvsPythonGC)
636-
SqlHandle::~SqlHandle() {}
637-
638-
SQLHANDLE SqlHandle::get() const {
639-
return _handle;
640-
}
641-
642-
SQLSMALLINT SqlHandle::type() const {
643-
return _type;
644-
}
645-
646-
void SqlHandle::free() {
636+
SqlHandle::~SqlHandle() {
647637
if (_handle && SQLFreeHandle_ptr) {
648638
const char* type_str = nullptr;
649639
switch (_type) {
@@ -661,6 +651,14 @@ void SqlHandle::free() {
661651
}
662652
}
663653

654+
SQLHANDLE SqlHandle::get() const {
655+
return _handle;
656+
}
657+
658+
SQLSMALLINT SqlHandle::type() const {
659+
return _type;
660+
}
661+
664662
// Wrap SQLSetConnectAttr
665663
// SQLRETURN SQLSetConnectAttr_wrap(SqlHandlePtr ConnectionHandle, SQLINTEGER Attribute,
666664
// py::object ValuePtr) {
@@ -1963,8 +1961,7 @@ PYBIND11_MODULE(ddbc_bindings, m) {
19631961
.def_readwrite("sqlState", &ErrorInfo::sqlState)
19641962
.def_readwrite("ddbcErrorMsg", &ErrorInfo::ddbcErrorMsg);
19651963

1966-
py::class_<SqlHandle, SqlHandlePtr>(m, "SqlHandle")
1967-
.def("free", &SqlHandle::free);
1964+
py::class_<SqlHandle, SqlHandlePtr>(m, "SqlHandle");
19681965
py::class_<Connection>(m, "Connection")
19691966
.def(py::init<const std::wstring&, bool>(), py::arg("conn_str"), py::arg("autocommit") = false)
19701967
.def("connect", &Connection::connect, py::arg("attrs_before") = py::dict(), "Establish a connection to the database")

mssql_python/pybind/ddbc_bindings.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ class SqlHandle {
160160
~SqlHandle();
161161
SQLHANDLE get() const;
162162
SQLSMALLINT type() const;
163-
void free();
164163
private:
165164
SQLSMALLINT _type;
166165
SQLHANDLE _handle;

0 commit comments

Comments
 (0)