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.oraclesalescloud as drv conn = drv.connect("HostURL=https://my.host.oraclecloud.com; Username=abc123; Password=abcdef;") cur = conn.cursor() cmd = "INSERT INTO Opportunities (OptyId, Name) VALUES (?, ?)" params = [["Commercial Oppty", "Residential Oppty"], ["Commercial Oppty", "Residential Oppty"]] cur.executemany(cmd, params) print("Records affected: ", cur.rowcount)
Update
The following example modifies existing records in the table:
import cdata.oraclesalescloud as drv conn = drv.connect("HostURL=https://my.host.oraclecloud.com; Username=abc123; Password=abcdef;") cur = conn.cursor() cmd = "UPDATE Opportunities SET Name = ? WHERE Id = ?" params = [["Residential Oppty", "300000002693011"], ["Residential Oppty", "300000002693011"]] cur.executemany(cmd, params) print("Records affected: ", cur.rowcount)
Delete
The following example removes existing records from the table:
import cdata.oraclesalescloud as drv conn = drv.connect("HostURL=https://my.host.oraclecloud.com; Username=abc123; Password=abcdef;") cur = conn.cursor() cmd = "DELETE FROM Opportunities WHERE Id = ?" params = [["300000002693011"], ["300000002693011"]] cur.executemany(cmd, params) print("Records affected: ", cur.rowcount)