CData Python Connector for Office 365 2019 - Online Help
Questions / Feedback?

Querying Data

CData Python Connector for Office 365 2019 - Build 19.0.7416

After connecting with the steps in Connecting, you can execute a SQL statements using the connection's cursor object.

Executing Queries

To execute SQL statements that return data, use the cursor object's 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:

import cdata.office365 as mod
conn = mod.connect("InitiateOAuth=GETANDREFRESH;OAuthClientId=MyApplicationId;OAuthClientSecret=MySecretKey;CallbackURL=http://localhost:33333;")
cur = conn.cursor()
cur.execute("SELECT Id, location_displayName FROM Events")
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:

import cdata.office365 as mod
conn = mod.connect("InitiateOAuth=GETANDREFRESH;OAuthClientId=MyApplicationId;OAuthClientSecret=MySecretKey;CallbackURL=http://localhost:33333;")
cur = conn.cursor()
cmd = "SELECT Id, location_displayName FROM Events WHERE Id = ?"
params = ["Jq74mCczmFXk1tC10GB"]
cur.execute(cmd, params)
rs = cur.fetchall()
for row in rs:
	print(row)

 
 
Copyright (c) 2020 CData Software, Inc. - All rights reserved.
Build 19.0.7416.0