1<?xml version='1.0'?>
2<!--
3 * $Id: postgres.xsl 4518 2008-07-28 15:39:28Z henningw $
4 *
5 * XSL converter script for postgresql databases
6 *
7 * Copyright (C) 2001-2007 FhG Fokus
8 *
9 * This file is part of Kamailio, a free SIP server.
10 *
11 * Kamailio is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version
15 *
16 * Kamailio is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
24 *
25 */
26-->
27
28
29<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
30                version='1.0'
31                xmlns:xi="http://www.w3.org/2001/XInclude"
32>
33
34    <xsl:import href="sql.xsl"/>
35
36<!-- specify the table type -->
37    <xsl:template name="table.close">
38	<xsl:text>)</xsl:text>
39	<xsl:if test="type[@db=$db]">
40	    <xsl:text> Type=</xsl:text>
41	    <xsl:value-of select="normalize-space(type[@db=$db])"/>
42	</xsl:if>
43	<xsl:text>;&#x0A;&#x0A;</xsl:text>
44    </xsl:template>
45
46    <xsl:template name="column.type">
47	<xsl:variable name="type">
48	    <xsl:call-template name="get-type"/>
49	</xsl:variable>
50
51	<xsl:choose>
52	    <xsl:when test="type[@db=$db]">
53		<xsl:value-of select="normalize-space(type[@db=$db])"/>
54	    </xsl:when>
55	    <xsl:when test="$type='char'">
56		<xsl:text>SMALLINT</xsl:text>
57		<xsl:call-template name="column.trailing"/>
58	    </xsl:when>
59	    <xsl:when test="$type='short'">
60		<xsl:text>SMALLINT</xsl:text>
61		<xsl:call-template name="column.trailing"/>
62	    </xsl:when>
63	    <xsl:when test="$type='int'">
64			<xsl:if test="not(autoincrement)">
65				<xsl:text>INTEGER</xsl:text>
66			</xsl:if>
67		<xsl:call-template name="column.trailing"/>
68	    </xsl:when>
69	    <xsl:when test="$type='long'">
70		<xsl:text>BIGINT</xsl:text>
71		<xsl:call-template name="column.trailing"/>
72	    </xsl:when>
73	    <xsl:when test="$type='datetime'">
74		<xsl:text>TIMESTAMP</xsl:text>
75		<xsl:call-template name="column.trailing"/>
76	    </xsl:when>
77	    <xsl:when test="$type='double'">
78		<xsl:text>DOUBLE PRECISION</xsl:text>
79		<xsl:call-template name="column.trailing"/>
80	    </xsl:when>
81	    <xsl:when test="$type='float'">
82		<xsl:text>REAL</xsl:text>
83		<xsl:call-template name="column.trailing"/>
84	    </xsl:when>
85	    <xsl:when test="$type='string'">
86		<xsl:text>VARCHAR</xsl:text>
87		<xsl:call-template name="column.size"/>
88		<xsl:call-template name="column.trailing"/>
89	    </xsl:when>
90	    <xsl:when test="$type='binary' or
91						$type='largebinary'">
92		<xsl:text>BYTEA</xsl:text>
93		<xsl:call-template name="column.size"/>
94		<xsl:call-template name="column.trailing"/>
95	    </xsl:when>
96	    <xsl:when test="$type='text' or
97                        $type='largetext'">
98		<xsl:text>TEXT</xsl:text>
99		<xsl:call-template name="column.size"/>
100		<xsl:call-template name="column.trailing"/>
101	    </xsl:when>
102	    <xsl:otherwise>
103		<xsl:call-template name="type-error"/>
104	    </xsl:otherwise>
105	</xsl:choose>
106	</xsl:template>
107
108	<xsl:template name="column.trailing">
109	<xsl:variable name="column.type">
110	    <xsl:call-template name="get-type"/>
111	</xsl:variable>
112	<xsl:if test="$column.type='datetime'">
113	    <xsl:text> WITHOUT TIME ZONE</xsl:text>
114	</xsl:if>
115	<xsl:if test="autoincrement">
116		<xsl:text>SERIAL</xsl:text>
117	</xsl:if>
118	<!-- PRIMARY KEY column definition -->
119	<xsl:if test="primary">
120		<xsl:text> PRIMARY KEY</xsl:text>
121	</xsl:if>
122	</xsl:template>
123
124	<xsl:template name="get-index-name">
125	<xsl:variable name="index.name">
126	    <xsl:call-template name="get-name"/>
127	</xsl:variable>
128	<xsl:variable name="table.name">
129	    <xsl:call-template name="get-name">
130		<xsl:with-param name="select" select="parent::table"/>
131	    </xsl:call-template>
132	</xsl:variable>
133	<!-- because postgres don't like identical index names, even on table level -->
134	<xsl:value-of select="concat($table.name, '_', $index.name)"/>
135	</xsl:template>
136
137</xsl:stylesheet>
138