File: sql_functions.xsl

package info (click to toggle)
virtuoso-opensource 6.1.4%2Bdfsg1-7
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 245,116 kB
  • sloc: ansic: 639,631; sql: 439,225; xml: 287,085; java: 61,048; sh: 38,723; cpp: 36,889; cs: 25,240; php: 12,562; yacc: 9,036; lex: 7,149; makefile: 6,093; jsp: 4,447; awk: 1,643; perl: 1,017; ruby: 1,003; python: 329
file content (212 lines) | stat: -rw-r--r-- 9,699 bytes parent folder | download | duplicates (2)
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
<?xml version='1.0'?>
<!--
 -  
 -  $Id: sql_functions.xsl,v 1.2 2006/08/15 22:09:20 source Exp $
 -
 -  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
 -  project.
 -  
 -  Copyright (C) 1998-2006 OpenLink Software
 -  
 -  This project is free software; you can redistribute it and/or modify it
 -  under the terms of the GNU General Public License as published by the
 -  Free Software Foundation; only version 2 of the License, dated June 1991.
 -  
 -  This program is distributed in the hope that it will be useful, but
 -  WITHOUT ANY WARRANTY; without even the implied warranty of
 -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 -  General Public License for more details.
 -  
 -  You should have received a copy of the GNU General Public License along
 -  with this program; if not, write to the Free Software Foundation, Inc.,
 -  51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 -  
 -  
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'>

<xsl:output method="text"/>

<xsl:template match="/book"> 
<xsl:text>
DROP TABLE DB.DBA.PARAMETER;
DROP TABLE DB.DBA.FUNCTIONS;
DROP TABLE DB.DBA.REFENTRY;

CREATE TABLE DB.DBA.REFENTRY (
 ID VARCHAR(50) NOT NULL,
 TITLE VARCHAR(100),
 CATEGORY VARCHAR(50),
 PURPOSE VARCHAR(255),
 DESCRIPTION LONG VARCHAR,
 CONSTRAINT pk_refentry PRIMARY KEY (ID)
 )
;

CREATE INDEX idx_refentry_cats on DB.DBA.REFENTRY(CATEGORY)
;

CREATE TABLE DB.DBA.FUNCTIONS (
 FUNCTIONNAME VARCHAR(100) NOT NULL,
 REFENTRYID VARCHAR(50) NOT NULL,
 RETURN_TYPE VARCHAR(50),
 RETURN_DESC VARCHAR(255),
 CONSTRAINT pk_function PRIMARY KEY (FUNCTIONNAME),
 CONSTRAINT fk_func_refentry FOREIGN KEY (REFENTRYID) REFERENCES DB.DBA.REFENTRY(ID)
 )
;

CREATE TABLE DB.DBA.PARAMETER (
 ID INTEGER IDENTITY,
 PARAMETER VARCHAR(50) NOT NULL,
 FUNCTIONNAME VARCHAR(100) NOT NULL,
 TYPE VARCHAR(50),
 DIRECTION VARCHAR(50),
 DESCRIPTION LONG VARCHAR,
 OPTIONAL INTEGER,
 CONSTRAINT pk_parameter PRIMARY KEY (ID, PARAMETER),
 CONSTRAINT fk_param_func FOREIGN KEY (FUNCTIONNAME) REFERENCES DB.DBA.FUNCTIONS(FUNCTIONNAME)
 )
;

GRANT SELECT ON DB.DBA.REFENTRY TO PUBLIC
;

GRANT SELECT ON DB.DBA.FUNCTIONS TO PUBLIC
;

GRANT SELECT ON DB.DBA.PARAMETER TO PUBLIC
;

</xsl:text>

<xsl:apply-templates select="chapter[@id = 'functions']" /> <!-- select="chapter" / -->
</xsl:template> 

<xsl:template match="chapter[@id = 'functions']">
<xsl:apply-templates select="refentry" />
</xsl:template>

<xsl:template match="para">
<xsl:value-of select='translate(., "&#39;", "@")' />
</xsl:template>

<xsl:template match="funcprototype">
<xsl:text>
INSERT INTO DB.DBA.FUNCTIONS (FUNCTIONNAME, REFENTRYID, RETURN_TYPE, RETURN_DESC) VALUES (
</xsl:text>
&apos;<xsl:value-of select="funcdef/function" />&apos;,
&apos;<xsl:value-of select="../../../@id" />&apos;,
&apos;<xsl:value-of select="normalize-space(substring-before(funcdef, funcdef/function))" />&apos;,
&apos;<xsl:apply-templates select="../../refsect1[title='Return Types']//para" />&apos;
<xsl:text>
);
</xsl:text>
<xsl:for-each select="paramdef">
    <xsl:apply-templates select="." />
  </xsl:for-each>
</xsl:template>

<xsl:template match="paramdef[optional]">
<xsl:text>
INSERT INTO DB.DBA.PARAMETER (PARAMETER, FUNCTIONNAME, TYPE, DIRECTION, DESCRIPTION, OPTIONAL) VALUES (
</xsl:text>
<xsl:variable name="param"><xsl:value-of select="./optional/parameter" /></xsl:variable>
&apos;<xsl:value-of select="./optional/parameter" />&apos;,
&apos;<xsl:value-of select="../funcdef/function" />&apos;,
  <xsl:choose>
    <xsl:when test="contains(., 'varchar')"><xsl:text>&apos;varchar&apos;,</xsl:text></xsl:when>
    <xsl:when test="contains(., 'string')"><xsl:text>&apos;varchar&apos;,</xsl:text></xsl:when>
    <xsl:when test="contains(., 'integer')"><xsl:text>&apos;integer&apos;,</xsl:text></xsl:when>
    <xsl:when test="contains(., 'int')"><xsl:text>&apos;integer&apos;,</xsl:text></xsl:when>
    <xsl:when test="contains(., 'array')"><xsl:text>&apos;array&apos;,</xsl:text></xsl:when>
    <xsl:when test="contains(., 'vector')"><xsl:text>&apos;vector&apos;,</xsl:text></xsl:when>
    <xsl:when test="contains(., 'blob')"><xsl:text>&apos;blob&apos;,</xsl:text></xsl:when>
    <xsl:when test="contains(., 'cursor')"><xsl:text>&apos;cursor handle&apos;,</xsl:text></xsl:when>
    <xsl:when test="contains(., 'double precision')"><xsl:text>&apos;double precision&apos;,</xsl:text></xsl:when>
    <xsl:when test="contains(., 'datetime')"><xsl:text>&apos;datetime&apos;,</xsl:text></xsl:when>
    <xsl:when test="contains(., 'any')"><xsl:text>&apos;any/variable&apos;,</xsl:text></xsl:when>
    <xsl:when test="contains(., 'string_output')"><xsl:text>&apos;string_output&apos;,</xsl:text></xsl:when>
    <xsl:when test="contains(., 'sequence')"><xsl:text>&apos;array&apos;,</xsl:text></xsl:when>
    <xsl:when test="contains(., 'number')"><xsl:text>&apos;numeric&apos;,</xsl:text></xsl:when>
    <xsl:when test="contains(., 'numeric')"><xsl:text>&apos;numeric&apos;,</xsl:text></xsl:when>
    <xsl:when test="contains(., 'boolean')"><xsl:text>&apos;boolean&apos;,</xsl:text></xsl:when>
    <xsl:when test="contains(., 'node_set')"><xsl:text>&apos;node set&apos;,</xsl:text></xsl:when>
    <xsl:otherwise><xsl:text>&apos;</xsl:text><xsl:value-of select="normalize-space(substring-after(., $param))" /><xsl:text>&apos;,</xsl:text></xsl:otherwise>
  </xsl:choose>
  <xsl:choose>
    <xsl:when test="contains(., 'in ')"><xsl:text>&apos;in&apos;,</xsl:text></xsl:when>
    <xsl:when test="contains(., 'out ')"><xsl:text>&apos;out&apos;,</xsl:text></xsl:when>
    <xsl:when test="contains(., 'inout ')"><xsl:text>&apos;inout&apos;,</xsl:text></xsl:when>
    <xsl:otherwise><xsl:text>&apos;</xsl:text><xsl:value-of select="normalize-space(substring-before(., $param))" /><xsl:text>&apos;,</xsl:text></xsl:otherwise>
  </xsl:choose>
&apos;<xsl:apply-templates select="../../../../refsect1/refsect2[title=$param]//para" />&apos;,
1
<xsl:text>
);
</xsl:text>
</xsl:template>

<xsl:template match="paramdef[parameter]">
<xsl:text>
INSERT INTO DB.DBA.PARAMETER (PARAMETER, FUNCTIONNAME, TYPE, DIRECTION, DESCRIPTION) VALUES (
</xsl:text>
<xsl:variable name="param"><xsl:value-of select="./parameter" /></xsl:variable>
&apos;<xsl:value-of select="parameter" />&apos;,
&apos;<xsl:value-of select="../funcdef/function" />&apos;,
  <xsl:choose>
    <xsl:when test="contains(., 'varchar')"><xsl:text>&apos;varchar&apos;,</xsl:text></xsl:when>
    <xsl:when test="contains(., 'string')"><xsl:text>&apos;varchar&apos;,</xsl:text></xsl:when>
    <xsl:when test="contains(., 'integer')"><xsl:text>&apos;integer&apos;,</xsl:text></xsl:when>
    <xsl:when test="contains(., 'int')"><xsl:text>&apos;integer&apos;,</xsl:text></xsl:when>
    <xsl:when test="contains(., 'array')"><xsl:text>&apos;array&apos;,</xsl:text></xsl:when>
    <xsl:when test="contains(., 'vector')"><xsl:text>&apos;vector&apos;,</xsl:text></xsl:when>
    <xsl:when test="contains(., 'blob')"><xsl:text>&apos;blob&apos;,</xsl:text></xsl:when>
    <xsl:when test="contains(., 'cursor')"><xsl:text>&apos;cursor handle&apos;,</xsl:text></xsl:when>
    <xsl:when test="contains(., 'double precision')"><xsl:text>&apos;double precision&apos;,</xsl:text></xsl:when>
    <xsl:when test="contains(., 'datetime')"><xsl:text>&apos;datetime&apos;,</xsl:text></xsl:when>
    <xsl:when test="contains(., 'any')"><xsl:text>&apos;any/variable&apos;,</xsl:text></xsl:when>
    <xsl:when test="contains(., 'string_output')"><xsl:text>&apos;string_output&apos;,</xsl:text></xsl:when>
    <xsl:when test="contains(., 'sequence')"><xsl:text>&apos;array&apos;,</xsl:text></xsl:when>
    <xsl:when test="contains(., 'number')"><xsl:text>&apos;numeric&apos;,</xsl:text></xsl:when>
    <xsl:when test="contains(., 'numeric')"><xsl:text>&apos;numeric&apos;,</xsl:text></xsl:when>
    <xsl:when test="contains(., 'boolean')"><xsl:text>&apos;boolean&apos;,</xsl:text></xsl:when>
    <xsl:when test="contains(., 'node_set')"><xsl:text>&apos;node set&apos;,</xsl:text></xsl:when>
    <xsl:otherwise><xsl:text>&apos;</xsl:text><xsl:value-of select="normalize-space(substring-after(., $param))" /><xsl:text>&apos;,</xsl:text></xsl:otherwise>
  </xsl:choose>
  <xsl:choose>
    <xsl:when test="contains(., 'in ')"><xsl:text>&apos;in&apos;,</xsl:text></xsl:when>
    <xsl:when test="contains(., 'out ')"><xsl:text>&apos;out&apos;,</xsl:text></xsl:when>
    <xsl:when test="contains(., 'inout ')"><xsl:text>&apos;inout&apos;,</xsl:text></xsl:when>
    <xsl:otherwise><xsl:text>&apos;</xsl:text><xsl:value-of select="normalize-space(substring-before(., $param))" /><xsl:text>&apos;,</xsl:text></xsl:otherwise>
  </xsl:choose>
&apos;<xsl:apply-templates select="../../../../refsect1/refsect2[title=$param]//para" />&apos;
<xsl:text>
);
</xsl:text>
</xsl:template>

<xsl:template match="refentrytitle|function" />

<xsl:template match="refentry[refmeta/refmiscinfo='bif']" />

<xsl:template match="refentry[not(refmeta/refmiscinfo='bif')]">
<xsl:text>
INSERT INTO DB.DBA.REFENTRY (ID, TITLE, CATEGORY, PURPOSE, DESCRIPTION) VALUES (
</xsl:text>
&apos;<xsl:value-of select="@id" />&apos;,
&apos;<xsl:value-of select="refmeta/refentrytitle" />&apos;,
&apos;<xsl:value-of select='translate(refmeta/refmiscinfo, "&#39;", "@")' />&apos;,
&apos;<xsl:value-of select='translate(refnamediv/refpurpose, "&#39;", "@")' />&apos;,
&apos;<xsl:apply-templates select="refsect1[title='Description']//para" />&apos;
<xsl:text>
);
</xsl:text>
  <xsl:for-each select="refsynopsisdiv/funcsynopsis/funcprototype">
    <xsl:sort select="funcdef/function" data-type="text"/>
    <xsl:apply-templates select="." />
  </xsl:for-each>

</xsl:template>

</xsl:stylesheet>