CData Python Connector for OData

Build 20.0.7587

Updating Data

The connection's cursor object is used to issue INSERT, UPDATE, and DELETE commands to the data source. If desired, parameters are used with these statements. Unlike many python connectors, this connector does not support transactions. Consequently, any SQL statements executed by this connector affect the data source immediately. So, the commit() method on the connection object should not be used.

Insert

The following example adds a new record to the table:

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

Update

The following example modifies an existing record in the table:

import cdata.odata as mod
conn = mod.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"]
cur.execute(cmd, params)
print("Records affected: ", cur.rowcount)

Delete

The following example removes an existing record from the table:

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

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