CData Python Connector for Access

Build 21.0.7930

Batch Processing

This python connector is also able to perform batch processing to write to the data source. This can 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. Do not call the connection's commit() method following the execution.

Insert

The following example adds new records to the table:

cur = conn.cursor()
cmd = "INSERT INTO Orders (ShipName, ShipCity) VALUES (?, ?)"
params = [["Raleigh", "New York"], ["Raleigh", "New York"]]
cur.executemany(cmd, params)
print("Records affected: ", cur.rowcount)

Update

The following example modifies existing records in the table:

cur = conn.cursor()
cmd = "UPDATE Orders SET ShipCity = ? WHERE Id = ?"
params = [["New York", "10261"], ["New York", "10261"]]
cur.executemany(cmd, params)
print("Records affected: ", cur.rowcount)

Delete

The following example removes existing records from the table:

cur = conn.cursor()
cmd = "DELETE FROM Orders WHERE Id = ?"
params = [["10261"], ["10261"]]
cur.executemany(cmd, params)
print("Records affected: ", cur.rowcount)

Copyright (c) 2021 CData Software, Inc. - All rights reserved.
Build 21.0.7930