microsoft/mssql-python

Support params dict

amachanic opened this issue · 2 comments

Instead of forcing ordered params, can you also allow a dict? This is a fairly common convention in Python DB libraries (see psycopg and pymssql for example) and is much nicer than passing a tuple.

Example:

cursor.execute(
    'select * from tbl where col1 = @a and col2 = @b',
    {'@a': 123, '@b': 234}
)

Note on this example: Many libraries (psycopg in particular) instead use a format like the following. I think that format would be useful too, but as SQL Server's variables are much more flexible it would be great to support them natively as in the above.

cursor.execute(
    'select * from tbl where col1 = %(a)s and col2 = %(b)s',
    {'a': 123, 'b': 234}
)

Thank you!

I second this a lot!