3 replication trigger wrapper generator
5 usage
: connect to a database
, that has tables which are to be replicated
7 add replication specific information to the table-definition
8 * name of the replication program
9 * name of the program to be called when a record is too big to fit
10 in one single replication-change record
11 (in Table Description add
: REPLICATION DOT-P
<program-name
>)
13 create a subdirectory-tree within your current working-directory
:
21 double-check that there are no triggers in the generated
22 rplctn
/reptrig.df file
, that would overwrite triggers you
23 already have in your schema
!
24 If you are sure it's safe
, then load this .df-file into your
27 double-check that all generated triggers are correct. Compile
30 NOTE
: This is
NOT a load-and-go tool
! It is rather just to give you
31 some ideas about what you could do and how
, to speed up the
36 10/96 hutegger creation
40 define variable l_action-list as character init
"changed,new,deleted".
41 define variable l_dot-p as character.
42 define variable l_event-list as character init
"write,create,delete".
43 define variable l_event as character.
44 define variable l_fldex as character.
45 define variable l_i as integer.
46 define variable l_max as integer.
47 define variable l_ok as logical.
48 define variable l_token as character.
50 define stream df-file.
52 /* trigger-definitions
*/
53 output stream df-file to value
("rplctn/reptrig.df").
56 where _File._File-name
< "_":
59 if _File._Fil-misc2
[6] = ""
60 or _File._Fil-misc2
[6] = ?
61 then next.
/* no replication for this table
*/
65 /* 1. step
: check for information entered by user into _file-desc
*/
68 l_i
= index
(_File._desc
,"REPLICATION FLDEX").
71 l_token
= substring
(_File._desc
,l_i
+ 18,-1,"character")
72 l_i
= index
(l_token
," ")
73 l_fldex
= substring
(l_token
,1,l_i
- 1,"character").
78 l_i
= index
(_File._desc
,"REPLICATION DOT-P").
81 l_token
= substring
(_File._desc
,l_i
+ 18,-1,"character")
82 l_i
= index
(l_token
," ")
83 l_dot-p
= substring
(l_token
,1,l_i
- 1,"character").
88 /* 2. step
: determine field to exclude when record too big
89 * a
) select character-field with biggest format
(only
"x(<int>)")
90 * b
) if none found take first raw-field
91 * c
) if none found take first character-field
95 then do
: /* select fldex from _field-records
*/
99 for each _Field of _File
:
101 if _Field._data-type
= "character"
102 and _field._Format matches
"x(*)"
103 then do
: /* potential field
*/
107 l_token
= substring
(_field._Format
109 ,length
(_field._Format
,"character") - 3
113 repeat l_i
= 1 to length
(l_token
)
115 assign l_ok
= ( lookup
(substring
(l_token
,l_i
,1,"character")
116 ,"0,1,2,3,4,5,6,7,8,9"
121 then do
: /* found x
(<int
>) format
*/
123 l_i
= integer
(l_token
).
127 l_fldex
= _Field._field-name.
128 end.
/* found x
(<int
>) format
*/
130 end.
/* potential field
*/
132 end.
/* for each _Field of _File
*/
134 /* if fldex is still empty we haven't found any character-field
135 * with format
"x(<int>)".
136 * So we just take the first raw or character field we find
140 then do
: /* take any raw or character field
*/
141 find first _Field of _File
142 where _Field._data-type
= "raw"
144 if not available _Field
145 then find first _Field of _File
146 where _Field._data-type
= "character"
150 l_fldex
= _field._Field-name.
151 end.
/* take any raw or character field
*/
153 end.
/* select fldex from _field-records
*/
156 /* 3. step
: generate trigger .p's
*/
159 /* trigger-definitions
*/
160 put stream df-file unformatted
161 "UPDATE TABLE """ _File._File-name
"""" skip.
165 l_event
= entry
(l_i
,l_event-list
).
167 /* trigger-definitions
*/
168 put stream df-file unformatted
169 " TABLE-TRIGGER ""REPLICATION-" CAPS(l_event
)
170 """ NO-OVERRIDE PROCEDURE ""rplctn/"
171 l_event
"/" _File._Dump-name
".p"" CRC ""?""" skip.
174 output to value
("rplctn/" + l_event
+ "/" + _File._Dump-name
+ ".p").
176 "/* replication trigger for "
177 entry
(l_i
,l_action-list
)
179 _File._File-name
+ " table */" skip
(1)
180 "TRIGGER PROCEDURE FOR REPLICATION-"
181 l_event
" OF " _File._File-name
"." skip
(1)
182 chr
(123) "rplctn/reptrgr.i" skip
183 " &event = """ l_event
"""" skip
184 " &table = """ _File._File-name
"""" skip
185 " &fldex = """ l_fldex
" """ skip
186 " &dot-p = """ l_dot-p
" """ skip
188 "/*" fill
("-",66) "*/" skip.