Skip to content

Commit 2d6d4dc

Browse files
author
Admin
committed
Added support for stored procedures.
Fixed translation of right-hand side comments.
1 parent 2d0705d commit 2d6d4dc

File tree

1 file changed

+143
-61
lines changed

1 file changed

+143
-61
lines changed

sql2doxygen.ps1

Lines changed: 143 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ $lines = get-content $args[0]
4343
$inComment = $false
4444
$inCreateTable = $false
4545
$inCreateFunction = $false
46+
$inCreateProcedure = $false
4647

4748
# For all lines...
4849
foreach ($line in $lines)
@@ -52,7 +53,7 @@ foreach ($line in $lines)
5253
{
5354
write-output $line
5455
}
55-
# If currently parsing a comment, continue until end of comment found.
56+
# If currently parsing a comment, continue until end found.
5657
elseif ($inComment -eq $true)
5758
{
5859
write-output $line
@@ -69,49 +70,49 @@ foreach ($line in $lines)
6970

7071
if ($line -notmatch '\*/')
7172
{
72-
$inComment = $true
73-
}
73+
$inComment = $true
74+
}
7475
}
75-
# Part of sql-style comment?
76+
# Part of sql-style comment?
7677
elseif ($line -match '^--')
77-
{
78-
if ($line -match '^----+')
79-
{
80-
$line = $line -replace '-','/'
81-
}
82-
78+
{
79+
if ($line -match '^----+')
80+
{
81+
$line = $line -replace '-','/'
82+
}
83+
8384
$line = $line -replace '--!','//!'
8485
$line = $line -replace '---','///'
8586
$line = $line -replace '--','//'
8687

8788
write-output $line
88-
}
89-
# If currently parsing a table, continue until end of table found.
89+
}
90+
# If currently parsing a table, continue until end found.
9091
elseif ($inCreateTable -eq $true)
9192
{
92-
$line = $line -replace '^\(', '{'
93-
$line = $line -replace '^\);?', '};'
94-
95-
$line = $line -replace '--!','//!'
96-
$line = $line -replace '---','///'
97-
$line = $line -replace '--','//'
98-
9993
if ($line -match '^(?<indent>\s+)(?<column>\w+)\s+(?<fulltype>[\w.]+)')
10094
{
10195
$type = $matches.fulltype -replace '^\w+\.',''
102-
$indent = $matches.indent
103-
$column = $matches.column
96+
$indent = $matches.indent
97+
$column = $matches.column
10498

105-
$comment = ''
99+
$comment = ''
106100

107-
if ($line -match '(?<comment>/\*.+\*/$)')
108-
{
109-
$comment = $matches.comment
110-
}
101+
if ($line -match '(?<comment>(/\*.+\*/|-.+)$)')
102+
{
103+
$comment = $matches.comment
104+
}
111105

112106
$line = $indent + $type + ' ' + $column + '; ' + $comment
113107
}
114108

109+
$line = $line -replace '^\(', '{'
110+
$line = $line -replace '^\);?', '};'
111+
112+
$line = $line -replace '--!','//!'
113+
$line = $line -replace '---','///'
114+
$line = $line -replace '--','//'
115+
115116
write-output $line
116117

117118
if ($line -match '};')
@@ -130,7 +131,7 @@ foreach ($line in $lines)
130131

131132
$inCreateTable = $true
132133
}
133-
# If currently parsing a function, continue until end of function found.
134+
# If currently parsing a function, continue until end found.
134135
elseif ($inCreateFunction -eq $true)
135136
{
136137
$line = $line -replace '^begin', '{'
@@ -141,7 +142,7 @@ foreach ($line in $lines)
141142
if ($line -match '^\($')
142143
{
143144
$inArgsList = $true
144-
$argsList = @()
145+
$argsList = @()
145146
}
146147

147148
if ($line -match '^\)$')
@@ -155,45 +156,49 @@ foreach ($line in $lines)
155156
$returnType = $returnType -replace '\(','['
156157
$returnType = $returnType -replace '\)',']'
157158

158-
write-output ($returnType + ' ' + $name)
159-
write-output '('
159+
write-output ($returnType + ' ' + $name)
160+
write-output '('
161+
162+
$firstArg = $true
160163

161-
$firstArg = $true
162-
163-
foreach ($arg in $argsList)
164-
{
165-
if ($firstArg -ne $true)
166-
{
167-
$arg = ', ' + $arg
168-
}
169-
170-
write-output $arg
164+
foreach ($arg in $argsList)
165+
{
166+
if ($firstArg -ne $true)
167+
{
168+
$arg = ', ' + $arg
169+
}
171170

172-
$firstArg = $false
173-
}
171+
write-output $arg
174172

175-
write-output ')'
173+
$firstArg = $false
174+
}
175+
176+
write-output ')'
176177
}
177-
elseif ( ($inArgsList -eq $true) -and ($line -match '^(?<indent>\s+)(?<param>@\w+)\s+(?<fulltype>[\w.]+)') )
178+
elseif ( ($inArgsList -eq $true) -and ($line -match '^(?<indent>\s+)(?<param>@\w+)\s+(?<fulltype>[\w.]+)') )
178179
{
179180
$type = $matches.fulltype -replace '^\w+\.',''
180-
$indent = $matches.indent
181-
$param = $matches.param
181+
$indent = $matches.indent
182+
$param = $matches.param
183+
184+
$comment = ''
182185

183-
$comment = ''
186+
if ($line -match '(?<comment>(/\*.+\*/|--.+)$)')
187+
{
188+
$comment = $matches.comment
184189

185-
if ($line -match '(?<comment>/\*.+\*/$)')
186-
{
187-
$comment = $matches.comment
188-
}
190+
$comment = $comment -replace '--!','//!'
191+
$comment = $comment -replace '---','///'
192+
$comment = $comment -replace '--','//'
193+
}
189194

190195
$argsList += $indent + $type + ' ' + $param + ' ' + $comment
191196
}
192-
elseif ($returnType -ne $null)
193-
{
194-
write-output $line
195-
}
196-
197+
elseif ($returnType -ne $null)
198+
{
199+
write-output $line
200+
}
201+
197202
if ($line -match '}')
198203
{
199204
$inCreateFunction = $false
@@ -220,11 +225,88 @@ foreach ($line in $lines)
220225
$parens = $matches.parens
221226
}
222227

223-
if ($returnType -ne $null)
224-
{
225-
write-output ($returnType + ' ' + $name + $parens)
226-
}
227-
228+
if ($returnType -ne $null)
229+
{
230+
write-output ($returnType + ' ' + $name + $parens)
231+
}
232+
228233
$inCreateFunction = $true
229234
}
235+
# If currently parsing a procedure, continue until end found.
236+
elseif ($inCreateProcedure -eq $true)
237+
{
238+
$line = $line -replace '^as', '{'
239+
$line = $line -replace '^go', '}'
240+
241+
if ( ($line -match '^{$') -and ($name -ne $null) )
242+
{
243+
write-output ('void' + ' ' + $name + '()')
244+
write-output '{'
245+
}
246+
elseif ($line -match '^\($')
247+
{
248+
$inArgsList = $true
249+
$argsList = @()
250+
251+
write-output ('void' + ' ' + $name)
252+
write-output '('
253+
254+
$name = $null
255+
}
256+
elseif ($line -match '^\)$')
257+
{
258+
$inArgsList = $false
259+
260+
$firstArg = $true
261+
262+
foreach ($arg in $argsList)
263+
{
264+
if ($firstArg -ne $true)
265+
{
266+
$arg = ', ' + $arg
267+
}
268+
269+
write-output $arg
270+
271+
$firstArg = $false
272+
}
273+
274+
write-output ')'
275+
}
276+
elseif ( ($inArgsList -eq $true) -and ($line -match '^(?<indent>\s+)(?<param>@\w+)\s+(?<fulltype>[\w.]+)') )
277+
{
278+
$type = $matches.fulltype -replace '^\w+\.',''
279+
$indent = $matches.indent
280+
$param = $matches.param
281+
282+
$comment = ''
283+
284+
if ($line -match '(?<comment>(/\*.+\*/|--.+)$)')
285+
{
286+
$comment = $matches.comment
287+
288+
$comment = $comment -replace '--!','//!'
289+
$comment = $comment -replace '---','///'
290+
$comment = $comment -replace '--','//'
291+
}
292+
293+
$argsList += $indent + $type + ' ' + $param + ' ' + $comment
294+
}
295+
else
296+
{
297+
write-output $line
298+
}
299+
300+
if ($line -match '}')
301+
{
302+
$inCreateProcedure = $false
303+
}
304+
}
305+
# Start of procedure definition?
306+
elseif ($line -match '^\s*create\s+procedure\s+(?<fullname>[\w.]+)')
307+
{
308+
$name = $matches.fullname -replace '^\w+\.',''
309+
310+
$inCreateProcedure = $true
311+
}
230312
}

0 commit comments

Comments
 (0)