CData Python Connector for Google Analytics

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.googleanalytics as mod
conn = mod.connect("InitiateOAuth=GETANDREFRESH;Profile=myProfile;")
cur = conn.cursor()
cur.execute("SELECT Browser, DeviceCategory FROM Traffic")
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.googleanalytics as mod
conn = mod.connect("InitiateOAuth=GETANDREFRESH;Profile=myProfile;")
cur = conn.cursor()
cmd = "SELECT Browser, DeviceCategory FROM Traffic WHERE Transactions > ?"
params = ["0"]
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