CData Python Connector for Microsoft Dynamics 365

Build 22.0.8462

Querying Data

After connecting with the steps in Connecting, you can execute a SQL statements using the open connection.

Executing Queries

To execute SQL statements that return data, use the execute method. Once a query is executed, the result set is fetched from the cursor. This result set can then be iterated over to process the records individually:

cur = conn.execute("SELECT GoalHeadingId, GoalHeadingId FROM GoalHeadings")
rs = cur.fetchall()
for row in rs:
	print(row)

Parameterized Queries

Various python collections, such as arrays and tuples are provided as additional arguments for the execute method. This allows you to parameterize the queries executed and help to prevent SQL Injection:

cmd = "SELECT GoalHeadingId, GoalHeadingId FROM GoalHeadings WHERE Name <> ?"
params = ["MyAccount"]
cur = conn.execute(cmd, params)
rs = cur.fetchall()
for row in rs:
	print(row)

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