Permalink
Browse files

Cleaned up compiler warnings

  • Loading branch information...
1 parent bbb08f0 commit 3c7a9e79a0dea3af4f9ea7697418607f4e844a84 @mkleehammer committed May 20, 2011
Showing with 64 additions and 57 deletions.
  1. +8 −0 setup.py
  2. +1 −1 src/cnxninfo.cpp
  3. +5 −5 src/connection.cpp
  4. +1 −1 src/connection.h
  5. +12 −12 src/cursor.cpp
  6. +1 −1 src/errors.cpp
  7. +21 −21 src/getdata.cpp
  8. +14 −14 src/params.cpp
  9. +0 −1 src/pyodbc.h
  10. +1 −1 src/pyodbcmodule.cpp
View
@@ -109,6 +109,14 @@ def get_compiler_settings(version_str):
pass
if os.name == 'nt':
+ settings['extra_compile_args'] = ['/Wall',
+ '/wd4668',
+ '/wd4820',
+ '/wd4711', # function selected for automatic inline expansion
+ '/wd4100', # unreferenced formal parameter
+ '/wd4127', # "conditional expression is constant" testing compilation constants
+ '/wd4191', # casts to PYCFunction, perhaps the extra parameters should be added
+ ]
settings['libraries'].append('odbc32')
settings['libraries'].append('advapi32')
View
@@ -116,7 +116,7 @@ static PyObject* CnxnInfo_New(Connection* cnxn)
if (SQL_SUCCEEDED(SQLGetTypeInfo(hstmt, SQL_TYPE_TIMESTAMP)) && SQL_SUCCEEDED(SQLFetch(hstmt)))
{
if (SQL_SUCCEEDED(SQLGetData(hstmt, 3, SQL_INTEGER, &columnsize, sizeof(columnsize), 0)))
- p->datetime_precision = columnsize;
+ p->datetime_precision = (int)columnsize;
SQLFreeStmt(hstmt, SQL_CLOSE);
}
View
@@ -112,13 +112,13 @@ static bool Connect(PyObject* pConnectString, HDBC hdbc, bool fAnsi, long timeou
"not have a Unicode connect function");
return false;
}
- szConnect[i] = (char)p[i];
+ szConnect[i] = (SQLCHAR)p[i];
}
}
else
{
const char* p = PyString_AS_STRING(pConnectString);
- memcpy(szConnect, p, PyString_GET_SIZE(pConnectString) + 1);
+ memcpy(szConnect, p, (size_t)(PyString_GET_SIZE(pConnectString) + 1));
}
Py_BEGIN_ALLOW_THREADS
@@ -679,7 +679,7 @@ Connection_setautocommit(PyObject* self, PyObject* value, void* closure)
return -1;
}
- int nAutoCommit = PyObject_IsTrue(value) ? SQL_AUTOCOMMIT_ON : SQL_AUTOCOMMIT_OFF;
+ SQLUINTEGER nAutoCommit = PyObject_IsTrue(value) ? SQL_AUTOCOMMIT_ON : SQL_AUTOCOMMIT_OFF;
SQLRETURN ret;
Py_BEGIN_ALLOW_THREADS
ret = SQLSetConnectAttr(cnxn->hdbc, SQL_ATTR_AUTOCOMMIT, (SQLPOINTER)nAutoCommit, SQL_IS_UINTEGER);
@@ -771,7 +771,7 @@ Connection_settimeout(PyObject* self, PyObject* value, void* closure)
return 0;
}
-static bool _add_converter(Connection* cnxn, int sqltype, PyObject* func)
+static bool _add_converter(Connection* cnxn, SQLSMALLINT sqltype, PyObject* func)
{
if (cnxn->conv_count)
{
@@ -852,7 +852,7 @@ Connection_conv_add(Connection* cnxn, PyObject* args)
if (!PyArg_ParseTuple(args, "iO", &sqltype, &func))
return 0;
- if (!_add_converter(cnxn, sqltype, func))
+ if (!_add_converter(cnxn, (SQLSMALLINT)sqltype, func))
return 0;
Py_RETURN_NONE;
View
@@ -24,7 +24,7 @@ struct Connection
HDBC hdbc;
// Will be SQL_AUTOCOMMIT_ON or SQL_AUTOCOMMIT_OFF.
- int nAutoCommit;
+ SQLUINTEGER nAutoCommit;
// The ODBC version the driver supports, from SQLGetInfo(DRIVER_ODBC_VER). This is set after connecting.
char odbc_major;
View
@@ -307,7 +307,7 @@ create_name_map(Cursor* cur, SQLSMALLINT field_count, bool lower)
// I'm not sure how
if (cDecimalDigits != 0)
{
- nColSize = cDecimalDigits + 3;
+ nColSize = (SQLUINTEGER)(cDecimalDigits + 3);
}
else
{
@@ -318,12 +318,12 @@ create_name_map(Cursor* cur, SQLSMALLINT field_count, bool lower)
colinfo = Py_BuildValue("(sOOiiiO)",
(char*)name,
- type, // type_code
- Py_None, // display size
- (int)nColSize, // internal_size
- nColSize, // precision
- cDecimalDigits, // scale
- nullable_obj); // null_ok
+ type, // type_code
+ Py_None, // display size
+ (int)nColSize, // internal_size
+ (int)nColSize, // precision
+ (int)cDecimalDigits, // scale
+ nullable_obj); // null_ok
if (!colinfo)
goto done;
@@ -598,7 +598,7 @@ PrepareResults(Cursor* cur, int cCols)
for (i = 0; i < cCols; i++)
{
- if (!InitColumnInfo(cur, (SQLSMALLINT)(i + 1), &cur->colinfos[i]))
+ if (!InitColumnInfo(cur, (SQLUSMALLINT)(i + 1), &cur->colinfos[i]))
{
pyodbc_free(cur->colinfos);
cur->colinfos = 0;
@@ -747,7 +747,7 @@ execute(Cursor* cur, PyObject* pSql, PyObject* params, bool skip_first)
{
SQLLEN remaining = min(cur->cnxn->varchar_maxlength, length - offset);
Py_BEGIN_ALLOW_THREADS
- ret = SQLPutData(cur->hstmt, (SQLPOINTER)wchar[offset], remaining * sizeof(SQLWCHAR));
+ ret = SQLPutData(cur->hstmt, (SQLPOINTER)wchar[offset], (SQLLEN)(remaining * sizeof(SQLWCHAR)));
Py_END_ALLOW_THREADS
if (!SQL_SUCCEEDED(ret))
return RaiseErrorFromHandle("SQLPutData", cur->cnxn->hdbc, cur->hstmt);
@@ -1308,8 +1308,8 @@ Cursor_statistics(PyObject* self, PyObject* args, PyObject* kwargs)
if (!free_results(cur, FREE_STATEMENT))
return 0;
- SQLUSMALLINT nUnique = PyObject_IsTrue(pUnique) ? SQL_INDEX_UNIQUE : SQL_INDEX_ALL;
- SQLUSMALLINT nReserved = PyObject_IsTrue(pQuick) ? SQL_QUICK : SQL_ENSURE;
+ SQLUSMALLINT nUnique = (SQLUSMALLINT)(PyObject_IsTrue(pUnique) ? SQL_INDEX_UNIQUE : SQL_INDEX_ALL);
+ SQLUSMALLINT nReserved = (SQLUSMALLINT)(PyObject_IsTrue(pQuick) ? SQL_QUICK : SQL_ENSURE);
SQLRETURN ret = 0;
@@ -1388,7 +1388,7 @@ _specialColumns(PyObject* self, PyObject* args, PyObject* kwargs, SQLUSMALLINT n
SQLRETURN ret = 0;
- SQLSMALLINT nNullable = PyObject_IsTrue(pNullable) ? SQL_NULLABLE : SQL_NO_NULLS;
+ SQLUSMALLINT nNullable = (SQLUSMALLINT)(PyObject_IsTrue(pNullable) ? SQL_NULLABLE : SQL_NO_NULLS);
Py_BEGIN_ALLOW_THREADS
ret = SQLSpecialColumns(cur->hstmt, nIdType, (SQLCHAR*)szCatalog, SQL_NTS, (SQLCHAR*)szSchema, SQL_NTS, (SQLCHAR*)szTable, SQL_NTS,
View
@@ -8,7 +8,7 @@
struct SqlStateMapping
{
char* prefix;
- int prefix_len;
+ size_t prefix_len;
PyObject** pexc_class; // Note: Double indirection (pexc_class) necessary because the pointer values are not
// initialized during startup
};
View
@@ -59,7 +59,7 @@ class DataBuffer
this->dataType = dataType;
- element_size = (dataType == SQL_C_WCHAR) ? sizeof(SQLWCHAR) : sizeof(char);
+ element_size = (int)((dataType == SQL_C_WCHAR) ? sizeof(SQLWCHAR) : sizeof(char));
null_size = (dataType == SQL_C_BINARY) ? 0 : element_size;
buffer = stackBuffer;
@@ -135,15 +135,15 @@ class DataBuffer
else
{
// We're Unicode, but SQLWCHAR and Py_UNICODE don't match, so maintain our own SQLWCHAR buffer.
- buffer = (char*)pyodbc_malloc(newSize);
+ buffer = (char*)pyodbc_malloc((size_t)newSize);
}
if (buffer == 0)
return false;
usingStack = false;
- memcpy(buffer, stackBuffer, bufferSize);
+ memcpy(buffer, stackBuffer, (size_t)bufferSize);
bufferSize = newSize;
return true;
}
@@ -162,7 +162,7 @@ class DataBuffer
}
else
{
- char* tmp = (char*)realloc(buffer, newSize);
+ char* tmp = (char*)realloc(buffer, (size_t)newSize);
if (tmp == 0)
return false;
buffer = tmp;
@@ -285,7 +285,7 @@ GetDataString(Cursor* cur, Py_ssize_t iCol)
SQLLEN cbData = 0;
Py_BEGIN_ALLOW_THREADS
- ret = SQLGetData(cur->hstmt, (SQLSMALLINT)(iCol+1), nTargetType, buffer.GetBuffer(), buffer.GetRemaining(), &cbData);
+ ret = SQLGetData(cur->hstmt, (SQLUSMALLINT)(iCol+1), nTargetType, buffer.GetBuffer(), buffer.GetRemaining(), &cbData);
Py_END_ALLOW_THREADS;
if (cbData == SQL_NULL_DATA)
@@ -394,18 +394,18 @@ GetDataDecimal(Cursor* cur, Py_ssize_t iCol)
ColumnInfo* pinfo = &cur->colinfos[iCol];
- SQLLEN cbNeeded = pinfo->column_size + 3 + // sign, decimal, NULL
- (pinfo->column_size / 3) + 2; // grouping. I believe this covers all cases.
+ SQLLEN cbNeeded = (SQLLEN)(pinfo->column_size + 3 + // sign, decimal, NULL
+ (pinfo->column_size / 3) + 2); // grouping. I believe this covers all cases.
SQLLEN cbFetched = 0;
- char* sz = (char*)_alloca(cbNeeded);
+ char* sz = (char*)_alloca((size_t)cbNeeded);
if (sz == 0)
return PyErr_NoMemory();
SQLRETURN ret;
Py_BEGIN_ALLOW_THREADS
- ret = SQLGetData(cur->hstmt, (SQLSMALLINT)(iCol+1), SQL_C_CHAR, sz, cbNeeded, &cbFetched);
+ ret = SQLGetData(cur->hstmt, (SQLUSMALLINT)(iCol+1), SQL_C_CHAR, sz, cbNeeded, &cbFetched);
Py_END_ALLOW_THREADS
if (!SQL_SUCCEEDED(ret))
return RaiseErrorFromHandle("SQLGetData", cur->cnxn->hdbc, cur->hstmt);
@@ -424,7 +424,7 @@ GetDataDecimal(Cursor* cur, Py_ssize_t iCol)
{
if (sz[i] == chGroupSeparator || sz[i] == '$' || sz[i] == chCurrencySymbol)
{
- memmove(&sz[i], &sz[i] + 1, cbFetched - i);
+ memmove(&sz[i], &sz[i] + 1, (size_t)(cbFetched - i));
cbFetched--;
}
else if (sz[i] == chDecimal)
@@ -444,7 +444,7 @@ GetDataBit(Cursor* cur, Py_ssize_t iCol)
SQLRETURN ret;
Py_BEGIN_ALLOW_THREADS
- ret = SQLGetData(cur->hstmt, (SQLSMALLINT)(iCol+1), SQL_C_BIT, &ch, sizeof(ch), &cbFetched);
+ ret = SQLGetData(cur->hstmt, (SQLUSMALLINT)(iCol+1), SQL_C_BIT, &ch, sizeof(ch), &cbFetched);
Py_END_ALLOW_THREADS
if (!SQL_SUCCEEDED(ret))
@@ -471,7 +471,7 @@ GetDataLong(Cursor* cur, Py_ssize_t iCol)
SQLSMALLINT nCType = pinfo->is_unsigned ? SQL_C_ULONG : SQL_C_LONG;
Py_BEGIN_ALLOW_THREADS
- ret = SQLGetData(cur->hstmt, (SQLSMALLINT)(iCol+1), nCType, &value, sizeof(value), &cbFetched);
+ ret = SQLGetData(cur->hstmt, (SQLUSMALLINT)(iCol+1), nCType, &value, sizeof(value), &cbFetched);
Py_END_ALLOW_THREADS
if (!SQL_SUCCEEDED(ret))
return RaiseErrorFromHandle("SQLGetData", cur->cnxn->hdbc, cur->hstmt);
@@ -495,7 +495,7 @@ static PyObject* GetDataLongLong(Cursor* cur, Py_ssize_t iCol)
SQLRETURN ret;
Py_BEGIN_ALLOW_THREADS
- ret = SQLGetData(cur->hstmt, (SQLSMALLINT)(iCol+1), nCType, &value, sizeof(value), &cbFetched);
+ ret = SQLGetData(cur->hstmt, (SQLUSMALLINT)(iCol+1), nCType, &value, sizeof(value), &cbFetched);
Py_END_ALLOW_THREADS
if (!SQL_SUCCEEDED(ret))
@@ -505,8 +505,8 @@ static PyObject* GetDataLongLong(Cursor* cur, Py_ssize_t iCol)
Py_RETURN_NONE;
if (pinfo->is_unsigned)
- return PyLong_FromUnsignedLongLong((PY_LONG_LONG)value);
-
+ return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)(SQLUBIGINT)value);
+
return PyLong_FromLongLong((PY_LONG_LONG)value);
}
@@ -518,7 +518,7 @@ GetDataDouble(Cursor* cur, Py_ssize_t iCol)
SQLRETURN ret;
Py_BEGIN_ALLOW_THREADS
- ret = SQLGetData(cur->hstmt, (SQLSMALLINT)(iCol+1), SQL_C_DOUBLE, &value, sizeof(value), &cbFetched);
+ ret = SQLGetData(cur->hstmt, (SQLUSMALLINT)(iCol+1), SQL_C_DOUBLE, &value, sizeof(value), &cbFetched);
Py_END_ALLOW_THREADS
if (!SQL_SUCCEEDED(ret))
return RaiseErrorFromHandle("SQLGetData", cur->cnxn->hdbc, cur->hstmt);
@@ -538,15 +538,15 @@ GetSqlServerTime(Cursor* cur, Py_ssize_t iCol)
SQLRETURN ret;
Py_BEGIN_ALLOW_THREADS
- ret = SQLGetData(cur->hstmt, (SQLSMALLINT)(iCol+1), SQL_C_BINARY, &value, sizeof(value), &cbFetched);
+ ret = SQLGetData(cur->hstmt, (SQLUSMALLINT)(iCol+1), SQL_C_BINARY, &value, sizeof(value), &cbFetched);
Py_END_ALLOW_THREADS
if (!SQL_SUCCEEDED(ret))
return RaiseErrorFromHandle("SQLGetData", cur->cnxn->hdbc, cur->hstmt);
if (cbFetched == SQL_NULL_DATA)
Py_RETURN_NONE;
- int micros = value.fraction / 1000; // nanos --> micros
+ int micros = (int)(value.fraction / 1000); // nanos --> micros
return PyTime_FromTime(value.hour, value.minute, value.second, micros);
}
@@ -559,7 +559,7 @@ GetDataTimestamp(Cursor* cur, Py_ssize_t iCol)
SQLRETURN ret;
Py_BEGIN_ALLOW_THREADS
- ret = SQLGetData(cur->hstmt, (SQLSMALLINT)(iCol+1), SQL_C_TYPE_TIMESTAMP, &value, sizeof(value), &cbFetched);
+ ret = SQLGetData(cur->hstmt, (SQLUSMALLINT)(iCol+1), SQL_C_TYPE_TIMESTAMP, &value, sizeof(value), &cbFetched);
Py_END_ALLOW_THREADS
if (!SQL_SUCCEEDED(ret))
return RaiseErrorFromHandle("SQLGetData", cur->cnxn->hdbc, cur->hstmt);
@@ -571,15 +571,15 @@ GetDataTimestamp(Cursor* cur, Py_ssize_t iCol)
{
case SQL_TYPE_TIME:
{
- int micros = value.fraction / 1000; // nanos --> micros
+ int micros = (int)(value.fraction / 1000); // nanos --> micros
return PyTime_FromTime(value.hour, value.minute, value.second, micros);
}
case SQL_TYPE_DATE:
return PyDate_FromDate(value.year, value.month, value.day);
}
- int micros = value.fraction / 1000; // nanos --> micros
+ int micros = (int)(value.fraction / 1000); // nanos --> micros
return PyDateTime_FromDateAndTime(value.year, value.month, value.day, value.hour, value.minute, value.second, micros);
}
Oops, something went wrong.

0 comments on commit 3c7a9e7

Please sign in to comment.