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 GoalHeadings (GoalHeadingId, GoalHeadingId) 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:
cur = conn.cursor() cmd = "UPDATE GoalHeadings SET GoalHeadingId = ? WHERE GoalHeadingId = ?" params = [["John", "'test'"], ["John", "'test'"]] 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 GoalHeadings WHERE GoalHeadingId = ?" params = [["'test'"], ["'test'"]] cur.executemany(cmd, params) print("Records affected: ", cur.rowcount)