diff --git a/pyodbc-4.0.30-PyUnicode_AsUTF8String.patch b/pyodbc-4.0.30-PyUnicode_AsUTF8String.patch new file mode 100644 index 0000000..a2592fa --- /dev/null +++ b/pyodbc-4.0.30-PyUnicode_AsUTF8String.patch @@ -0,0 +1,103 @@ +From 3a8a947e41ae1cd5fb109fe07f85a4299ff5a77a Mon Sep 17 00:00:00 2001 +From: Inada Naoki +Date: Mon, 29 Jun 2020 10:56:38 +0900 +Subject: [PATCH 1/3] Use PyUnicode_AsUTF8String + +PyUnicode_EncodeUTF8 is deprecated, and PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(p), ...) is inefficient. +--- + src/cnxninfo.cpp | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/cnxninfo.cpp b/src/cnxninfo.cpp +index 9934feec..99ce33bd 100644 +--- a/src/cnxninfo.cpp ++++ b/src/cnxninfo.cpp +@@ -42,7 +42,7 @@ bool CnxnInfo_init() + static PyObject* GetHash(PyObject* p) + { + #if PY_MAJOR_VERSION >= 3 +- Object bytes(PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(p), PyUnicode_GET_SIZE(p), 0)); ++ Object bytes(PyUnicode_AsUTF8String(p)); + if (!bytes) + return 0; + p = bytes.Get(); + +From 09864fb7a39ed81d6d0c360ffd796e858e1197d5 Mon Sep 17 00:00:00 2001 +From: Inada Naoki +Date: Sun, 5 Jul 2020 16:06:48 +0900 +Subject: [PATCH 2/3] Fix ExecuteMulti too + +--- + src/params.cpp | 24 +++++++++++++++++++++--- + 1 file changed, 21 insertions(+), 3 deletions(-) + +diff --git a/src/params.cpp b/src/params.cpp +index 20548c2d..108ba02f 100644 +--- a/src/params.cpp ++++ b/src/params.cpp +@@ -1921,9 +1921,10 @@ bool ExecuteMulti(Cursor* cur, PyObject* pSql, PyObject* paramArrayObj) + if (PyUnicode_Check(objCell)) + { + const TextEnc& enc = cur->cnxn->sqlwchar_enc; +- int cb = PyUnicode_GET_DATA_SIZE(objCell) / 2; +- + PyObject* bytes = NULL; ++ ++#if PY_MAJOR_VERSION < 3 ++ int cb = PyUnicode_GET_DATA_SIZE(objCell) / 2; + const Py_UNICODE* source = PyUnicode_AS_UNICODE(objCell); + + switch (enc.optenc) +@@ -1941,11 +1942,28 @@ bool ExecuteMulti(Cursor* cur, PyObject* pSql, PyObject* paramArrayObj) + bytes = PyUnicode_EncodeUTF16(source, cb, "strict", BYTEORDER_BE); + break; + } +- ++#else ++ switch (enc.optenc) ++ { ++ case OPTENC_UTF8: ++ bytes = PyUnicode_AsUTF8String(objCell); ++ break; ++ case OPTENC_UTF16: ++ bytes = PyUnicode_AsUTF16String(objCell); ++ break; ++ case OPTENC_UTF16LE: ++ bytes = PyUnicode_AsEncodedString(objCell, "utf_16_le", NULL); ++ break; ++ case OPTENC_UTF16BE: ++ bytes = PyUnicode_AsEncodedString(objCell, "utf_16_be", NULL); ++ break; ++ } ++#endif + if (bytes && PyBytes_Check(bytes)) + { + objCell = bytes; + } ++ //TODO: Raise or clear error when bytes == NULL. + } + + szLastFunction = "SQLPutData"; + +From 8b0aaf0d8c001c1baad229259805f7d5a85b4aad Mon Sep 17 00:00:00 2001 +From: Keith Erskine +Date: Sat, 5 Feb 2022 19:18:24 -0600 +Subject: [PATCH 3/3] benign commit to trigger build tests + +--- + src/errors.h | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/errors.h b/src/errors.h +index 771c2696..6ce8d79d 100644 +--- a/src/errors.h ++++ b/src/errors.h +@@ -61,7 +61,7 @@ inline PyObject* RaiseErrorFromException(PyObject* pError) + #if PY_MAJOR_VERSION >= 3 + PyErr_SetObject((PyObject*)Py_TYPE(pError), pError); + #else +- PyObject* cls = (PyObject*)((PyInstance_Check(pError) ? (PyObject*)((PyInstanceObject*)pError)->in_class : (PyObject*)(Py_TYPE(pError)))); ++ PyObject* cls = (PyObject*)((PyInstance_Check(pError) ? (PyObject*)((PyInstanceObject*)pError)->in_class : (PyObject*)(Py_TYPE(pError)))); + PyErr_SetObject(cls, pError); + #endif + return 0; diff --git a/pyodbc.spec b/pyodbc.spec index c5bfb5c..caea55a 100644 --- a/pyodbc.spec +++ b/pyodbc.spec @@ -1,8 +1,6 @@ -%global modulename pyodbc - Name: pyodbc Version: 4.0.30 -Release: 6%{?dist} +Release: 7%{?dist} Summary: Python DB API 2.0 Module for ODBC License: MIT URL: https://github.com/mkleehammer/pyodbc @@ -12,6 +10,8 @@ BuildRequires: unixODBC-devel BuildRequires: python3-devel BuildRequires: python3-setuptools +Patch0: pyodbc-4.0.30-PyUnicode_AsUTF8String.patch + Recommends: (postgresql-odbc if postgresql-server) Recommends: (mariadb-connector-odbc if mariadb-server) @@ -22,20 +22,19 @@ decimal. %description %_description -%package -n python3-%{modulename} +%package -n python3-%{name} Summary: Python DB API 2.0 Module for ODBC -%{?python_provide:%python_provide python3-%{modulename}} +%{?python_provide:%python_provide python3-%{name}} Recommends: (mariadb-connector-odbc if mariadb-server) Recommends: (postgresql-odbc if postgresql-server) -%description -n python3-%{modulename} +%description -n python3-%{name} A Python DB API 2 and 3 module for ODBC. This project provides an up-to-date, convenient interface to ODBC using native data types like datetime and decimal. - %prep -%setup -q +%autosetup -n %{name}-%{version} -p1 %build %py3_build @@ -49,6 +48,11 @@ decimal. %{python3_sitearch}/* %changelog +* Tue Jun 28 2022 Ondrej Sloup - 4.0.30-7 +- Use autosetup +- Use name macro +- Fix pyodbc fails to build with Python 3.11: error: PyUnicode_EncodeUTF8 (#2049428) + * Mon Jun 13 2022 Python Maint - 4.0.30-6 - Rebuilt for Python 3.11