Add %age area column to vacancies section.
[capital-apms-progress.git] / rplctn / gentrgr.p
blobfcedeaf47aa924874e8f2c63b4b413b86ea41bd8
1 /*
3 replication trigger wrapper generator
5 usage: connect to a database, that has tables which are to be replicated
6 first step:
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>)
12 second step:
13 create a subdirectory-tree within your current working-directory:
14 rplctn
15 rplctn/create
16 rplctn/delete
17 rplctn/write
18 third step:
19 run this program
20 fifth step:
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
25 Database.
26 forth step:
27 double-check that all generated triggers are correct. Compile
28 them...
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
32 process....
35 history:
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").
55 for each _File
56 where _File._File-name < "_":
58 /** /
59 if _File._Fil-misc2[6] = ""
60 or _File._Fil-misc2[6] = ?
61 then next. /* no replication for this table */
62 / **/
65 /* 1. step: check for information entered by user into _file-desc */
67 assign
68 l_i = index(_File._desc,"REPLICATION FLDEX").
69 if l_i <> 0
70 then assign
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").
74 else assign
75 l_fldex = "".
77 assign
78 l_i = index(_File._desc,"REPLICATION DOT-P").
79 if l_i <> 0
80 then assign
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").
84 else assign
85 l_dot-p = "".
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
94 if l_fldex = ""
95 then do: /* select fldex from _field-records */
97 assign l_max = 0.
99 for each _Field of _File:
101 if _Field._data-type = "character"
102 and _field._Format matches "x(*)"
103 then do: /* potential field */
105 assign
106 l_ok = true
107 l_token = substring(_field._Format
109 ,length(_field._Format,"character") - 3
110 ,"character"
113 repeat l_i = 1 to length(l_token)
114 while l_ok = true:
115 assign l_ok = ( lookup(substring(l_token,l_i,1,"character")
116 ,"0,1,2,3,4,5,6,7,8,9"
117 ) <> 0 ).
118 end.
120 if l_ok
121 then do: /* found x(<int>) format */
122 assign
123 l_i = integer(l_token).
124 if l_i > l_max
125 then assign
126 l_max = l_i
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
139 if l_fldex = ""
140 then do: /* take any raw or character field */
141 find first _Field of _File
142 where _Field._data-type = "raw"
143 no-error.
144 if not available _Field
145 then find first _Field of _File
146 where _Field._data-type = "character"
147 no-error.
148 if available _Field
149 then assign
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.
163 repeat l_i = 1 to 3:
164 assign
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.
173 /* trigger code */
174 output to value("rplctn/" + l_event + "/" + _File._Dump-name + ".p").
175 put unformatted
176 "/* replication trigger for "
177 entry(l_i,l_action-list)
178 " records of the "
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
187 " " chr(125) skip(1)
188 "/*" fill("-",66) "*/" skip.
189 end.
191 end.