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

Cannot parameterize SQL with strings using pyodbc #49

Open
mtslaugh opened this issue Dec 30, 2024 · 0 comments
Open

Cannot parameterize SQL with strings using pyodbc #49

mtslaugh opened this issue Dec 30, 2024 · 0 comments

Comments

@mtslaugh
Copy link

What happens?

Executing parameterized SQL with pyodbc fails when the parameters are provided as python strings, but works as expected when parameters are provided as numeric values.

To Reproduce

Execute a parameterized query via pyodbc and specify the parameter as a string:

import pyodbc

cnxn = pyodbc.connect('DSN=DuckDB')
cursor = cnxn.cursor()

cursor.execute("CREATE TABLE fuu (j STRING)")
cursor.execute("INSERT INTO fuu VALUES (?)", 'Hello')
cursor.execute("SELECT * FROM fuu")
result = cursor.fetchall()
print(result)

This produces the following error:

pyodbc.Error: ('01000', '[01000] ODBC_DuckDB->GetParamValues\nFailed to set parameter value (0) (SQLExecDirectW)')

To confirm that it does work with numeric values:

import pyodbc

cnxn = pyodbc.connect('DSN=DuckDB')
cursor = cnxn.cursor()

cursor.execute("CREATE TABLE fuu (i INTEGER)")
cursor.execute("INSERT INTO fuu VALUES (?)", 42)
cursor.execute("SELECT * FROM fuu")
result = cursor.fetchall()
print(result)

Outputs [(42,)] as expected.

OS:

Windows 11 x64 version 10.1.26100

DuckDB Version:

v1.1.3 (nightly build as of 2024-12-29)

DuckDB Client:

ODBC

Hardware:

Intel Core i7-9750H CPU @ 2.6GHz × 6 , 16 GB Memory

Python environment:

Anaconda Python version 3.13.1, pyodbc version 5.2.0

Name:

Matthew T. Slaughter

Affiliation:

Kaiser Permanente

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant