CData Python Connector for OData

Build 20.0.7587

Batch Processing

This python connector is also able to perform batch processing to write to the data source. This ca be done by using the executemany() method of the cursor object. In addition to a SQL statement string, a data frame of values should be provided as a series of parameters to execute the SQL statement with. as with normal write operations, the statements are executed immediately by the provider, making a call to the connection's commit() method unnecessary.

Insert

The following example adds new records to the table:

import cdata.odata as drv
conn = drv.connect("User=myuseraccount;Password=mypassword;URL=http://myserver/myOrgRoot;")
cur = conn.cursor()
cmd = "INSERT INTO Lead (Id, FullName) VALUES (?, ?)"
params = [["Jon Doe", "John"], ["Jon Doe", "John"]]
cur.executemany(cmd, params)
print("Records affected: ", cur.rowcount)

Update

The following example modifies existing records in the table:

import cdata.odata as drv
conn = drv.connect("User=myuseraccount;Password=mypassword;URL=http://myserver/myOrgRoot;")
cur = conn.cursor()
cmd = "UPDATE Lead SET FullName = ? WHERE Id = ?"
params = [["John", "1045625d-99ee-e011-a272-00155d01ad6b"], ["John", "1045625d-99ee-e011-a272-00155d01ad6b"]]
cur.executemany(cmd, params)
print("Records affected: ", cur.rowcount)

Delete

The following example removes existing records from the table:

import cdata.odata as drv
conn = drv.connect("User=myuseraccount;Password=mypassword;URL=http://myserver/myOrgRoot;")
cur = conn.cursor()
cmd = "DELETE FROM Lead WHERE Id = ?"
params = [["1045625d-99ee-e011-a272-00155d01ad6b"], ["1045625d-99ee-e011-a272-00155d01ad6b"]]
cur.executemany(cmd, params)
print("Records affected: ", cur.rowcount)

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