Skip to content

Commit 70f6aa3

Browse files
Saumya Garggargsaumya
authored andcommitted
resolving conflict
1 parent 179ebf2 commit 70f6aa3

2 files changed

Lines changed: 2 additions & 42 deletions

File tree

mssql_python/pybind/connection/connection.cpp

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -116,46 +116,6 @@ bool Connection::getAutocommit() const {
116116
return value == SQL_AUTOCOMMIT_ON;
117117
}
118118

119-
SQLRETURN set_attribute(SQLINTEGER Attribute, py::object ValuePtr) {
120-
LOG("Set SQL Connection Attribute");
121-
if (!SQLSetConnectAttr_ptr) {
122-
LOG("Function pointer not initialized. Loading the driver.");
123-
DriverLoader::getInstance().loadDriver(); // Load the driver
124-
}
125-
126-
// Print the type of ValuePtr and attribute value - helpful for debugging
127-
LOG("Type of ValuePtr: {}, Attribute: {}", py::type::of(ValuePtr).attr("__name__").cast<std::string>(), Attribute);
128-
129-
SQLPOINTER value = 0;
130-
SQLINTEGER length = 0;
131-
132-
if (py::isinstance<py::int_>(ValuePtr)) {
133-
// Handle integer values
134-
int intValue = ValuePtr.cast<int>();
135-
value = reinterpret_cast<SQLPOINTER>(intValue);
136-
length = SQL_IS_INTEGER; // Integer values don't require a length
137-
} else if (py::isinstance<py::bytes>(ValuePtr) || py::isinstance<py::bytearray>(ValuePtr)) {
138-
// Handle byte or bytearray values (like access tokens)
139-
// Store in static buffer to ensure memory remains valid during connection
140-
static std::vector<std::string> bytesBuffers;
141-
bytesBuffers.push_back(ValuePtr.cast<std::string>());
142-
value = const_cast<char*>(bytesBuffers.back().c_str());
143-
length = SQL_IS_POINTER; // Indicates we're passing a pointer (required for token)
144-
} else {
145-
LOG("Unsupported ValuePtr type");
146-
return SQL_ERROR;
147-
}
148-
149-
SQLRETURN ret = SQLSetConnectAttr_ptr(_dbc_handle->get(), Attribute, value, length);
150-
if (!SQL_SUCCEEDED(ret)) {
151-
LOG("Failed to set Connection attribute");
152-
}
153-
else {
154-
LOG("Set Connection attribute successfully");
155-
}
156-
return ret;
157-
}
158-
159119
SqlHandlePtr Connection::allocStatementHandle() {
160120
LOG("Allocating statement handle");
161121
SQLHANDLE stmt = nullptr;
@@ -205,8 +165,7 @@ void Connection::apply_attrs_before(const py::dict& attrs) {
205165
continue;
206166
}
207167

208-
//do not hard code the key values
209-
if (key == 1256) {
168+
if (key == SQL_COPT_SS_ACCESS_TOKEN) {
210169
SQLRETURN ret = set_attribute(key, py::reinterpret_borrow<py::object>(item.second));
211170
if (!SQL_SUCCEEDED(ret)) {
212171
throw std::runtime_error("Failed to set access token before connect");

mssql_python/pybind/connection/connection.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class Connection {
1818
Connection(const std::wstring& conn_str, bool autocommit = false);
1919
~Connection();
2020

21+
// Establish the connection using the stored connection string.
2122
SQLRETURN connect(const py::dict& attrs_before = py::dict());
2223

2324
// Close the connection and free resources.

0 commit comments

Comments
 (0)