Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrieve a query as a NumPy structured array #1156

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
53db7b5
WIP: Started porting build and PostgreSQL tests to py3
mkleehammer Nov 19, 2022
f141582
WIP: First pass at removing Python version macros.
mkleehammer Nov 20, 2022
e60427f
Rewrote Row.__repr__ due to memory errors
mkleehammer Nov 20, 2022
a252c47
WIP: Eliminate compat module. Convert mem calls to PyMem.
mkleehammer Nov 20, 2022
ae5990a
Replace assert macros with assert
mkleehammer Nov 20, 2022
e6fc6e8
WIP: Started eliminating deprecated Unicode API
mkleehammer Nov 20, 2022
a755fed
Delete raw encoding and ODBCCHAR.
mkleehammer Nov 21, 2022
080d608
Minor unicode and warning cleanups
mkleehammer Jan 2, 2023
58c2461
Fixed removal of ansi keyword.
mkleehammer Jan 2, 2023
d6d6a40
WIP
mkleehammer Apr 14, 2023
0276209
Reapplied decimal parsing rewrite
mkleehammer Apr 2, 2023
f871a47
Comment out fastexecute temporarily.
mkleehammer May 9, 2023
0388b96
Remove tests3 directory
mkleehammer May 9, 2023
592f36f
Rename pytest tests. Minor fixes.
mkleehammer Aug 22, 2023
b350fce
Ported mysql tests to pytest
mkleehammer Aug 24, 2023
da2906d
Update Github actions to drop old versions of Python
mkleehammer Aug 24, 2023
89a6f63
Update Github actions to use pytest
mkleehammer Aug 24, 2023
0f8e67f
Move unported tests to an "old" directory.
mkleehammer Aug 24, 2023
e464f66
Add tests.__init__.py back
mkleehammer Aug 24, 2023
2d337cb
Temporarily remove SQL Server tests
mkleehammer Aug 24, 2023
3205fb4
Initial port of SQL Server tests
mkleehammer Aug 25, 2023
262662c
Fix Github ubuntu build file
mkleehammer Aug 25, 2023
738a5b9
Remove Python 2.7 from Appveyor
mkleehammer Aug 25, 2023
96a48a8
Updated Github ubuntu build action with SQL Server 14
mkleehammer Aug 25, 2023
f2f5125
Fix Python 3.7 incompatibility.
mkleehammer Aug 25, 2023
74cfb2c
add npcontainer.cpp
ilanschnell Dec 10, 2019
fc394e8
only attempt to compile npcontainer when numpy is installed
ilanschnell Dec 11, 2019
3386185
add missing defines in npcontainer.cpp
ilanschnell Dec 11, 2019
5c94b81
remove unused fetchsarray
ilanschnell Dec 11, 2019
5423551
add missing call to NpContainer_init()
ilanschnell Dec 12, 2019
be01a68
add comment about use_unicode in npcontainer.cpp
ilanschnell Dec 12, 2019
5a32e62
minor cleanup
ilanschnell Dec 13, 2019
ec7aaa7
fix declaration of fetchdictarray_doc in npcontainer.h
ilanschnell Jan 16, 2020
68cfccf
move headers in order to compile on certain systems
ilanschnell Jan 23, 2020
8b6f990
use dynamic text size limit, see comment
ilanschnell May 12, 2022
761a5e0
Allow Python exception
Apr 21, 2023
fa68917
update segfault error propagation
ndmlny-qs Jul 18, 2023
97da475
remove macOS ARM64 builds (#1247)
keitherskine Aug 5, 2023
ea1d83c
Fix merge conflict flags
ndmlny-qs Aug 25, 2023
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
4 changes: 3 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ ignore =
E221,
# multi spaces before op - I line up assignments often
E401,
# multiple imports on one line
# multiple imports on one line
E722,
# ignore bare except in tests
9 changes: 6 additions & 3 deletions .github/workflows/artifacts_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ jobs:
strategy:
matrix:
# https://docs.github.com/en/actions/using-jobs/choosing-the-runner-for-a-job
# ubuntu-20.04 supports more versions of Python than ubuntu-22.04
# https://raw.githubusercontent.com/actions/python-versions/main/versions-manifest.json
os: [windows-2019, macos-11, ubuntu-20.04]

steps:
Expand All @@ -45,14 +47,15 @@ jobs:
platforms: all

- name: Build wheels
uses: pypa/cibuildwheel@v2.11.2
uses: pypa/cibuildwheel@v2.13.1
# https://cibuildwheel.readthedocs.io/en/stable/options/#options-summary
env:
# Windows - both 64-bit and 32-bit builds
CIBW_ARCHS_WINDOWS: "AMD64 x86"

# macOS - both Intel and ARM builds; no bundled libraries
CIBW_ARCHS_MACOS: "x86_64 arm64"
# macOS - just Intel build (ARM doesn't work); no bundled libraries
# https://cibuildwheel.readthedocs.io/en/stable/faq/#how-to-cross-compile
CIBW_ARCHS_MACOS: x86_64
# prevent the addition of unixODBC dylibs to the wheel by simply not calling the repair
CIBW_REPAIR_WHEEL_COMMAND_MACOS: ""

Expand Down
49 changes: 23 additions & 26 deletions .github/workflows/ubuntu_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,14 @@ on: [push, pull_request]
jobs:
run_tests:
name: Run tests on Python ${{ matrix.python-version }}
# ubuntu-20.04 supports more versions of Python than ubuntu-22.04
# https://raw.githubusercontent.com/actions/python-versions/main/versions-manifest.json
runs-on: ubuntu-20.04

strategy:
fail-fast: false
matrix:
include:
- python-version: "2.7"
tests-dir: tests2
- python-version: "3.6"
tests-dir: tests3
- python-version: "3.7"
tests-dir: tests3
- python-version: "3.8"
tests-dir: tests3
- python-version: "3.9"
tests-dir: tests3
- python-version: "3.10"
tests-dir: tests3
- python-version: "3.11"
tests-dir: tests3
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]

services:

Expand Down Expand Up @@ -161,15 +149,16 @@ jobs:
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install Python dependencies
- name: Install Python dev dependencies
# pyodbc doesn't have any Python dependencies, but we do need pytest for testing.
run: |
cd "$GITHUB_WORKSPACE"
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi

- name: Build and install pyodbc
run: |
Expand All @@ -185,22 +174,30 @@ jobs:
echo "*** pyodbc drivers"
python -c "import pyodbc; print('\n'.join(sorted(pyodbc.drivers())))"

- name: Run SQL Server 2017 tests
- name: Run PostgreSQL tests
env:
PYODBC_POSTGRESQL: "DRIVER={PostgreSQL Unicode};SERVER=localhost;PORT=5432;UID=postgres_user;PWD=postgres_pwd;DATABASE=test"
run: |
cd "$GITHUB_WORKSPACE"
python "./${{ matrix.tests-dir }}/sqlservertests.py" "DRIVER={ODBC Driver 17 for SQL Server};SERVER=localhost,1401;UID=sa;PWD=StrongPassword2017;DATABASE=test"
pytest "./tests/postgresql_test.py"

- name: Run SQL Server 2019 tests
- name: Run MySQL tests
env:
PYODBC_MYSQL: "DRIVER={MySQL ODBC 8.0 ANSI Driver};SERVER=localhost;UID=root;PWD=root;DATABASE=test;CHARSET=utf8mb4"
run: |
cd "$GITHUB_WORKSPACE"
python "./${{ matrix.tests-dir }}/sqlservertests.py" "DRIVER={ODBC Driver 18 for SQL Server};SERVER=localhost,1402;UID=sa;PWD=StrongPassword2019;DATABASE=test;Encrypt=Optional"
pytest "./tests/mysql_test.py"

- name: Run PostgreSQL tests
- name: Run SQL Server 2017 tests
env:
PYODBC_SQLSERVER: "DRIVER={ODBC Driver 17 for SQL Server};SERVER=localhost,1401;UID=sa;PWD=StrongPassword2017;DATABASE=test"
run: |
cd "$GITHUB_WORKSPACE"
python "./${{ matrix.tests-dir }}/pgtests.py" "DRIVER={PostgreSQL Unicode};SERVER=localhost;PORT=5432;UID=postgres_user;PWD=postgres_pwd;DATABASE=test"
python "./tests/sqlserver_test.py"

- name: Run MySQL tests
- name: Run SQL Server 2019 tests
env:
PYODBC_SQLSERVER: "DRIVER={ODBC Driver 18 for SQL Server};SERVER=localhost,1402;UID=sa;PWD=StrongPassword2019;DATABASE=test;Encrypt=Optional"
run: |
cd "$GITHUB_WORKSPACE"
python "./${{ matrix.tests-dir }}/mysqltests.py" "DRIVER={MySQL ODBC 8.0 ANSI Driver};SERVER=localhost;UID=root;PWD=root;DATABASE=test;CHARSET=utf8mb4"
python "./tests/sqlserver_test.py"
28 changes: 28 additions & 0 deletions HACKING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@


# Development Testing

We use tox for complete testing, but when you are in the middle of development you need fast
turn around. In this mode you need to be able to build and run tests using pytest manually.
To do this, build from the root of the directory using `--inplace` which will build the library
into the root. Run pytest from the same root directory and the new pyodbc library you built
will be in the path for your test:

python setup.py build_ext --inplace
pytest test/test_postgresql.py -vxk test_text

If a segmentation fault occurs while running tests, pytest will have eaten the output. Add
-s to the command line:

python setup.py build_ext --inplace -D PYODBC_TRACE
pytest test/test_postgresql.py -vxk test_text -vs


# Notes

## uint16_t

You'll notice we use uint16_t instead of SQLWCHAR. The unixODBC headers would define SQLWCHAR
as wchar_t even when wchar_t as defined by the C library as uint32_t. The data in the buffer
was still 16 bit however.

9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# pyodbc

[![AppVeyor](https://ci.appveyor.com/api/projects/status/github/mkleehammer/pyodbc?branch=master&svg=true&passingText=Windows%20build&failingText=Windows%20build)](https://ci.appveyor.com/project/mkleehammer/pyodbc)
[![Github Actions - Ubuntu Build](https://github.com/mkleehammer/pyodbc/actions/workflows/ubuntu_build.yml/badge.svg?branch=master)](https://github.com/mkleehammer/pyodbc/actions/workflows/ubuntu_build.yml)
[![Ubuntu build](https://github.com/mkleehammer/pyodbc/actions/workflows/ubuntu_build.yml/badge.svg)](https://github.com/mkleehammer/pyodbc/actions/workflows/ubuntu_build.yml)
[![PyPI](https://img.shields.io/pypi/v/pyodbc?color=brightgreen)](https://pypi.org/project/pyodbc/)

pyodbc is an open source Python module that makes accessing ODBC databases simple. It
implements the [DB API 2.0](https://www.python.org/dev/peps/pep-0249) specification but is
packed with even more Pythonic convenience.
implements the [DB API 2.0](https://www.python.org/dev/peps/pep-0249) specification but is packed with even more Pythonic convenience.

The easiest way to install pyodbc is to use pip:

Expand All @@ -31,6 +29,3 @@ compiler. See the [docs](https://github.com/mkleehammer/pyodbc/wiki/Install) fo
[Documentation](https://github.com/mkleehammer/pyodbc/wiki)

[Release Notes](https://github.com/mkleehammer/pyodbc/releases)

IMPORTANT: Python 2.7 support is being ended. The pyodbc 4.x versions will be the last to
support Python 2.7. The pyodbc 5.x versions will support only Python 3.7 and above.
17 changes: 0 additions & 17 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,6 @@ environment:
# all the Python versions to be tested, both 32-bit and 64-bit
# ref: https://www.appveyor.com/docs/windows-images-software/#python

# Python 2.7 must be built with Visual Studio 9.0, which is available only
# on AppVeyor Windows images Visual Studio 2013 and Visual Studio 2015

- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
PYTHON_HOME: "C:\\Python27"

- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
PYTHON_HOME: "C:\\Python27-x64"

# Python 3.5+ need at least the Visual Studio 2015 image

- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
PYTHON_HOME: "C:\\Python36"

- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
PYTHON_HOME: "C:\\Python36-x64"

- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
PYTHON_HOME: "C:\\Python37"

Expand Down
13 changes: 0 additions & 13 deletions appveyor/after_test.cmd

This file was deleted.

80 changes: 0 additions & 80 deletions appveyor/compile.cmd

This file was deleted.

4 changes: 0 additions & 4 deletions appveyor/test_connect.py

This file was deleted.

21 changes: 6 additions & 15 deletions appveyor/test_script.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,9 @@ IF NOT "%APVYR_RUN_TESTS%" == "true" (
)


REM Extract the major version of the current Python interpreter, and bitness
FOR /F "tokens=* USEBACKQ" %%F IN (`%PYTHON_HOME%\python -c "import sys; sys.stdout.write(str(sys.version_info.major))"`) DO (
SET PYTHON_MAJOR_VERSION=%%F
)
FOR /F "tokens=* USEBACKQ" %%F IN (`%PYTHON_HOME%\python -c "import sys; sys.stdout.write('64' if sys.maxsize > 2**32 else '32')"`) DO (
SET PYTHON_ARCH=%%F
)
IF %PYTHON_MAJOR_VERSION% EQU 2 (
SET TESTS_DIR=tests2
) ELSE (
SET TESTS_DIR=tests3
)


:mssql
Expand Down Expand Up @@ -68,7 +59,7 @@ SET PYTHON_ARGS="%CONN_STR:"=\"%"
IF "%APVYR_VERBOSE%" == "true" (
SET PYTHON_ARGS=%PYTHON_ARGS% --verbose
)
"%PYTHON_HOME%\python" "%TESTS_DIR%\sqlservertests.py" %PYTHON_ARGS%
"%PYTHON_HOME%\python" "tests\sqlserver_test.py" %PYTHON_ARGS%
IF ERRORLEVEL 1 SET OVERALL_RESULT=1

:mssql2
Expand All @@ -88,7 +79,7 @@ SET PYTHON_ARGS="%CONN_STR:"=\"%"
IF "%APVYR_VERBOSE%" == "true" (
SET PYTHON_ARGS=%PYTHON_ARGS% --verbose
)
"%PYTHON_HOME%\python" "%TESTS_DIR%\sqlservertests.py" %PYTHON_ARGS%
"%PYTHON_HOME%\python" "tests\sqlserver_test.py" %PYTHON_ARGS%
IF ERRORLEVEL 1 SET OVERALL_RESULT=1

:mssql3
Expand All @@ -107,7 +98,7 @@ SET PYTHON_ARGS="%CONN_STR:"=\"%"
IF "%APVYR_VERBOSE%" == "true" (
SET PYTHON_ARGS=%PYTHON_ARGS% --verbose
)
"%PYTHON_HOME%\python" "%TESTS_DIR%\sqlservertests.py" %PYTHON_ARGS%
"%PYTHON_HOME%\python" "tests\sqlserver_test.py" %PYTHON_ARGS%
IF ERRORLEVEL 1 SET OVERALL_RESULT=1

:mssql4
Expand All @@ -126,7 +117,7 @@ SET PYTHON_ARGS="%CONN_STR:"=\"%"
IF "%APVYR_VERBOSE%" == "true" (
SET PYTHON_ARGS=%PYTHON_ARGS% --verbose
)
"%PYTHON_HOME%\python" "%TESTS_DIR%\sqlservertests.py" %PYTHON_ARGS%
"%PYTHON_HOME%\python" "tests\sqlserver_test.py" %PYTHON_ARGS%
IF ERRORLEVEL 1 SET OVERALL_RESULT=1

:mssql5
Expand All @@ -145,7 +136,7 @@ SET PYTHON_ARGS="%CONN_STR:"=\"%"
IF "%APVYR_VERBOSE%" == "true" (
SET PYTHON_ARGS=%PYTHON_ARGS% --verbose
)
"%PYTHON_HOME%\python" "%TESTS_DIR%\sqlservertests.py" %PYTHON_ARGS%
"%PYTHON_HOME%\python" "tests\sqlserver_test.py" %PYTHON_ARGS%
IF ERRORLEVEL 1 SET OVERALL_RESULT=1

:mssql6
Expand All @@ -164,7 +155,7 @@ SET PYTHON_ARGS="%CONN_STR:"=\"%"
IF "%APVYR_VERBOSE%" == "true" (
SET PYTHON_ARGS=%PYTHON_ARGS% --verbose
)
"%PYTHON_HOME%\python" "%TESTS_DIR%\sqlservertests.py" %PYTHON_ARGS%
"%PYTHON_HOME%\python" "tests\sqlserver_test.py" %PYTHON_ARGS%
IF ERRORLEVEL 1 SET OVERALL_RESULT=1


Expand Down
12 changes: 12 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# https://pip.pypa.io/en/stable/reference/requirements-file-format/
# https://peps.python.org/pep-0508/
# https://peps.python.org/pep-0440/

setuptools ~= 67.7
pytest ~= 7.3

# I'm going to try leaving the versions off since we're supporting drastically different Python
# versions. I want the most up to date I can get in each, at least until one of them makes a
# backwards incompatible change.
flake8
pylint
1 change: 0 additions & 1 deletion requirements-test.txt

This file was deleted.

Loading