Obtaining the Row Count Using TD_Evt_ApplyCount
The event TD_Evt_ApplyCount can be used to query the Stream driver for the number of inserts, updates, and deletes performed by each DML Group in the job. The index parameter in the GetEvent method is used to indicate the data’s DML Group. The index that is passed to the GetEvent method is the same index that is returned by the AddDMLGroup method for the desired DML Group. This is different from the way the Update driver returns the number of rows inserted, updated, and deleted. The Update driver uses the index parameter in the GetEvent method to signify the data’s target table. However, just like the data returned by the Update driver’s TD_Evt_ApplyCount event, the data for this event only applies to the instance making the GetEvent call.
The TD_Evt_ApplyCount event can be queried at any time during the job after Initiate and before Terminate. The data returned will correspond to the number of rows inserted, updated or deleted since the last checkpoint was taken. If no checkpoint was taken during the job then the data returned will not be meaningful until after EndAcquisition is called. The final statistics for the number of rows inserted, updated, or deleted will always be available after the EndAcquisition method returns with a TD_END_Method. This event returns a block of data for each statement in the DML Group.
The eventData parameter provided to the GetEvent method points to a concatenation of these data blocks if the method returns with TD_END_Method. If the method does not return with TD_END_Method then the eventData pointer is not correct. Each DML statement only has one data block filled with the information described above as long as the statement is not an upsert or merge statement, in which case there would be two data blocks filled with information. For example, any insert statement only has a data block returned with information about the number of rows inserted. This is true for update and delete statements as well. Upsert and merge DML statements have two data blocks filled with information: one for the number of updates and one for the number of inserts.Figure 6: Layout of Data Buffer returned by the TD_Evt_ApplyCount Method
Based on this information and the length (in bytes) provided in eventDataLen after the GetEvent method returns, the number of rows inserted, updated, and deleted can be obtained for each DML statement in the DML Group.