db_sqlite.xsl 4.1 KB

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