ODBC Driver for Tableau CRM Analytics

Build 24.0.9060

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 Name, CloseDate FROM Dataset_Opportunity WHERE StageName = ?", ("Closed Won",))
for (Name, CloseDate) in cursor:
    print("Name = {}, CloseDate = {}".format(Name, CloseDate))

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 = [
  ("1-1-2018 1",),
  ("1-1-2018 2",),
  ("1-1-2018 3",),
]

cursor.executemany("INSERT INTO Dataset_Opportunity (CloseDate) VALUES (?)", params)

Copyright (c) 2024 CData Software, Inc. - All rights reserved.
Build 24.0.9060