rs_commit

Description

Commits a transaction in a data server.

Examples

Example 1

This example illustrates the default rs_commit function string for the rs_sqlserver_function_class and rs_default_function_class classes. The function string executes a stored procedure named rs_update_lastcommit and then executes the Transact-SQL commit transaction command.

create function string rs_commit
 for sqlserver_derived_class
 output language
 'execute rs_update_lastcommit
   @origin = ?rs_origin!sys?,
   @origin_qid = ?rs_origin_qid!sys?,
   @secondary_qid = ?rs_secondary_qid!sys?,
   @origin_time = ?rs_origin_commit_time!sys?;
 commit transaction'

Here is the text of the rs_update_lastcommit procedure for rs_sqlserver_function_class:

/* Create a procedure to update the 
 ** rs_lastcommit table. */
 create procedure rs_update_lastcommit
     @origin  int,
     @origin_qid  binary(36),
     @secondary_qid  binary(36),
     @origin_time  datetime
 as
 begin
     update rs_lastcommit
         set origin_qid = @origin_qid,
         secondary_qid = @secondary_qid,
         origin_time = @origin_time, 
         commit_time = getdate()
     where origin = @origin
     if (@@rowcount = 0)
     begin
         insert rs_lastcommit (origin, 
             origin_qid, secondary_qid,
             origin_time, commit_time,
             pad1, pad2, pad3, pad4, 
             pad5, pad6, pad7, pad8)
             values (@origin, @origin_qid,
             @secondary_qid,@origin_time,
             getdate(), 0x00, 0x00, 0x00,
             0x00, 0x00, 0x00, 0x00, 0x00)
     end
 end

Usage

WARNING! If the rs_lastcommit system table is not updated properly for each transaction committed, after a restart Replication Server may apply transactions more than once or skip transactions.

See also

alter function string, create function string, rs_begin, rs_get_lastcommit, rs_rollback