postgres.xsl 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  28. version='1.0'
  29. xmlns:xi="http://www.w3.org/2001/XInclude"
  30. >
  31. <xsl:import href="sql.xsl"/>
  32. <!-- specify the table type -->
  33. <xsl:template name="table.close">
  34. <xsl:text>)</xsl:text>
  35. <xsl:if test="type[@db=$db]">
  36. <xsl:text> Type=</xsl:text>
  37. <xsl:value-of select="normalize-space(type[@db=$db])"/>
  38. </xsl:if>
  39. <xsl:text>;&#x0A;&#x0A;</xsl:text>
  40. </xsl:template>
  41. <xsl:template name="column.type">
  42. <xsl:variable name="type">
  43. <xsl:call-template name="get-type"/>
  44. </xsl:variable>
  45. <xsl:choose>
  46. <xsl:when test="type[@db=$db]">
  47. <xsl:value-of select="normalize-space(type[@db=$db])"/>
  48. </xsl:when>
  49. <xsl:when test="$type='char'">
  50. <xsl:text>SMALLINT</xsl:text>
  51. <xsl:call-template name="column.trailing"/>
  52. </xsl:when>
  53. <xsl:when test="$type='short'">
  54. <xsl:text>SMALLINT</xsl:text>
  55. <xsl:call-template name="column.trailing"/>
  56. </xsl:when>
  57. <xsl:when test="$type='int'">
  58. <xsl:if test="not(autoincrement)">
  59. <xsl:text>INTEGER</xsl:text>
  60. </xsl:if>
  61. <xsl:call-template name="column.trailing"/>
  62. </xsl:when>
  63. <xsl:when test="$type='long'">
  64. <xsl:text>BIGINT</xsl:text>
  65. <xsl:call-template name="column.trailing"/>
  66. </xsl:when>
  67. <xsl:when test="$type='datetime'">
  68. <xsl:text>TIMESTAMP</xsl:text>
  69. <xsl:call-template name="column.trailing"/>
  70. </xsl:when>
  71. <xsl:when test="$type='double'">
  72. <xsl:text>DOUBLE PRECISION</xsl:text>
  73. <xsl:call-template name="column.trailing"/>
  74. </xsl:when>
  75. <xsl:when test="$type='float'">
  76. <xsl:text>REAL</xsl:text>
  77. <xsl:call-template name="column.trailing"/>
  78. </xsl:when>
  79. <xsl:when test="$type='string'">
  80. <xsl:text>VARCHAR</xsl:text>
  81. <xsl:call-template name="column.size"/>
  82. <xsl:call-template name="column.trailing"/>
  83. </xsl:when>
  84. <xsl:when test="$type='binary' or
  85. $type='largebinary'">
  86. <xsl:text>BYTEA</xsl:text>
  87. <xsl:call-template name="column.size"/>
  88. <xsl:call-template name="column.trailing"/>
  89. </xsl:when>
  90. <xsl:when test="$type='text' or
  91. $type='largetext'">
  92. <xsl:text>TEXT</xsl:text>
  93. <xsl:call-template name="column.size"/>
  94. <xsl:call-template name="column.trailing"/>
  95. </xsl:when>
  96. <xsl:otherwise>
  97. <xsl:call-template name="type-error"/>
  98. </xsl:otherwise>
  99. </xsl:choose>
  100. </xsl:template>
  101. <xsl:template name="column.trailing">
  102. <xsl:variable name="column.type">
  103. <xsl:call-template name="get-type"/>
  104. </xsl:variable>
  105. <xsl:if test="$column.type='datetime'">
  106. <xsl:text> WITHOUT TIME ZONE</xsl:text>
  107. </xsl:if>
  108. <xsl:if test="autoincrement">
  109. <xsl:text>SERIAL</xsl:text>
  110. </xsl:if>
  111. <!-- PRIMARY KEY column definition -->
  112. <xsl:if test="primary">
  113. <xsl:text> PRIMARY KEY</xsl:text>
  114. </xsl:if>
  115. </xsl:template>
  116. <xsl:template name="get-index-name">
  117. <xsl:variable name="index.name">
  118. <xsl:call-template name="get-name"/>
  119. </xsl:variable>
  120. <xsl:variable name="table.name">
  121. <xsl:call-template name="get-name">
  122. <xsl:with-param name="select" select="parent::table"/>
  123. </xsl:call-template>
  124. </xsl:variable>
  125. <!-- because postgres don't like identical index names, even on table level -->
  126. <xsl:value-of select="concat($table.name, '_', $index.name)"/>
  127. </xsl:template>
  128. </xsl:stylesheet>