Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,12 @@ def get_compiler_settings():
'/wd4514', # unreference inline function removed
'/wd4820', # padding after struct member
'/wd4668', # is not defined as a preprocessor macro
'/wd4710', # function not inlined
'/wd4711', # function selected for automatic inline expansion
'/wd4100', # unreferenced formal parameter
'/wd4127', # "conditional expression is constant" testing compilation constants
'/wd4191', # casts to PYCFunction which doesn't have the keywords parameter
'/wd5045', # information note about Spectre mitigation (which we're not using)
])

if '--windbg' in sys.argv:
Expand Down
68 changes: 23 additions & 45 deletions src/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,18 @@ static bool ApplyPreconnAttrs(HDBC hdbc, SQLINTEGER ikey, PyObject *value, char

if (PyLong_Check(value))
{
if (_PyLong_Sign(value) >= 0)
unsigned long long uval = PyLong_AsUnsignedLongLong(value);
if (PyErr_Occurred())
{
ivalue = (SQLPOINTER)PyLong_AsUnsignedLong(value);
vallen = SQL_IS_UINTEGER;
} else
{
ivalue = (SQLPOINTER)PyLong_AsLong(value);
PyErr_Clear();
ivalue = (SQLPOINTER)PyLong_AsLongLong(value);
vallen = SQL_IS_INTEGER;
}
else
{
ivalue = (SQLPOINTER)uval;
vallen = SQL_IS_UINTEGER;
}
}
else if (PyByteArray_Check(value))
{
Expand Down Expand Up @@ -377,9 +380,8 @@ static char conv_clear_doc[] =
"clear_output_converters() --> None\n\n"
"Remove all output converter functions.";

static PyObject* Connection_conv_clear(PyObject* self, PyObject* args)
static PyObject* Connection_conv_clear(PyObject* self, PyObject* /* args (unused) */)
{
UNUSED(args);
Connection* cnxn = (Connection*)self;
Py_XDECREF(cnxn->map_sqltype_to_converter);
cnxn->map_sqltype_to_converter = 0;
Expand Down Expand Up @@ -445,10 +447,8 @@ static char close_doc[] =
"Note that closing a connection without committing the changes first will cause\n"
"an implicit rollback to be performed.";

static PyObject* Connection_close(PyObject* self, PyObject* args)
static PyObject* Connection_close(PyObject* self, PyObject* /* args (unused) */)
{
UNUSED(args);

Connection* cnxn = Connection_Validate(self);
if (!cnxn)
return 0;
Expand All @@ -458,10 +458,8 @@ static PyObject* Connection_close(PyObject* self, PyObject* args)
Py_RETURN_NONE;
}

static PyObject* Connection_cursor(PyObject* self, PyObject* args)
static PyObject* Connection_cursor(PyObject* self, PyObject* /* args (unused) */)
{
UNUSED(args);

Connection* cnxn = Connection_Validate(self);
if (!cnxn)
return 0;
Expand Down Expand Up @@ -759,10 +757,8 @@ PyObject* Connection_endtrans(Connection* cnxn, SQLSMALLINT type)
Py_RETURN_NONE;
}

static PyObject* Connection_commit(PyObject* self, PyObject* args)
static PyObject* Connection_commit(PyObject* self, PyObject* /* args (unused) */)
{
UNUSED(args);

Connection* cnxn = Connection_Validate(self);
if (!cnxn)
return 0;
Expand All @@ -772,10 +768,8 @@ static PyObject* Connection_commit(PyObject* self, PyObject* args)
return Connection_endtrans(cnxn, SQL_COMMIT);
}

static PyObject* Connection_rollback(PyObject* self, PyObject* args)
static PyObject* Connection_rollback(PyObject* self, PyObject* /* args (unused) */)
{
UNUSED(args);

Connection* cnxn = Connection_Validate(self);
if (!cnxn)
return 0;
Expand Down Expand Up @@ -810,10 +804,8 @@ static char getinfo_doc[] =
"Calls SQLGetInfo, passing `type`, and returns the result formatted as a Python object.";


PyObject* Connection_getautocommit(PyObject* self, void* closure)
PyObject* Connection_getautocommit(PyObject* self, void* /* closure (unused) */)
{
UNUSED(closure);

Connection* cnxn = Connection_Validate(self);
if (!cnxn)
return 0;
Expand All @@ -823,10 +815,8 @@ PyObject* Connection_getautocommit(PyObject* self, void* closure)
return result;
}

static int Connection_setautocommit(PyObject* self, PyObject* value, void* closure)
static int Connection_setautocommit(PyObject* self, PyObject* value, void* /* closure (unused) */)
{
UNUSED(closure);

Connection* cnxn = Connection_Validate(self);
if (!cnxn)
return -1;
Expand Down Expand Up @@ -854,9 +844,8 @@ static int Connection_setautocommit(PyObject* self, PyObject* value, void* closu
}


static PyObject* Connection_getclosed(PyObject* self, void* closure)
static PyObject* Connection_getclosed(PyObject* self, void* /* closure (unused) */)
{
UNUSED(closure);
Connection* cnxn;

if (self == 0 || !Connection_Check(self))
Expand All @@ -876,10 +865,8 @@ static PyObject* Connection_getclosed(PyObject* self, void* closure)
}


static PyObject* Connection_getsearchescape(PyObject* self, void* closure)
static PyObject* Connection_getsearchescape(PyObject* self, void* /* closure (unused) */)
{
UNUSED(closure);

Connection* cnxn = (Connection*)self;

if (!cnxn->searchescape)
Expand All @@ -901,21 +888,17 @@ static PyObject* Connection_getsearchescape(PyObject* self, void* closure)
return cnxn->searchescape;
}

static PyObject* Connection_getmaxwrite(PyObject* self, void* closure)
static PyObject* Connection_getmaxwrite(PyObject* self, void* /* closure (unused) */)
{
UNUSED(closure);

Connection* cnxn = Connection_Validate(self);
if (!cnxn)
return 0;

return PyLong_FromSsize_t(cnxn->maxwrite);
}

static int Connection_setmaxwrite(PyObject* self, PyObject* value, void* closure)
static int Connection_setmaxwrite(PyObject* self, PyObject* value, void* /* closure (unused) */)
{
UNUSED(closure);

Connection* cnxn = Connection_Validate(self);
if (!cnxn)
return -1;
Expand Down Expand Up @@ -943,21 +926,17 @@ static int Connection_setmaxwrite(PyObject* self, PyObject* value, void* closure
}


static PyObject* Connection_gettimeout(PyObject* self, void* closure)
static PyObject* Connection_gettimeout(PyObject* self, void* /* closure (unused) */)
{
UNUSED(closure);

Connection* cnxn = Connection_Validate(self);
if (!cnxn)
return 0;

return PyLong_FromLong(cnxn->timeout);
}

static int Connection_settimeout(PyObject* self, PyObject* value, void* closure)
static int Connection_settimeout(PyObject* self, PyObject* value, void* /* closure (unused) */)
{
UNUSED(closure);

Connection* cnxn = Connection_Validate(self);
if (!cnxn)
return -1;
Expand Down Expand Up @@ -1328,9 +1307,8 @@ static PyObject* Connection_setdecoding(PyObject* self, PyObject* args, PyObject


static char enter_doc[] = "__enter__() -> self.";
static PyObject* Connection_enter(PyObject* self, PyObject* args)
static PyObject* Connection_enter(PyObject* self, PyObject* /* args (unused) */)
{
UNUSED(args);
Py_INCREF(self);
return self;
}
Expand Down
46 changes: 13 additions & 33 deletions src/cursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,10 +435,8 @@ static char close_doc[] =
"be unusable from this point forward; a ProgrammingError exception will be\n"
"raised if any operation is attempted with the cursor.";

static PyObject* Cursor_close(PyObject* self, PyObject* args)
static PyObject* Cursor_close(PyObject* self, PyObject* /* args (unused) */)
{
UNUSED(args);

Cursor* cursor = Cursor_Validate(self, CURSOR_REQUIRE_OPEN | CURSOR_RAISE_ERROR);
if (!cursor)
return 0;
Expand Down Expand Up @@ -643,13 +641,12 @@ int GetDiagRecs(Cursor* cur)
// Default to UTF-16, which may not work if the driver/manager is using some other encoding
const char *unicode_enc = cur->cnxn ? cur->cnxn->metadata_enc.name : ENCSTR_UTF16NE;
PyObject* msg_value = PyUnicode_Decode(
(char*)cMessageText, iTextLength * sizeof(uint16_t), unicode_enc, "strict"
(char*)cMessageText, (Py_ssize_t)(iTextLength * sizeof(uint16_t)), unicode_enc, "strict"
);
if (!msg_value)
{
// If the char cannot be decoded, return something rather than nothing.
Py_XDECREF(msg_value);
msg_value = PyBytes_FromStringAndSize((char*)cMessageText, iTextLength * sizeof(uint16_t));
msg_value = PyBytes_FromStringAndSize((char*)cMessageText, (Py_ssize_t)(iTextLength * sizeof(uint16_t)));
}

PyObject* msg_tuple = PyTuple_New(2); // the message as a Python tuple of class and value
Expand Down Expand Up @@ -1272,10 +1269,8 @@ static PyObject* Cursor_iternext(PyObject* self)
return result;
}

static PyObject* Cursor_fetchval(PyObject* self, PyObject* args)
static PyObject* Cursor_fetchval(PyObject* self, PyObject* /* args (unused) */)
{
UNUSED(args);

Cursor* cursor = Cursor_Validate(self, CURSOR_REQUIRE_RESULTS | CURSOR_RAISE_ERROR);
if (!cursor)
return 0;
Expand All @@ -1292,10 +1287,8 @@ static PyObject* Cursor_fetchval(PyObject* self, PyObject* args)
return Row_item(row, 0);
}

static PyObject* Cursor_fetchone(PyObject* self, PyObject* args)
static PyObject* Cursor_fetchone(PyObject* self, PyObject* /* args (unused) */)
{
UNUSED(args);

PyObject* row;
Cursor* cursor = Cursor_Validate(self, CURSOR_REQUIRE_RESULTS | CURSOR_RAISE_ERROR);
if (!cursor)
Expand All @@ -1314,10 +1307,8 @@ static PyObject* Cursor_fetchone(PyObject* self, PyObject* args)
}


static PyObject* Cursor_fetchall(PyObject* self, PyObject* args)
static PyObject* Cursor_fetchall(PyObject* self, PyObject* /* args (unused) */)
{
UNUSED(args);

PyObject* result;
Cursor* cursor = Cursor_Validate(self, CURSOR_REQUIRE_RESULTS | CURSOR_RAISE_ERROR);
if (!cursor)
Expand Down Expand Up @@ -1809,10 +1800,8 @@ static char getTypeInfo_doc[] =
"17) num_prec_radix\n"
"18) interval_precision";

static PyObject* Cursor_getTypeInfo(PyObject* self, PyObject* args, PyObject* kwargs)
static PyObject* Cursor_getTypeInfo(PyObject* self, PyObject* args, PyObject* /* kwargs (unused) */)
{
UNUSED(kwargs);

int nDataType = SQL_ALL_TYPES;

if (!PyArg_ParseTuple(args, "|i", &nDataType))
Expand Down Expand Up @@ -1851,10 +1840,8 @@ static PyObject* Cursor_getTypeInfo(PyObject* self, PyObject* args, PyObject* kw
}


static PyObject* Cursor_nextset(PyObject* self, PyObject* args)
static PyObject* Cursor_nextset(PyObject* self, PyObject* /* args (unused) */)
{
UNUSED(args);

Cursor* cur = Cursor_Validate(self, 0);

if (!cur)
Expand Down Expand Up @@ -2149,9 +2136,8 @@ static char cancel_doc[] =
"This calls SQLCancel and is designed to be called from another thread to"
"stop processing of an ongoing query.";

static PyObject* Cursor_cancel(PyObject* self, PyObject* args)
static PyObject* Cursor_cancel(PyObject* self, PyObject* /* args (unused) */)
{
UNUSED(args);
Cursor* cur = Cursor_Validate(self, CURSOR_REQUIRE_OPEN | CURSOR_RAISE_ERROR);
if (!cur)
return 0;
Expand All @@ -2167,9 +2153,8 @@ static PyObject* Cursor_cancel(PyObject* self, PyObject* args)
}


static PyObject* Cursor_ignored(PyObject* self, PyObject* args)
static PyObject* Cursor_ignored(PyObject* /* self (unused) */, PyObject* /* args (unused) */)
{
UNUSED(self, args);
Py_RETURN_NONE;
}

Expand Down Expand Up @@ -2223,10 +2208,8 @@ static PyMemberDef Cursor_members[] =
{ 0 }
};

static PyObject* Cursor_getnoscan(PyObject* self, void *closure)
static PyObject* Cursor_getnoscan(PyObject* self, void* /* closure (unused) */)
{
UNUSED(closure);

Cursor* cursor = Cursor_Validate(self, CURSOR_REQUIRE_OPEN | CURSOR_RAISE_ERROR);
if (!cursor)
return 0;
Expand All @@ -2249,10 +2232,8 @@ static PyObject* Cursor_getnoscan(PyObject* self, void *closure)
Py_RETURN_TRUE;
}

static int Cursor_setnoscan(PyObject* self, PyObject* value, void *closure)
static int Cursor_setnoscan(PyObject* self, PyObject* value, void* /* closure (unused) */)
{
UNUSED(closure);

Cursor* cursor = Cursor_Validate(self, CURSOR_REQUIRE_OPEN | CURSOR_RAISE_ERROR);
if (!cursor)
return -1;
Expand Down Expand Up @@ -2351,9 +2332,8 @@ static char setinputsizes_doc[] =
"Setting sizes to None reverts all parameters to the defaults.";

static char enter_doc[] = "__enter__() -> self.";
static PyObject* Cursor_enter(PyObject* self, PyObject* args)
static PyObject* Cursor_enter(PyObject* self, PyObject* /* args (unused) */)
{
UNUSED(args);
Py_INCREF(self);
return self;
}
Expand Down
3 changes: 2 additions & 1 deletion src/cursor.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ struct Cursor
PyObject* pPreparedSQL;

// The number of parameter markers in pPreparedSQL. This will be zero when pPreparedSQL is zero but is set
// immediately after preparing the SQL.
// immediately after preparing the SQL. Must be between 0 and SHRT_MAX - 1 because ODBC uses a signed short for
// indexing into the parameters in some places, with one-based (not zero-based) counting.
int paramcount;

// If non-zero, a pointer to an array of SQL type values allocated via malloc. This is zero until we actually ask
Expand Down
2 changes: 1 addition & 1 deletion src/errors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ PyObject* GetErrorFromHandle(Connection *conn, const char* szFunction, HDBC hdbc
// For now, default to UTF-16 if this is not in the context of a connection.
// Note that this will not work if the DM is using a different wide encoding (e.g. UTF-32).
const char *unicode_enc = conn ? conn->metadata_enc.name : ENCSTR_UTF16NE;
Object msgStr(PyUnicode_Decode((char*)szMsg, cchMsg * sizeof(uint16_t), unicode_enc, "strict"));
Object msgStr(PyUnicode_Decode((char*)szMsg, (Py_ssize_t)(cchMsg * sizeof(uint16_t)), unicode_enc, "strict"));

if (cchMsg != 0 && msgStr.Get())
{
Expand Down
4 changes: 2 additions & 2 deletions src/getdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -779,14 +779,14 @@ PyObject *GetData_SqlVariant(Cursor *cur, Py_ssize_t iCol) {
// the ODBC driver read the sql_variant header which contains the underlying data type
pBuff = 0;
indicator = 0;
retcode = SQLGetData(cur->hstmt, static_cast<SQLSMALLINT>(iCol + 1), SQL_C_BINARY,
retcode = SQLGetData(cur->hstmt, static_cast<SQLUSMALLINT>(iCol + 1), SQL_C_BINARY,
&pBuff, 0, &indicator);
if (!SQL_SUCCEEDED(retcode))
return RaiseErrorFromHandle(cur->cnxn, "SQLGetData", cur->cnxn->hdbc, cur->hstmt);

// Get the SQL_CA_SS_VARIANT_TYPE field for the column which will contain the underlying data type
variantType = 0;
retcode = SQLColAttribute(cur->hstmt, iCol + 1, SQL_CA_SS_VARIANT_TYPE, NULL, 0, NULL, &variantType);
retcode = SQLColAttribute(cur->hstmt, static_cast<SQLUSMALLINT>(iCol + 1), SQL_CA_SS_VARIANT_TYPE, NULL, 0, NULL, &variantType);
if (!SQL_SUCCEEDED(retcode))
return RaiseErrorFromHandle(cur->cnxn, "SQLColAttribute", cur->cnxn->hdbc, cur->hstmt);

Expand Down
Loading
Loading