The rs_datarow_for_writetext and rs_writetext forms of the applied subcommand are used to distribute modifications to text or image data. These subcommands are built on the Replication Server version 10.1 performance feature of packing data as structured tokens. Each text or image column has a special character and length field, followed by the actual data value. Packing the data in this way eliminates the need for Replication Server to interpret every byte of data, which provides performance benefits.
rs_datarow_for_writetext carries an image of the data row associated with a text or non-image column that has been modified by the Transact-SQL writetext command, by the Client-Library™ function, ct_send_data, or by the DB-Library™ functions dbwritetext and dbmoretext. The image is used by Replication Server to construct the primary key for subsequent modification at the replicate database. The syntax for rs_datarow_for_writetext is:
distribute command_tags applied 'table'.rs_datarow_for_writetext yielding datarow column_list
yielding datarow column_list carries the column names, the values of non-text or image columns, and the replication status of text or image columns. The replication status can be always_rep, rep_if_changed, or never_rep. The column_list field also carries additional information, called text_status, about the text or image columns. The text_status can be one of the following keywords:
Keyword |
Description |
---|---|
tpnull |
The column has a null text pointer. There are no modifications to text or image columns. |
tpinit |
Modifications were made at the primary database, which caused a text pointer allocation. |
hastext |
The current text or image data value follows. |
notrep |
The text or image column is not replicated. No commands are required in the replicate database because the data did not change value and the text or image column has a replicate_if_changed status. |
zerolen |
The text or image column contains a null value after an operation at the primary database. For example, after a text pointer has been allocated, there may be data values in a text or image column and an application at the primary database sets them to null. |
rs_insert and rs_update also carry the replication status and additional text_status information for text and image columns. rs_delete carries the replication status only.
The rs_writetext form of the applied subcommand carries the text or image data. rs_writetext can carry up to 4K of the text or image data, so the data can be segmented and carried in multiple rs_writetext iterations. The syntax for rs_writetext is:
distribute command_tags applied 'table'.rs_writetext append [first] [last] [changed] [with log] [textlen=100] column_list
append indicates that there are more segments of text or image data to follow.
first marks the first segment of data for the text or image column.
last marks the last segment of data for the text or image column.
changed indicates that the text or image column changed value. If the changed keyword is omitted, the text or image value did not change. This flag is used by the minimal columns feature to discard the data after Replication Server determines it is not needed.
with log indicates that the modification is logged at the primary database transaction log. It is required only in the first segment of text or image data.
textlen indicates the total size of the text or image column. It is required only in the first segment of text or image data.
column_list contains the column name, followed by the text or image data. The data begins with a token header, which is constructed in this order:
The tilda (~) character, which denotes a structured token.
The period (.) character, if it is text data, or the slash (/) character, if it is image data.
The 3-byte character representation of the length of the text or image data segment being carried in an rs_writetext command. The 3-byte length is calculated by converting the length into base-64 representation, then adding the base character ! to each digit to ensure it is a printable character. The formula for calculating the base-64 number is the resultant 3 digits in d3, d2, and d1:
d3 = len/(64*64) len = len - (d3*64*64) d2 = len/64 d1 = len%64
For example, the length of the text segment is 126, and d3= 0, d2=1, and d1=62. The base character ! is added to the digits (the integer value for the base character is 33), and they become !, ", and _ (0+33, 1+33, and 62+33). Thus, the structure token header is represented as:
~.!"_
Following is an example of the LTL commands generated from the writetext command to update a text column called blurb:
distribute @origin_qid=0x00010000010000, @tran_id=0x00018238, applied 'texttest'.rs_datarow_for_writetext yielding datarow @title_id='BU1032', @price=$90.00, @blurb=hastext always_rep, @picture = hastext always_rep
distribute @origin_qid=0x00010000010001, @tran_id=0x00018238, applied 'texttest'.rs_writetext append first last changed with log textlen = 126 @blurb = ~.!"_ Straight Talk About Computers is an annotated analysis of what computers can do for you: a no-hype guide for the critical user
distribute @origin_qid=0x00010000010002, @tran_id=0x00018238, applied 'texttest'.rs_writetext append first with log textlen = ... @picture = ~/&*^ '0X010203...'
distribute @origin_qid=0x00010000010003, @tran_id=0x00018238, applied 'texttest'.rs_writetext append last @picture = ~/!(* 0x4990...