ODBC Driver for Azure Active Directory

Build 22.0.8509

Parameterized Statements

The following code example shows how to bind parameters to create parameterized statements.

Single-Use Statements

The execute method accepts an additional sequence for binding query parameters to values.

cursor.execute("SELECT Id, displayName FROM DirectoryRoles WHERE Id = ?", ("Jq74mCczmFXk1tC10GBs",))
for (Id, displayName) in cursor:
    print("Id = {}, displayName = {}".format(Id, displayName))

Multi-Use Statements

The executemany method can be used to execute the same query repeatedly with different sets of parameters. Instead of a sequence of parameters, executemany accepts a nested sequence of parameters which are used for each execution.

executemany works only with INSERT, UPDATE and DELETE statements. It cannot be used with any operation that returns results, such as a SELECT or an EXECUTE.

params = [
  ("Global Reader 1",),
  ("Global Reader 2",),
  ("Global Reader 3",),
]

cursor.executemany("INSERT INTO DirectoryRoles(displayName) VALUES (?)", params)

Copyright (c) 2023 CData Software, Inc. - All rights reserved.
Build 22.0.8509