8000 Support params dict · Issue #20 · microsoft/mssql-python · GitHub
[go: up one dir, main page]

Skip to content

Support params dict #20

@amachanic

Description

@amachanic

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0