Skip to content

Commit e6a9bbc

Browse files
committed
resolving copilot comments
1 parent 0f672b9 commit e6a9bbc

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

mssql_python/pybind/ddbc_bindings.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3096,18 +3096,14 @@ SQLRETURN FetchBatchData(SQLHSTMT hStmt, ColumnBuffers& buffers, py::list& colum
30963096
}
30973097
case SQL_GUID: {
30983098
SQLGUID* guidValue = &buffers.guidBuffers[col - 1][i];
3099-
uint8_t reordered[16];
3100-
reordered[0] = ((char*)&guidValue->Data1)[3];
3101-
reordered[1] = ((char*)&guidValue->Data1)[2];
3102-
reordered[2] = ((char*)&guidValue->Data1)[1];
3103-
reordered[3] = ((char*)&guidValue->Data1)[0];
3104-
reordered[4] = ((char*)&guidValue->Data2)[1];
3105-
reordered[5] = ((char*)&guidValue->Data2)[0];
3106-
reordered[6] = ((char*)&guidValue->Data3)[1];
3107-
reordered[7] = ((char*)&guidValue->Data3)[0];
3108-
std::memcpy(reordered + 8, guidValue->Data4, 8);
3109-
3110-
py::bytes py_guid_bytes(reinterpret_cast<char*>(reordered), 16);
3099+
// We already have the raw bytes from SQL Server in the SQLGUID struct.
3100+
// We do not need to perform any additional reordering here, as the C++
3101+
// SQLGUID struct is already laid out in the non-standard SQL Server byte order.
3102+
std::vector<char> guid_bytes(16);
3103+
std::memcpy(guid_bytes.data(), guidValue, sizeof(SQLGUID));
3104+
3105+
// Convert the raw C++ byte vector to a Python bytes object
3106+
py::bytes py_guid_bytes(guid_bytes.data(), guid_bytes.size());
31113107
py::dict kwargs;
31123108
kwargs["bytes"] = py_guid_bytes;
31133109
py::object uuid_obj = py::module_::import("uuid").attr("UUID")(**kwargs);

0 commit comments

Comments
 (0)