-
Notifications
You must be signed in to change notification settings - Fork 1
/
D2M2_011.TPW
476 lines (476 loc) · 23.2 KB
/
D2M2_011.TPW
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#! File Name: D2M2_011.tpw
#! Purpose: METABASE: Triggers to SQL (GUID support [???])
#! Author: Copyright © 1999-2999 by Roberto Artigas Jr
#! All rights reserved world wide.
#! Changes:
#! 2020.07.12.SUN Roberto Artigas
#! * Add table prefix to the item name. Generic change, multiple places.
#! * Implement lower case option. Very useful for some backends.
#! 2020.06.11.THU: Roberto Artigas
#! * QUOTE option implemented [tested and goes thru without errors on postgres]
#! 2020.04.22.WED: Roberto Artigas
#! * IF deleted table record, THEN update the Server and Delete time stamps.
#! 2019.11.20 Roberto Artigas
#! * Added the EncryptionVersion logic to the template.
#! 2019.08.15: Roberto Artigas
#! * Made changes for the field externals. Commented out the replaced code for now.
#! 2019.08.14: Roberto Artigas [short quotes from conversation with Dennis E Evans]
#! * ... Postgre, Oracle [SQLAnywhere] triggers are row based, MS is set based so they are not only
#! using different syntax but they are logically different.
#! ... converting this stuff is difficult. MS has extensions to the merge statement,
#! Oracle has their own extensions, neither are part of the standard, just a mine field of issues.
#! * Mr. Dennis has clearly stated in the above statements the why this area of databases is "difficult"
#! to deal with. And while ANSI has standards, there is no "enforcement" of those standards thru
#! incentives or disincentives monetary or otherwise. Vendors +1, customers -1.
#! The reality is that vendor lock-in can happen. There are current trends that are helping that.
#! 2019.07.28 Roberto Artigas
#! * Creation of this generic structured template
#! Triggers in it's own source do to complexity and GUID customization.
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#GROUP(%VariablesCreate011)
#PREPARE
#IF(NOT VAREXISTS(%TheTableTrigger)) #! RA.2020.06.11.THU: Add quotes
#DECLARE(%TheTableTrigger)
#ENDIF
#IF(NOT VAREXISTS(%TheTriggerBefore)) #! RA.2020.06.11.THU: Add quotes
#DECLARE(%TheTriggerBefore)
#ENDIF
#IF(NOT VAREXISTS(%TheTriggerAfter)) #! RA.2020.06.11.THU: Add quotes
#DECLARE(%TheTriggerAfter)
#ENDIF
#IF(NOT VAREXISTS(%NextLine))
#DECLARE(%NextLine)
#ENDIF
#IF(NOT VAREXISTS(%FieldNameExt))
#DECLARE(%FieldNameExt)
#ENDIF
#IF(NOT VAREXISTS(%TimeStamp))
#DECLARE(%TimeStamp)
#ENDIF
#IF(NOT VAREXISTS(%ServerTimeStamp))
#DECLARE(%ServerTimeStamp)
#ENDIF
#IF(NOT VAREXISTS(%DeletedTimeStamp))
#DECLARE(%DeletedTimeStamp)
#ENDIF
#ENDPREPARE
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#GROUP(%MetabaseTriggerCreateGenerate ,%pBaseName) #! TRIGGER create generate
#INSERT(%ProcessTriggerCreate ,%pBaseName) #! RA.2019.10.11: Tested
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#GROUP(%ProcessTriggerCreate,%pBaseName)
#INSERT(%VariablesCreate011)
#IF(%TraceFlow)
#SET(%CountNFiles,ITEMS(%NFiles))
---- #GROUP(%%ProcessTriggerCreate,'%pBaseName'): CountNFiles: %CountNFiles
#ENDIF
#FOR(%NFiles)
#FIX(%File,%NFilesName)
#INSERT(%TableNameComments,%pBaseName) #! OPTION: Table name comments
#SET(%TheTable,'')
#!CALL(%SetupTheTable,%TheTable,%pBaseName,%NFilesCount,%optDefineNamesEnable,%optDefineNames,%NFilesName,%NFilesFullPath,%optNameOwnerUse,%NameOwner,%NameDatabase)
#CALL(%SetupTheTable2,%TheTable,%pBaseName,%NFilesCount,%optDefineNamesEnable,%optDefineNames,%NFilesName,%NFilesFullPath,%optNameOwnerUse,%NameOwner,%NameDatabase,%FilePrefix,%optPrefixAllNames,'_')
#!SET(%TheTableTrigger , %TheTable & '_Trigger') #! RA.2020.06.11: Add quotes
#SET(%TheTableTrigger , %TheTable & '_trigger') #! RA.2020.06.11: Add quotes
#CALL(%QuoteThisThing,%TheTable,%TheTable,%pBaseName,%optQuoteAllThings) #! RA.2020.06.11: Add quotes
#CALL(%QuoteThisThing,%TheTableTrigger,%TheTableTrigger,%pBaseName,%optQuoteAllThings) #! RA.2020.06.11: Add quotes
#CALL(%MakeSingleCase,%TheTable,%TheTable,%optLowerCaseAllThings) #! RA.2020.07.12: Make lower case
#CALL(%MakeSingleCase,%TheTableTrigger,%TheTableTrigger,%optLowerCaseAllThings) #! RA.2020.07.12: Make lower case
#SET(%TheTriggerBefore, 'trigger_before_' & %NFilesName) #! RA.2020.06.11: Add quotes
#SET(%TheTriggerAfter , 'trigger_after_' & %NFilesName) #! RA.2020.06.11: Add quotes
#CALL(%DoPrefixToName,%TheTriggerBefore,%FilePrefix,%TheTriggerBefore,'_',%optPrefixAllNames) #! RA.2020.07.12: Add table prefix
#CALL(%DoPrefixToName,%TheTriggerAfter,%FilePrefix,%TheTriggerAfter,'_',%optPrefixAllNames) #! RA.2020.07.12: Add table prefix
#CALL(%QuoteThisThing,%TheTriggerBefore,%TheTriggerBefore,%pBaseName,%optQuoteAllThings) #! RA.2020.06.11: Add quotes
#CALL(%QuoteThisThing,%TheTriggerAfter,%TheTriggerAfter,%pBaseName,%optQuoteAllThings) #! RA.2020.06.11: Add quotes
#CALL(%MakeSingleCase,%TheTriggerBefore,%TheTriggerBefore,%optLowerCaseAllThings) #! RA.2020.07.12: Make lower case
#CALL(%MakeSingleCase,%TheTriggerAfter,%TheTriggerAfter,%optLowerCaseAllThings) #! RA.2020.07.12: Make lower case
#CASE(%pBaseName)
#OF ('POSTGRESQL')
#INSERT(%PostgreSQLCreateTrigger)
#OF ('METABASE')
#OROF('SQLANYWHERE')
#OROF('MIMER')
#OROF('MYSQL')
#OROF('MSSQL')
#OROF('ORACLE')
#OROF('DB2')
-- No TRIGGER CREATE generated [No CODE exists]
#ENDCASE
#ENDFOR
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#GROUP(%MetabaseTriggerDropItGenerate ,%pBaseName) #! TRIGGER drop generate
#INSERT(%ProcessTriggerDropIt ,%pBaseName) #! RA.2019.10.11: Tested
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#GROUP(%ProcessTriggerDropIt,%pBaseName)
#IF(%TraceFlow)
#SET(%CountNFiles,ITEMS(%NFiles))
---- #GROUP(%%ProcessTriggerDropIt,'%pBaseName'): CountNFiles: %CountNFiles
#ENDIF
#FOR(%NFiles)
#FIX(%File,%NFilesName)
#INSERT(%TableNameComments,%pBaseName) #! OPTION: Table name comments
#SET(%TheTable,'')
#!CALL(%SetupTheTable,%TheTable,%pBaseName,%NFilesCount,%optDefineNamesEnable,%optDefineNames,%NFilesName,%NFilesFullPath,%optNameOwnerUse,%NameOwner,%NameDatabase)
#CALL(%SetupTheTable2,%TheTable,%pBaseName,%NFilesCount,%optDefineNamesEnable,%optDefineNames,%NFilesName,%NFilesFullPath,%optNameOwnerUse,%NameOwner,%NameDatabase,%FilePrefix,%optPrefixAllNames,'_')
#!SET(%TheTableTrigger, %TheTable & '_Trigger') #! RA.2020.06.11: Add quotes
#SET(%TheTableTrigger, %TheTable & '_trigger') #! RA.2020.06.11: Add quotes
#CALL(%QuoteThisThing,%TheTable,%TheTable,%pBaseName,%optQuoteAllThings) #! RA.2020.06.11: Add quotes
#CALL(%QuoteThisThing,%TheTableTrigger,%TheTableTrigger,%pBaseName,%optQuoteAllThings) #! RA.2020.06.11: Add quotes
#CALL(%MakeSingleCase,%TheTable,%TheTable,%optLowerCaseAllThings) #! RA.2020.07.12: Make lower case
#CALL(%MakeSingleCase,%TheTableTrigger,%TheTableTrigger,%optLowerCaseAllThings) #! RA.2020.07.12: Make lower case
#SET(%TheTriggerBefore, 'trigger_before_' & %NFilesName) #! RA.2020.06.11: Add quotes
#SET(%TheTriggerAfter , 'trigger_after_' & %NFilesName) #! RA.2020.06.11: Add quotes
#CALL(%DoPrefixToName,%TheTriggerBefore,%FilePrefix,%TheTriggerBefore,'_',%optPrefixAllNames) #! RA.2020.07.12: Add table prefix
#CALL(%DoPrefixToName,%TheTriggerAfter,%FilePrefix,%TheTriggerAfter,'_',%optPrefixAllNames) #! RA.2020.07.12: Add table prefix
#CALL(%QuoteThisThing,%TheTriggerBefore,%TheTriggerBefore,%pBaseName,%optQuoteAllThings) #! RA.2020.06.11: Add quotes
#CALL(%QuoteThisThing,%TheTriggerAfter,%TheTriggerAfter,%pBaseName,%optQuoteAllThings) #! RA.2020.06.11: Add quotes
#CALL(%MakeSingleCase,%TheTriggerBefore,%TheTriggerBefore,%optLowerCaseAllThings) #! RA.2020.07.12: Make lower case
#CALL(%MakeSingleCase,%TheTriggerAfter,%TheTriggerAfter,%optLowerCaseAllThings) #! RA.2020.07.12: Make lower case
#CASE(%pBaseName)
#OF ('POSTGRESQL')
#INSERT(%PostgreSQLDropItTrigger)
#OF ('METABASE')
#OROF('SQLANYWHERE')
#OROF('MIMER')
#OROF('MYSQL')
#OROF('MSSQL')
#OROF('ORACLE')
#OROF('DB2')
-- No TRIGGER DROP generated [No CODE exists]
#ENDCASE
#ENDFOR
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#GROUP(%PostgreSQLCreateTrigger)
CREATE OR REPLACE FUNCTION %TheTableTrigger()
RETURNS "trigger"
AS $$
BEGIN
IF (TG_WHEN = 'BEFORE') THEN
IF (TG_OP = 'INSERT') THEN
#FOR(%Field)
#INSERT(%GetFieldOptions) #! RASQL(,,,) for Fields
#IF(SUB(%NFieldOpt1,1,1)='N') #! Ignore this field
#CYCLE
#ENDIF
#IF(%FieldType='GROUP' OR %FieldType='END')
#CYCLE
#ENDIF
#!!!
#SET(%FieldNameExt,%FieldID)
#CALL(%SetupTheField,%FieldNameExt,%pBaseName,%FieldID,%FieldName)
#CALL(%QuoteThisThing,%FieldNameExt,%FieldNameExt,%pBaseName,%optQuoteAllThings) #! RA.2020.06.11: Add quotes
#!!!
#IF (UPPER(%FieldID) = 'TS' OR UPPER(%FieldID) = 'TIMESTAMP')
#! RA.2019.08.01: Doing something at the console.
#!SET(%NextLine, 'NEW.' & %FieldID)
#SET(%NextLine, 'NEW.' & %FieldNameExt)
#!IF (NEW.%FieldID IS NULL OR NEW.%FieldID = 0) THEN %NextLine = define.ryb_sf_getelapsedtimeutc(); END IF;
IF (%NextLine IS NULL OR %NextLine = 0) THEN %NextLine = define.ryb_sf_getelapsedtimeutc(); END IF;
#ENDIF
#IF (UPPER(%FieldID) = 'STS' OR UPPER(%FieldID) = 'SERVERTIMESTAMP')
#!SET(%NextLine, 'NEW.' & %FieldID)
#SET(%NextLine, 'NEW.' & %FieldNameExt)
%[29]NextLine = define.ryb_sf_getelapsedtimeutc();
#ENDIF
#IF (UPPER(%FieldID) = 'DTS' OR UPPER(%FieldID) = 'DELETETIMESTAMP' OR UPPER(%FieldID) = 'DELETEDTIMESTAMP')
#!SET(%NextLine, 'NEW.' & %FieldID)
#SET(%NextLine, 'NEW.' & %FieldNameExt)
%[29]NextLine = 0;
#ENDIF
#! RA.2019.11.20: Added the EncryptionVersion logic to the template.
#IF (UPPER(%FieldID) = 'ENCRYPTIONVERSION')
#!SET(%NextLine, 'NEW.' & %FieldID)
#SET(%NextLine, 'NEW.' & %FieldNameExt)
%[29]NextLine = 0;
#ENDIF
#IF (UPPER(%FieldID) = 'GUID')
#!SET(%NextLine, 'NEW.' & %FieldID)
#SET(%NextLine, 'NEW.' & %FieldNameExt)
#!IF (NEW.%FieldID IS NULL OR NEW.%FieldID = '') THEN %NextLine = define.ryb_sf_makeguid(); END IF;
IF (%NextLine IS NULL OR %NextLine = '') THEN %NextLine = define.ryb_sf_makeguid(); END IF;
#ENDIF
#! RA.2019.07.28: Standards for this database.
#IF (UPPER(%FieldID) = 'DATE_UPDATE')
#!SET(%NextLine, 'NEW.' & %FieldID)
#SET(%NextLine, 'NEW.' & %FieldNameExt)
%[29]NextLine = current_date;
#ENDIF
#IF (UPPER(%FieldID) = 'TIME_UPDATE')
#!SET(%NextLine, 'NEW.' & %FieldID)
#SET(%NextLine, 'NEW.' & %FieldNameExt)
%[29]NextLine = current_time;
#ENDIF
#IF (UPPER(%FieldID) = 'USER_UPDATE')
#!SET(%NextLine, 'NEW.' & %FieldID)
#SET(%NextLine, 'NEW.' & %FieldNameExt)
%[29]NextLine = current_user;
#ENDIF
#IF (UPPER(%FieldID) = 'ACTIVE_FLAG')
#!SET(%NextLine, 'NEW.' & %FieldID)
#SET(%NextLine, 'NEW.' & %FieldNameExt)
#! RA.2019.08.23: Replace if it is incorrect
IF (NEW.%FieldID IS NULL OR NEW.%FieldID = '') THEN %NextLine = 'A'; END IF;
#!%[29]NextLine = 'A';
#ENDIF
#! RA.2019.07.28: Standards for a specific field.
#IF (UPPER(%FieldID) = 'LED')
#!SET(%NextLine, 'NEW.' & %FieldID)
#SET(%NextLine, 'NEW.' & %FieldNameExt)
#! RA.2019.08.23: Replace if it is incorrect
IF (NEW.%FieldID IS NULL OR NEW.%FieldID = '') THEN %NextLine = 'ENG'; END IF;
#!%[29]NextLine = 'ENG';
#ENDIF
#IF (UPPER(%FieldID) = 'LE')
#!SET(%NextLine, 'NEW.' & %FieldID)
#SET(%NextLine, 'NEW.' & %FieldNameExt)
#! RA.2019.08.23: Replace if it is incorrect
IF (NEW.%FieldID IS NULL OR NEW.%FieldID = '') THEN %NextLine = 'ENG'; END IF;
#!%[29]NextLine = 'ENG';
#ENDIF
#IF (UPPER(%FieldID) = 'P_ORDER')
#!SET(%NextLine, 'NEW.' & %FieldID)
#SET(%NextLine, 'NEW.' & %FieldNameExt)
#! RA.2019.08.23: We are defaulting to 100. Leave whatever the user set.
#!%[29]NextLine = 100;
#ENDIF
#ENDFOR
ELSIF (TG_OP = 'UPDATE') THEN
#FOR(%Field)
#INSERT(%GetFieldOptions) #! RASQL(,,,) for Fields
#IF(SUB(%NFieldOpt1,1,1)='N') #! Ignore this field
#CYCLE
#ENDIF
#IF(%FieldType='GROUP' OR %FieldType='END')
#CYCLE
#ENDIF
#!!!
#SET(%FieldNameExt,%FieldID)
#CALL(%SetupTheField,%FieldNameExt,%pBaseName,%FieldID,%FieldName)
#CALL(%QuoteThisThing,%FieldNameExt,%FieldNameExt,%pBaseName,%optQuoteAllThings) #! RA.2020.06.11: Add quotes
#!!!
#IF (UPPER(%FieldID) = 'TS' OR UPPER(%FieldID) = 'TIMESTAMP')
#!SET(%TimeStamp , 'NEW.' & %FieldID)
#!SET(%NextLine , 'NEW.' & %FieldID)
#SET(%TimeStamp , 'NEW.' & %FieldNameExt)
#SET(%Nextline , 'NEW.' & %FieldNameExt)
#ENDIF
#IF (UPPER(%FieldID) = 'STS' OR UPPER(%FieldID) = 'SERVERTIMESTAMP')
#!SET(%NextLine , 'NEW.' & %FieldID)
#!SET(%ServerTimeStamp , 'NEW.' & %FieldID)
#SET(%ServerTimeStamp , 'NEW.' & %FieldNameExt)
#SET(%Nextline , 'NEW.' & %FieldNameExt)
%[29]NextLine = define.ryb_sf_getelapsedtimeutc();
#ENDIF
#IF (UPPER(%FieldID) = 'DTS' OR UPPER(%FieldID) = 'DELETETIMESTAMP' OR UPPER(%FieldID) = 'DELETEDTIMESTAMP')
#!SET(%NextLine , 'NEW.' & %FieldID)
#!SET(%DeletedTimeStamp , 'NEW.' & %FieldID)
#SET(%DeletedTimeStamp , 'NEW.' & %FieldNameExt)
#SET(%Nextline , 'NEW.' & %FieldNameExt)
#! RA.2020.20.23: IF you are UPDATING, THEN the Delete time stamp should be zero.
%[29]NextLine = 0;
#ENDIF
#! RA.2019.11.20: Added the EncryptionVersion logic to the template.
#IF (UPPER(%FieldID) = 'ENCRYPTIONVERSION')
#ENDIF
#IF (UPPER(%FieldID) = 'GUID')
#ENDIF
#! RA.2019.08.01: IF deleting something that is needed, THEN put it back.
#IF (UPPER(%FieldID) = 'LED')
#!SET(%NextLine, 'NEW.' & %FieldID)
#SET(%Nextline, 'NEW.' & %FieldNameExt)
IF (NEW.%FieldID IS NULL OR NEW.%FieldID = '') THEN %NextLine = 'ENG'; END IF;
#ENDIF
#IF (UPPER(%FieldID) = 'LE')
#!SET(%NextLine, 'NEW.' & %FieldID)
#SET(%Nextline, 'NEW.' & %FieldNameExt)
IF (NEW.%FieldID IS NULL OR NEW.%FieldID = '') THEN %NextLine = 'ENG'; END IF;
#ENDIF
#! RA.2019.07.28: Standards for this database.
#IF (UPPER(%FieldID) = 'DATE_UPDATE')
#!SET(%NextLine, 'NEW.' & %FieldID)
#SET(%Nextline, 'NEW.' & %FieldNameExt)
%[29]NextLine = current_date;
#ENDIF
#IF (UPPER(%FieldID) = 'TIME_UPDATE')
#!SET(%NextLine, 'NEW.' & %FieldID)
#SET(%Nextline, 'NEW.' & %FieldNameExt)
%[29]NextLine = current_time;
#ENDIF
#IF (UPPER(%FieldID) = 'USER_UPDATE')
#!SET(%NextLine, 'NEW.' & %FieldID)
#SET(%Nextline, 'NEW.' & %FieldNameExt)
%[29]NextLine = current_user;
#ENDIF
#IF (UPPER(%FieldID) = 'ACTIVE_FLAG')
#ENDIF
#ENDFOR
#! RA.2019.08.01: Check for consistency in record status changes.
#FOR(%Field)
#INSERT(%GetFieldOptions) #! RASQL(,,,) for Fields
#IF(SUB(%NFieldOpt1,1,1)='N') #! Ignore this field
#CYCLE
#ENDIF
#IF(%FieldType='GROUP' OR %FieldType='END')
#CYCLE
#ENDIF
#!!!
#SET(%FieldNameExt,%FieldID)
#CALL(%SetupTheField,%FieldNameExt,%pBaseName,%FieldID,%FieldName)
#CALL(%QuoteThisThing,%FieldNameExt,%FieldNameExt,%pBaseName,%optQuoteAllThings) #! RA.2020.06.11: Add quotes
#!!!
#IF (UPPER(%FieldID) = 'ACTIVE_FLAG')
#!SET(%NextLine, 'NEW.' & %FieldID)
#SET(%Nextline, 'NEW.' & %FieldNameExt)
IF (%NextLine = '') THEN %Nextline = 'A'; END IF;
#IF(%DeletedTimeStamp)
IF (%NextLine = 'A') THEN %DeletedTimeStamp = 0; END IF;
IF (%NextLine = 'I') THEN %DeletedTimeStamp = 0; END IF;
IF (%NextLine = 'D' AND %DeletedTimeStamp = 0) THEN %DeletedTimeStamp = define.ryb_sf_getelapsedtimeutc(); END IF;
IF (%NextLine = 'P' AND %DeletedTimeStamp = 0) THEN %DeletedTimeStamp = define.ryb_sf_getelapsedtimeutc(); END IF;
#ELSE
! Missing %%DeletedTimeStamp
#ENDIF
#ENDIF
#ENDFOR
#!
ELSIF (TG_OP = 'DELETE') THEN
#FOR(%Field)
#INSERT(%GetFieldOptions) #! RASQL(,,,) for Fields
#IF(SUB(%NFieldOpt1,1,1)='N') #! Ignore this field
#CYCLE
#ENDIF
#IF(%FieldType='GROUP' OR %FieldType='END')
#CYCLE
#ENDIF
#!!!
#SET(%FieldNameExt,%FieldID)
#CALL(%SetupTheField,%FieldNameExt,%pBaseName,%FieldID,%FieldName)
#CALL(%QuoteThisThing,%FieldNameExt,%FieldNameExt,%pBaseName,%optQuoteAllThings) #! RA.2020.06.11: Add quotes
#!!!
#! RA.2020.04.22:
#IF (UPPER(%FieldID) = 'TS' OR UPPER(%FieldID) = 'TIMESTAMP')
#ENDIF
#IF (UPPER(%FieldID) = 'STS' OR UPPER(%FieldID) = 'SERVERTIMESTAMP')
#! RA.2020.04.22: When DELETED update the Server and Delete time stamps
#SET(%ServerTimeStamp , 'NEW.' & %FieldNameExt)
#SET(%Nextline , 'NEW.' & %FieldNameExt)
%[29]NextLine = define.ryb_sf_getelapsedtimeutc();
#ENDIF
#IF (UPPER(%FieldID) = 'DTS' OR UPPER(%FieldID) = 'DELETETIMESTAMP' OR UPPER(%FieldID) = 'DELETEDTIMESTAMP')
#! RA.2020.04.22: When DELETED update the Server and Delete time stamps
#SET(%DeletedTimeStamp , 'NEW.' & %FieldNameExt)
#SET(%Nextline , 'NEW.' & %FieldNameExt)
%[29]NextLine = define.ryb_sf_getelapsedtimeutc();
#ENDIF
#! RA.2019.11.20: Added the EncryptionVersion logic to the template.
#IF (UPPER(%FieldID) = 'ENCRYPTIONVERSION')
#ENDIF
#IF (UPPER(%FieldID) = 'GUID')
#ENDIF
#! RA.2019.07.28: Standards for this database.
#IF (UPPER(%FieldID) = 'DATE_UPDATE')
#!SET(%NextLine, 'NEW.' & %FieldID)
#SET(%Nextline, 'NEW.' & %FieldNameExt)
%[29]NextLine = current_date;
#ENDIF
#IF (UPPER(%FieldID) = 'TIME_UPDATE')
#!SET(%NextLine, 'NEW.' & %FieldID)
#SET(%Nextline, 'NEW.' & %FieldNameExt)
%[29]NextLine = current_time;
#ENDIF
#IF (UPPER(%FieldID) = 'USER_UPDATE')
#!SET(%NextLine, 'NEW.' & %FieldID)
#SET(%Nextline, 'NEW.' & %FieldNameExt)
%[29]NextLine = current_user;
#ENDIF
#IF (UPPER(%FieldID) = 'ACTIVE_FLAG')
#!SET(%NextLine, 'NEW.' & %FieldID)
#SET(%Nextline, 'NEW.' & %FieldNameExt)
%[29]NextLine = 'D';
#ENDIF
#ENDFOR
END IF;
RETURN NEW;
ELSIF (TG_WHEN = 'AFTER') THEN
IF (TG_OP = 'INSERT') THEN
ELSIF (TG_OP = 'UPDATE') THEN
ELSIF (TG_OP = 'DELETE') THEN
END IF;
RETURN OLD;
END IF;
END $$
LANGUAGE plpgsql VOLATILE
;
DROP TRIGGER IF EXISTS %TheTriggerBefore ON %TheTable;
CREATE TRIGGER %TheTriggerBefore
BEFORE INSERT OR UPDATE OR DELETE ON %TheTable
FOR EACH ROW EXECUTE PROCEDURE %TheTableTrigger()
;
DROP TRIGGER IF EXISTS %TheTriggerAfter ON %TheTable;
CREATE TRIGGER %TheTriggerAfter
AFTER INSERT OR UPDATE OR DELETE ON %TheTable
FOR EACH ROW EXECUTE PROCEDURE %TheTableTrigger()
;
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#GROUP(%PostgreSQLDropItTrigger)
DROP TRIGGER IF EXISTS %TheTriggerBefore ON %TheTable
;
DROP TRIGGER IF EXISTS %TheTriggerAfter ON %TheTable
;
DROP FUNCTION IF EXISTS %TheTableTrigger
;
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#!
#! --
#! -- EXAMPLE: TRIGGERS
#! --
#! -- CREATE OR REPLACE FUNCTION define.users_trigger()
#! -- RETURNS "trigger"
#! -- AS $$
#! -- BEGIN
#! -- IF (TG_WHEN = 'BEFORE') THEN
#! -- IF (TG_OP = 'INSERT') THEN
#! -- ELSIF (TG_OP = 'UPDATE') THEN
#! -- ELSIF (TG_OP = 'DELETE') THEN
#! -- END IF;
#! -- RETURN NEW;
#! -- ELSIF (TG_WHEN = 'AFTER') THEN
#! -- IF (TG_OP = 'INSERT') THEN
#! -- ELSIF (TG_OP = 'UPDATE') THEN
#! -- ELSIF (TG_OP = 'DELETE') THEN
#! -- END IF;
#! -- RETURN OLD;
#! -- END IF;
#! -- END $$
#! -- LANGUAGE plpgsql VOLATILE
#! -- ;
#! -- DROP TRIGGER IF EXISTS trigger_before_users ON define.users;
#! -- CREATE TRIGGER trigger_before_users
#! -- BEFORE INSERT OR UPDATE OR DELETE ON define.users
#! -- FOR EACH ROW EXECUTE PROCEDURE define.users_trigger()
#! -- ;
#! -- DROP TRIGGER IF EXISTS trigger_after_users ON define.users;
#! -- CREATE TRIGGER trigger_after_users
#! -- AFTER INSERT OR UPDATE OR DELETE ON define.users
#! -- FOR EACH ROW EXECUTE PROCEDURE define.users_trigger()
#! -- ;
#! --
#!
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------