mkleehammer / pyodbc

Python ODBC bridge
https://github.com/mkleehammer/pyodbc/wiki
MIT No Attribution
2.95k stars 563 forks source link

Support for pyodbc.Cursor.execute with 0 or more parameters #1234

Closed CapAdv closed 1 year ago

CapAdv commented 1 year ago

Environment

Issue

If I execute an sql command (its MS SQL Server 2016 as specified above) using pyodbc and pass 'None' as the parameters, I'm expecting it to run a command that takes no parameters, like "waitfor delay '00:00:10'" without error, but actually it gives:

pyodbc.ProgrammingError: ('The SQL contains 0 parameter markers, but 1 parameters were supplied', 'HY000').

sql = "waitfor delay '00:00:10'"
sql_params = None
with pyodbc.connect(settings.Application_Conn, autocommit=True) as conn:
    crsr = conn.cursor()
    crsr.execute(sql, sql_params)

Is there a way using pyodbc to include the sql_params parameter in the crsr.execute but allow it to be 'empty' somehow and not fail when called against a command which takes no parameters, or maybe this is already possible ?