CData Python Connector for FreshBooks

Build 20.0.7587

Querying Data

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.freshbooks as mod
conn = mod.connect("InitiateOAuth=GETANDREFRESH;OAuthClientId=MyClientId;OAuthClientSecret=MyClientSecret;CallbackURL=http://localhost:33333")
cur = conn.cursor()
cur.execute("SELECT Email, Username FROM Clients")
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.freshbooks as mod
conn = mod.connect("InitiateOAuth=GETANDREFRESH;OAuthClientId=MyClientId;OAuthClientSecret=MyClientSecret;CallbackURL=http://localhost:33333")
cur = conn.cursor()
cmd = "SELECT Email, Username FROM Clients WHERE Email = ?"
params = ["support@mycompany.com"]
cur.execute(cmd, params)
rs = cur.fetchall()
for row in rs:
	print(row)

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