forked from RobertArtigas/DCT2SQL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
D2M2_012.TPW
141 lines (141 loc) · 6.81 KB
/
D2M2_012.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
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#! File Name: D2M2_012.tpw
#! Purpose: METABASE: Additional functionality
#! Author: Copyright © 1999-2999 by Roberto Artigas Jr
#! All rights reserved world wide.
#! Changes:
#! 2020.07.11.SAT Roberto Artigas
#! * Add table prefix to the item name. Generic change, multiple places.
#! 2020.07.03.FRI Roberto Artigas
#! * Make me lower case (with posible additional functionality)
#! 2020.06.11 Roberto Artigas
#! * Creation of this generic structured template
#! Created new file, other files getting large again
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#! RA.2020.06.13.SAT: Additional comments added. I might need to come back to this code.
#! RA.2020.06.11.THU: Tested to TWO (2) levels. Seems functional at that level. Tested.
#! RA.2020.06.11.THU: Begin "quote" procedure.
#! Will need to double check all the left and right quoting constants. Some are known.
#! NOTE: This DOES NOT deal with SQL environment settings. Options for: 'stuff',"stuff"
#GROUP(%QuoteThisThing,*%VariableOut,%VariableIn,%pBaseName,%QuoteOption)
#IF(NOT VAREXISTS(%QuoteLeft))
#DECLARE(%QuoteLeft)
#DECLARE(%QuoteRight)
#DECLARE(%QuoteNames)
#ENDIF
#!
#CASE(%pBaseName)
#OF ('MSSQL')
#SET(%QuoteLeft , '[')
#SET(%QuoteRight, ']')
#OF ('POSTGRESQL')
#OROF('SQLANYWHERE')
#OROF('MYSQL')
#OROF('ORACLE')
#OROF('DB2')
#OROF('METABASE')
#OROF('MIMER')
#SET(%QuoteLeft , '"')
#SET(%QuoteRight, '"')
#ENDCASE
#!
#SET(%VariableOut, %VariableIn)
#!
#IF(%QuoteOption)
#SET(%QuoteNames, %VariableIn)
#CALL(%QuotePieces,%QuoteNames,%QuoteNames,%QuoteLeft,%QuoteRight)
#SET(%VariableOut, %QuoteNames)
#ENDIF
#!---- [%%QuoteThisThing], %%VariableOut='%VariableOut', %%VariableIn='%VariableIn', %%pBaseName='%pBaseName', %%QuoteOption='%QuoteOption'
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#GROUP(%QuotePieces,*%pNamesOut,%pNamesIn,%pQuoteLeft,%pQuoteRight)
#IF(NOT VAREXISTS(%HaveSep))
#DECLARE(%ThisVar)
#DECLARE(%ThisOut)
#DECLARE(%ThisLoc)
#DECLARE(%NextLoc)
#ENDIF
#!
#SET(%pNamesOut, %pQuoteLeft & %pNamesIn & %pQuoteRight)
#!
#SET(%ThisVar, %pNamesIn)
#SET(%ThisOut, '')
#SET(%ThisLoc, 1)
#SET(%NextLoc, INSTRING('.',%ThisVar,1,%ThisLoc))
#IF(%NextLoc>0)
#LOOP,WHILE(%NextLoc>0)
#!---- %%NextLoc=%NextLoc
#SET(%ThisOut, %ThisOut & %pQuoteLeft & SUB(%pNamesIn, %ThisLoc, %ThisLoc + (%NextLoc-%ThisLoc) - 1) & %pQuoteRight)
#SET(%ThisOut, %ThisOut & '.')
#SET(%ThisLoc, %NextLoc + 1)
#SET(%NextLoc, INSTRING('.',%ThisVar,1,%ThisLoc))
#IF(%NextLoc>0)
#!-------------------------------------------------------------------------------------------------------------------!
#! RA.2020.06.18.THU: Added the aditional code. No current context to test. Have to come back to code later. !
#! RA.2020.06.11.WED: Preliminary testing done to two levels. Applicable to "schema"."tablename" functionality. !
#! Beyond the two levels. Not tested. Assume this algorithm will not work in your specific situation. -----TEST----- !
#! And YOU WILL need additional code HERE to parse the NEXT in between quoted piece of the variable. See above code. !
#!-------------------------------------------------------------------------------------------------------------------!
#SET(%ThisOut, %ThisOut & %pQuoteLeft & SUB(%pNamesIn, %ThisLoc, %ThisLoc + (%NextLoc-%ThisLoc) - 1) & %pQuoteRight)
#SET(%ThisOut, %ThisOut & '.')
#SET(%ThisLoc, %NextLoc + 1)
#SET(%NextLoc, INSTRING('.',%ThisVar,1,%ThisLoc))
#ELSE
#!------------------------------------------------------------------------------------------------------------!
#! RA.2020.06.18.THU: Correction to new calculation. Adding + 1 to the calculated range. Off by one error. !
#! This deals with the last piece [*.*.*.<last piece here>] which you have set up if you have no more pieces. !
#!------------------------------------------------------------------------------------------------------------!
#!SET(%ThisOut, %ThisOut & %pQuoteLeft & SUB(%pNamesIn, %ThisLoc, LEN(%pNamesIn) - 1) & %pQuoteRight)
#SET(%ThisOut, %ThisOut & %pQuoteLeft & SUB(%pNamesIn, %ThisLoc, LEN(%pNamesIn) - %ThisLoc + 1) & %pQuoteRight)
#END
#END
#SET(%pNamesOut, %ThisOut)
#END
#!---- [%%QuotePieces], %%pNamesOut='%pNamesOut', %%pNamesIn='%pNamesIn', %%pQuoteLeft='%pQuoteLeft', %%pQuoteRight='%pQuoteRight'
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#! RA.2020.07.03.FRI: Make me lower case (with posible additional functionality)
#GROUP(%MakeSingleCase,*%pSingleCaseOut,%pMixedCaseIn,%pLowerCase)
#IF(%pLowerCase)
#SET(%pSingleCaseOut,LOWER(%pMixedCaseIn))
#! #ELSE
#! #SET(%pSingleCaseOut,UPPER(%pMixedCaseIn))
#ENDIF
#!---------------------------------------------------------------------
#! RA.2020.07.10.FRI: Make me lower case (simple functionality)
#GROUP(%MakeLowerCase,*%pSingleCaseOut,%pMixedCaseIn,%pLowerCase)
#IF(%pLowerCase)
#SET(%pSingleCaseOut,LOWER(%pMixedCaseIn))
#ENDIF
#!---------------------------------------------------------------------
#! RA.2020.07.10.FRI: Make me upper case (simple functionality)
#GROUP(%MakeUpperCase,*%pSingleCaseOut,%pMixedCaseIn,%pUpperCase)
#IF(%pUpperCase)
#SET(%pSingleCaseOut,UPPER(%pMixedCaseIn))
#ENDIF
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#! RA.2020.07.11.SAT: Add table prefix to the item name
#GROUP(%DoPrefixToName,*%pCombinedName,%pTablePrefix,%pItemName,%pSeparator,%pDoThePrefix)
#IF(%pDoThePrefix)
#IF(%pSeparator)
#SET(%pCombinedName, %pTablePrefix & %pSeparator & %pItemName)
#ELSE
#SET(%pCombinedName, %pTablePrefix & %pItemName)
#ENDIF
#ELSE
#SET(%pCombinedName, %pItemName)
#ENDIF
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------