Skip to content

Commit eb3b5db

Browse files
committed
resolve level 4 warnings
1 parent f0730c1 commit eb3b5db

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

mssql_python/pybind/connection/connection.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static SqlHandlePtr getEnvHandle() {
2727
if (!SQL_SUCCEEDED(ret)) {
2828
ThrowStdException("Failed to set environment attributes");
2929
}
30-
return std::make_shared<SqlHandle>(SQL_HANDLE_ENV, env);
30+
return std::make_shared<SqlHandle>(static_cast<SQLSMALLINT>(SQL_HANDLE_ENV), env);
3131
}();
3232

3333
return envHandle;
@@ -54,7 +54,7 @@ void Connection::allocateDbcHandle() {
5454
LOG("Allocate SQL Connection Handle");
5555
SQLRETURN ret = SQLAllocHandle_ptr(SQL_HANDLE_DBC, _envHandle->get(), &dbc);
5656
checkError(ret);
57-
_dbcHandle = std::make_shared<SqlHandle>(SQL_HANDLE_DBC, dbc);
57+
_dbcHandle = std::make_shared<SqlHandle>(static_cast<SQLSMALLINT>(SQL_HANDLE_DBC), dbc);
5858
}
5959

6060
void Connection::connect(const py::dict& attrs_before) {
@@ -148,7 +148,7 @@ SqlHandlePtr Connection::allocStatementHandle() {
148148
SQLHANDLE stmt = nullptr;
149149
SQLRETURN ret = SQLAllocHandle_ptr(SQL_HANDLE_STMT, _dbcHandle->get(), &stmt);
150150
checkError(ret);
151-
return std::make_shared<SqlHandle>(SQL_HANDLE_STMT, stmt);
151+
return std::make_shared<SqlHandle>(static_cast<SQLSMALLINT>(SQL_HANDLE_STMT), stmt);
152152
}
153153

154154

@@ -214,7 +214,6 @@ bool Connection::reset() {
214214
ThrowStdException("Connection handle not allocated");
215215
}
216216
LOG("Resetting connection via SQL_ATTR_RESET_CONNECTION");
217-
SQLULEN reset = SQL_TRUE;
218217
SQLRETURN ret = SQLSetConnectAttr_ptr(
219218
_dbcHandle->get(),
220219
SQL_ATTR_RESET_CONNECTION,

mssql_python/pybind/ddbc_bindings.cpp

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,9 @@ SQLRETURN BindParameters(SQLHANDLE hStmt, const py::list& params,
320320
}
321321
// TODO: can be moved to python by registering SQL_DATE_STRUCT in pybind
322322
SQL_DATE_STRUCT* sqlDatePtr = AllocateParamBuffer<SQL_DATE_STRUCT>(paramBuffers);
323-
sqlDatePtr->year = param.attr("year").cast<int>();
324-
sqlDatePtr->month = param.attr("month").cast<int>();
325-
sqlDatePtr->day = param.attr("day").cast<int>();
323+
sqlDatePtr->year = static_cast<SQLSMALLINT>(param.attr("year").cast<int>());
324+
sqlDatePtr->month = static_cast<SQLUSMALLINT>(param.attr("month").cast<int>());
325+
sqlDatePtr->day = static_cast<SQLUSMALLINT>(param.attr("day").cast<int>());
326326
dataPtr = static_cast<void*>(sqlDatePtr);
327327
break;
328328
}
@@ -333,9 +333,9 @@ SQLRETURN BindParameters(SQLHANDLE hStmt, const py::list& params,
333333
}
334334
// TODO: can be moved to python by registering SQL_TIME_STRUCT in pybind
335335
SQL_TIME_STRUCT* sqlTimePtr = AllocateParamBuffer<SQL_TIME_STRUCT>(paramBuffers);
336-
sqlTimePtr->hour = param.attr("hour").cast<int>();
337-
sqlTimePtr->minute = param.attr("minute").cast<int>();
338-
sqlTimePtr->second = param.attr("second").cast<int>();
336+
sqlTimePtr->hour = static_cast<SQLUSMALLINT>(param.attr("hour").cast<int>());
337+
sqlTimePtr->minute = static_cast<SQLUSMALLINT>(param.attr("minute").cast<int>());
338+
sqlTimePtr->second = static_cast<SQLUSMALLINT>(param.attr("second").cast<int>());
339339
dataPtr = static_cast<void*>(sqlTimePtr);
340340
break;
341341
}
@@ -346,12 +346,12 @@ SQLRETURN BindParameters(SQLHANDLE hStmt, const py::list& params,
346346
}
347347
SQL_TIMESTAMP_STRUCT* sqlTimestampPtr =
348348
AllocateParamBuffer<SQL_TIMESTAMP_STRUCT>(paramBuffers);
349-
sqlTimestampPtr->year = param.attr("year").cast<int>();
350-
sqlTimestampPtr->month = param.attr("month").cast<int>();
351-
sqlTimestampPtr->day = param.attr("day").cast<int>();
352-
sqlTimestampPtr->hour = param.attr("hour").cast<int>();
353-
sqlTimestampPtr->minute = param.attr("minute").cast<int>();
354-
sqlTimestampPtr->second = param.attr("second").cast<int>();
349+
sqlTimestampPtr->year = static_cast<SQLSMALLINT>(param.attr("year").cast<int>());
350+
sqlTimestampPtr->month = static_cast<SQLUSMALLINT>(param.attr("month").cast<int>());
351+
sqlTimestampPtr->day = static_cast<SQLUSMALLINT>(param.attr("day").cast<int>());
352+
sqlTimestampPtr->hour = static_cast<SQLUSMALLINT>(param.attr("hour").cast<int>());
353+
sqlTimestampPtr->minute = static_cast<SQLUSMALLINT>(param.attr("minute").cast<int>());
354+
sqlTimestampPtr->second = static_cast<SQLUSMALLINT>(param.attr("second").cast<int>());
355355
// SQL server supports in ns, but python datetime supports in µs
356356
sqlTimestampPtr->fraction = static_cast<SQLUINTEGER>(
357357
param.attr("microsecond").cast<int>() * 1000); // Convert µs to ns
@@ -395,8 +395,11 @@ SQLRETURN BindParameters(SQLHANDLE hStmt, const py::list& params,
395395
assert(SQLBindParameter_ptr && SQLGetStmtAttr_ptr && SQLSetDescField_ptr);
396396

397397
RETCODE rc = SQLBindParameter_ptr(
398-
hStmt, paramIndex + 1 /* 1-based indexing */, paramInfo.inputOutputType,
399-
paramInfo.paramCType, paramInfo.paramSQLType, paramInfo.columnSize,
398+
hStmt,
399+
static_cast<SQLUSMALLINT>(paramIndex + 1), /* 1-based indexing */
400+
static_cast<SQLUSMALLINT>(paramInfo.inputOutputType),
401+
static_cast<SQLSMALLINT>(paramInfo.paramCType),
402+
static_cast<SQLSMALLINT>(paramInfo.paramSQLType), paramInfo.columnSize,
400403
paramInfo.decimalDigits, dataPtr, bufferLength, strLenOrIndPtr);
401404
if (!SQL_SUCCEEDED(rc)) {
402405
LOG("Error when binding parameter - {}", paramIndex);
@@ -406,7 +409,7 @@ SQLRETURN BindParameters(SQLHANDLE hStmt, const py::list& params,
406409
// https://learn.microsoft.com/en-us/sql/odbc/reference/appendixes/retrieve-numeric-data-sql-numeric-struct-kb222831?view=sql-server-ver16#sql_c_numeric-overview
407410
if (paramInfo.paramCType == SQL_C_NUMERIC) {
408411
SQLHDESC hDesc = nullptr;
409-
RETCODE rc = SQLGetStmtAttr_ptr(hStmt, SQL_ATTR_APP_PARAM_DESC, &hDesc, 0, NULL);
412+
rc = SQLGetStmtAttr_ptr(hStmt, SQL_ATTR_APP_PARAM_DESC, &hDesc, 0, NULL);
410413
if(!SQL_SUCCEEDED(rc)) {
411414
LOG("Error when getting statement attribute - {}", paramIndex);
412415
return rc;
@@ -866,7 +869,7 @@ SQLRETURN SQLGetData_wrap(SqlHandlePtr StatementHandle, SQLUSMALLINT colCount, p
866869
DriverLoader::getInstance().loadDriver(); // Load the driver
867870
}
868871

869-
SQLRETURN ret;
872+
SQLRETURN ret = SQL_SUCCESS;
870873
SQLHSTMT hStmt = StatementHandle->get();
871874
for (SQLSMALLINT i = 1; i <= colCount; ++i) {
872875
SQLWCHAR columnName[256];

0 commit comments

Comments
 (0)