Support for pyodbc.Cursor.execute with 0 or more parameters #1235
-
Environment
IssueIf 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').
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 ? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
sql = "SELECT 1 AS foo"
crsr.execute(sql, None) is equivalent to sql = "SELECT 1 AS foo"
crsr.execute(sql, (None,)) which are both ways to pass a single parameter value of
|
Beta Was this translation helpful? Give feedback.
is equivalent to
which are both ways to pass a single parameter value of
None
(which maps to SQLNULL
). To pass no parameters, simply use an empty tuple