-
Notifications
You must be signed in to change notification settings - Fork 1
/
D2M2_UTL007.TPW
226 lines (226 loc) · 11.6 KB
/
D2M2_UTL007.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
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#! File Name: D2M2_UTL007.tpw
#! Purpose: UTILITY: XREF for fields and keys
#! Author: Copyright © 1999-2999 by Roberto Artigas Jr
#! All rights reserved world wide.
#! Changes:
#! 2020.07.18 Roberto Artigas
#! * Rework template, reformat lines, add DCT2SQL infrastructure.
#! 2002.10.27 Roberto Artigas Jr
#! * Now outputing field picture and field type.
#! * Set in between divider between columns prompt now suported.
#! 2002.08.27 Roberto Artigas Jr
#! * Added the field picture to the field name to make it easier to deal
#! with checking dictionary primary key and foreign keys being longs.
#!
#UTILITY(D2M2_XREF_KEYS, '2020.07.18: [XREF] Check key names for consistency.')
#!-----------------------------------------------------------------------------
#! RA.2017.12.17 - The %BaseName determines what backend you are processing.
#! All the specific items related to a backend can be coded with a case statement.
#! This will make the code easier to maintain accross all the backends.
#PREPARE
#DECLARE(%BaseName) #! Define the BACKEND here
#SET(%BaseName, 'PSQL') #! PSQL: ???
#SET(%BaseName, 'INTERBASE') #! INTERBASE: ???
#SET(%BaseName, 'PERVASIVE') #! PERVASIVE: ???
#SET(%BaseName, 'FIREBIRD') #! FIREBIRD: ???
#SET(%BaseName, 'SYBASE') #! SYBASE: ???
#SET(%BaseName, 'DB2') #! DB2: ???
#SET(%BaseName, 'ORACLE') #! ORACLE: ???
#SET(%BaseName, 'MYSQL') #! MYSQL: RAYS.2018.09.03: Tested.
#SET(%BaseName, 'SQLANYWHERE') #! SQLANYWHERE: RAYS.2018.06.12: Tested.
#SET(%BaseName, 'MSSQL') #! MSSQL: RAYS.2018.06.03: Tested.
#SET(%BaseName, 'MIMER') #! MIMER: RAYS.2018.04.07: Tested.
#SET(%BaseName, 'POSTGRESQL') #! POSTGRESQL: RAYS.2018.06.10: Tested.
#SET(%BaseName, 'METABASE') #! METABASE: Generic-Skeleton. NO backend.
#DECLARE(%pBaseName) #! RA.2020.07.16: Needs Definion. WTH! [???]
#SET(%pBaseName,'TPLUTILITY') #! TPLUTILITY: NOT A BACKEND
#DECLARE(%BaseUtil) #! Define the UTILITY here
#SET(%BaseUtil, 'TPLUTILITY') #! TPLUTILITY: NOT A BACKEND
#ENDPREPARE
#!---------------------------------------------------------------------
#INSERT(%VariablesCommon) #! Need a few simple variables
#INSERT(%GetDictionaryPath) #! Get dictionary path and names
#INSERT(%VariablesDeclare) #! Option checks and output file names
#INSERT(%VariablesSetup) #! Setup output file names
#INSERT(%VariablesOptions) #! All option variables setup here
#INSERT(%DefineAreasOptions) #! File,Field,Keys,Relations
#INSERT(%ReserveWordDefines) #! Reserved Words Defines
#INSERT(%PreambleUtility) #! Basic copyright message
#INSERT(%VariablesUtility007) #! RA.2019.07.25.THU: Added
#!---------------------------------------------------------------------
#SHEET,HSCROLL,AT(,,464)
#INSERT(%MITLicenseD2M2UTL007)
#INSERT(%ShowExplainUtilXREFKEYS)
#INSERT(%MetabaseTabSelection)
#ENDSHEET
#!---------------------------------------------------------------------
#! START EXECUTION HERE
#!---------------------------------------------------------------------
#!#DECLARE(%DebugSet,LONG)
#!#SET(%DebugSet,1)
#!#DEBUG(%DebugSet)
#!
#SET(%UtilityChekTable , %TRUE)
#SET(%UtilityNameTable , %DictName & '_' & %BaseUtil & '_XREF_KEYS.TXT') #! RA.2020.03.24: Changed
#SET(%UtilityNameTableOut , %DictPath & %UtilityNameTable)
#!
#CALL(%UtilityPrefix , %BaseUtil) #! RA.2020.03.24: Changed
#CALL(%BuildQualifiedFiles)
#IF(%TRUE)
#SET(%LineCount , 0)
#SET(%AuditLines, 0)
#!
#FOR(%NFiles)
#FIX(%File, %NFilesName)
#!
#IF(ITEMS(%Key))
#FOR(%Key)
#IF(NOT ITEMS(%KeyField)) #! Key has fields? No!
#CYCLE #! Then go to the next
#ENDIF #! key to be processed
#!
#SET(%nLoc1,INSTRING('RASQL(',%KeyUserOptions,1,1))
#SET(%nLoc2,INSTRING(')',%KeyUserOptions,1,%nLoc1))
#SET(%nKeyUser,UPPER(SUB(%KeyUserOptions,%nLoc1,%nLoc2)))
#SET(%NKeyOpt1,EXTRACT(%NKeyUser,'RASQL',1))
#SET(%NKeyOpt2,EXTRACT(%NKeyUser,'RASQL',2))
#SET(%NKeyOpt3,EXTRACT(%NKeyUser,'RASQL',3))
#SET(%NKeyOpt4,EXTRACT(%NKeyUser,'RASQL',4))
#!------------------------------------------------------------!
#! The first option RASQL(NO) controls if a key is processed. !
#!------------------------------------------------------------!
#IF(SUB(%NKeyOpt1,1,1)='N')
#CYCLE
#ENDIF
#!
#! #SET(%NKeyName,%KeyID)
#! #FOR(%KeyField)
#! #SET(%NKeyField, SUB(%KeyField, INSTRING(':',%KeyField,1,1) + 1 , 50))
#! #FIX(%Field,%KeyField)
#! #SET(%NKeyField, %NKeyField & ' (' & %FieldPicture & ',' & %FieldType & ')')
#! #!ADD(%FieldTableList, %NKeyField & ' ==> ' & %File)
#! #SET(%WorkLine, %NKeyField & ALL(' ', %AtColPos - LEN(%NKeyField)) & ' ==> ' & %File)
#! #ADD(%FieldTableList, %WorkLine)
#! #ENDFOR
#!
#SET(%N007KeyField,%KeyID)
#FOR(%KeyField)
#FIX(%Field,%KeyField)
#!-- %Key :1: '%N007KeyField' [ %KeyField ] %Field
#SET(%N007KeyField, SUB(%KeyField, INSTRING(':',%KeyField,1,1) + 1 , LEN(%KeyField)))
#!SET(%N007KeyField, %N007KeyField & ' (' & %FieldPicture & ',' & %FieldType & ')')
#CALL(%GetFieldType,%WorkType,%FieldType,%FieldMemoSize,%FieldPlaces)
#SET(%N007KeyField, %N007KeyField & ' [ ' & %FieldPicture & ',' & %WorkType & ' ]')
#!-- %Key :2: '%N007KeyField' [ %KeyField ] %Field
#SET(%NextLine , %File & ALL(' ', %AtColPos2 - LEN(%File)) & ' ' & %FilePrefix)
#SET(%WorkLine , %N007KeyField & ALL(' ', %AtColPos1 - LEN(%N007KeyField)) & ' ==> ' & %NextLine)
#ADD(%FieldTableList, %WorkLine)
#ENDFOR #!#FOR(%KeyField)
#ENDFOR #!#FOR(%Key)
#ENDIF #!#IF(ITEMS(%Key))
#!
#ENDFOR #!FOR(%NFiles)
#!
#SET(%LineCount,0)
#SET(%AuditLines,0)
--
#FOR(%FieldTableList)
#SET(%LineCount,%LineCount+1)
-- %@N_06@(%LineCount) %FieldTableList
#SET(%AuditLines, %AuditLines + 1)
#IF(%AuditLines % 20 = 0 AND ITEMS(%FieldTableList) <> %AuditLines)
--
#ENDIF
#ENDFOR #!#FOR(%FieldTableList)
--
#!-- SEQ# DRIVERTYPE %[0]NULL PREFIX %[2]NULL FILENAME %[22]NULL EXTERNALFILE %[28]NULL KEYNAME %[23]NULL EXTERNALKEY
#ENDIF #!#IF(%TRUE)
#CALL(%UtilitySuffix , %BaseUtil) #! RA.2020.03.24: Changed
#!
#!
#!#SET(%DebugSet,0)
#!#DEBUG(%DebugSet)
#!---------------------------------------------------------------------
#! END EXECUTION HERE
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#GROUP(%MITLicenseD2M2UTL007)
#TAB('XREF_KEYS'),PROP(PROP:FontStyle,700)
#INSERT(%MITLicense)
#BOXED('Options'),AT(,,454),PROP(PROP:FontStyle,700),PROP(PROP:FontColor,0C79A3H)
#DISPLAY(''),AT(,,,1)
#PROMPT('Set in between field column divider at: ',@n4),%AtColPos1,AT(150,,30),DEFAULT(60)
#PROMPT('Set in between table column divider at: ',@n4),%AtColPos2,AT(150,,30),DEFAULT(60)
#DISPLAY('')
#DISPLAY('If you have large table names and field names, then enter 120 in both values above.')
#ENDBOXED
#ENDTAB
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#GROUP(%ExplainUtilXREFKEYS)
#PREPARE
#IF(NOT VAREXISTS(%ExplainTextXREFKEYS))
#DECLARE(%ExplainTextXREFKEYS)
#ENDIF
#SET(%ExplainTextXREFKEYS, '')
#!SET(%ExplainTextXREFKEYS, %ExplainTextXREFKEYS & 'This is one of the METABASE templates.')
#!SET(%ExplainTextXREFKEYS, %ExplainTextXREFKEYS & '<13,10><13,10>')
#SET(%ExplainTextXREFKEYS, %ExplainTextXREFKEYS & 'This generic utility will check duplicate key names in the dictionary')
#SET(%ExplainTextXREFKEYS, %ExplainTextXREFKEYS & ' that may give you problems in the various back ends.')
#!SET(%ExplainTextXREFKEYS, %ExplainTextXREFKEYS & '<13,10><13,10>')
#!SET(%ExplainTextXREFKEYS, %ExplainTextXREFKEYS & '<13,10><13,10>')
#!SET(%ExplainTextXREFKEYS, %ExplainTextXREFKEYS & 'This template has been tested with the ABC template chains.')
#SET(%ExplainTextXREFKEYS, %ExplainTextXREFKEYS & '')
#ENDPREPARE
#!
#GROUP(%ShowExplainUtilXREFKEYS)
#INSERT(%ExplainUtilXREFKEYS)
#!TAB(UPPER(%Application) & '.' & UPPER(%ProgramExtension)),PROP(PROP:FontStyle,700),PROP(PROP:FontColor,0C79A3H)
#TAB('Documentation'),PROP(PROP:FontColor,0C79A3H) #! ,PROP(PROP:FontStyle,700),PROP(PROP:FontColor,0C79A3H)
#BOXED('Documentation'),AT(,,454),PROP(PROP:FontStyle,700)
#DISPLAY(''),AT(,,,1)
#DISPLAY(%ExplainTextXREFKEYS),AT(,,436,204)
#ENDBOXED
#ENDTAB
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#!--------------------------------------------------------------------- #! RA.2019.07.25: Added
#GROUP(%VariablesUtility007)
#PREPARE
#!
#IF(VAREXISTS(%AuditLines)=0)
#DECLARE(%AuditLines)
#ENDIF
#IF(VAREXISTS(%LineCount)=0)
#DECLARE(%LineCount)
#ENDIF
#!
#IF(VAREXISTS(%FieldTableList)=0)
#DECLARE(%FieldTableList),MULTI,UNIQUE
#ENDIF
#IF(VAREXISTS(%NextLine)=0)
#DECLARE(%NextLine)
#ENDIF
#IF(VAREXISTS(%WorkLine)=0)
#DECLARE(%WorkLine)
#ENDIF
#IF(VAREXISTS(%WorkType)=0)
#DECLARE(%WorkType)
#ENDIF
#!
#IF(VAREXISTS(%N007KeyField)=0)
#DECLARE(%N007KeyField)
#ENDIF
#!
#ENDPREPARE
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------