Skip to content

Commit

Permalink
Building on MinGW
Browse files Browse the repository at this point in the history
mkleehammer/pyodbc/#1168
  • Loading branch information
RoDuth committed Dec 17, 2024
1 parent 12fe42e commit df57ccd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
11 changes: 9 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

import sys, os, shlex, re
import sys, os, re, shlex, sysconfig
from os.path import exists, join, isdir, relpath, expanduser
from pathlib import Path
from inspect import cleandoc
Expand Down Expand Up @@ -83,7 +83,14 @@ def get_compiler_settings():
'define_macros': [('PYODBC_VERSION', VERSION)]
}

if os.name == 'nt':
if 'mingw' in sysconfig.get_platform():
# Windows mingw (note that os.name == 'nt' is True)
settings['extra_compile_args'].extend([
'-Wno-write-strings',
])
settings['libraries'].append('odbc32')

elif os.name == 'nt':
settings['extra_compile_args'].extend([
'/Wall',
'/wd4514', # unreference inline function removed
Expand Down
5 changes: 3 additions & 2 deletions src/pyodbc.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ typedef long long INT64;
typedef unsigned long long UINT64;
#define _strcmpi strcasecmp
#define _strdup strdup
inline int max(int lhs, int rhs) { return (rhs > lhs) ? rhs : lhs; }
inline int max(int lhs, int rhs) { return (rhs > lhs) ? rhs : lhs; }
inline int min(int lhs, int rhs) { return (rhs < lhs) ? rhs : lhs; }
#endif

#ifdef __SUN__
Expand All @@ -45,7 +46,7 @@ typedef unsigned long long UINT64;
#include <structmember.h>
#include <bytesobject.h>

#ifdef __CYGWIN__
#if defined(__CYGWIN__) || defined(__MINGW32__)
#include <windows.h>
#endif

Expand Down
3 changes: 2 additions & 1 deletion src/pyodbcmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ static bool AllocateEnv()
}

SQLPOINTER defaultVersion = (SQLPOINTER)SQL_OV_ODBC3;
#ifdef SQL_OV_ODBC3_80
PyObject* odbcversion = PyObject_GetAttrString(pModule, "odbcversion");
if (PyObject_TypeCheck(odbcversion, &PyUnicode_Type)) {
if (PyUnicode_CompareWithASCIIString(odbcversion, "3.8") == 0)
Expand All @@ -311,7 +312,7 @@ static bool AllocateEnv()
}
}
Py_DECREF(odbcversion);

#endif
if (!SQL_SUCCEEDED(SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, defaultVersion, sizeof(int))))
{
PyErr_SetString(PyExc_RuntimeError, "Unable to set SQL_ATTR_ODBC_VERSION attribute.");
Expand Down

0 comments on commit df57ccd

Please sign in to comment.