oracle.xsl 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?xml version='1.0'?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. version='1.0'
  4. xmlns:db="http://iptel.org/dbschema/oracle"
  5. >
  6. <xsl:import href="sql.xsl"/>
  7. <xsl:template match="database" mode="drop">
  8. <xsl:apply-templates mode="drop"/>
  9. </xsl:template>
  10. <xsl:template name="table.close">
  11. <xsl:text>)</xsl:text>
  12. <xsl:text>;&#x0A;&#x0A;</xsl:text>
  13. </xsl:template>
  14. <xsl:template name="column.type">
  15. <xsl:variable name="type">
  16. <xsl:call-template name="get-type"/>
  17. </xsl:variable>
  18. <xsl:choose>
  19. <xsl:when test="db:type">
  20. <xsl:value-of select="normalize-space(db:type)"/>
  21. </xsl:when>
  22. <xsl:when test="$type='char'">
  23. <xsl:text>TINYINT</xsl:text>
  24. <xsl:call-template name="column.size"/>
  25. <xsl:call-template name="column.trailing"/>
  26. </xsl:when>
  27. <xsl:when test="$type='short'">
  28. <xsl:text>SMALLINT</xsl:text>
  29. <xsl:call-template name="column.size"/>
  30. <xsl:call-template name="column.trailing"/>
  31. </xsl:when>
  32. <xsl:when test="$type='int'">
  33. <xsl:text>INT</xsl:text>
  34. <xsl:call-template name="column.size"/>
  35. <xsl:call-template name="column.trailing"/>
  36. </xsl:when>
  37. <xsl:when test="$type='long'">
  38. <xsl:text>BIGINT</xsl:text>
  39. <xsl:call-template name="column.size"/>
  40. <xsl:call-template name="column.trailing"/>
  41. </xsl:when>
  42. <xsl:when test="$type='datetime'">
  43. <xsl:text>DATETIME</xsl:text>
  44. <xsl:call-template name="column.size"/>
  45. <xsl:call-template name="column.trailing"/>
  46. </xsl:when>
  47. <xsl:when test="$type='double'">
  48. <xsl:text>DOUBLE</xsl:text>
  49. <xsl:call-template name="column.size"/>
  50. <xsl:call-template name="column.trailing"/>
  51. </xsl:when>
  52. <xsl:when test="$type='float'">
  53. <xsl:text>FLOAT</xsl:text>
  54. <xsl:call-template name="column.size"/>
  55. <xsl:call-template name="column.trailing"/>
  56. </xsl:when>
  57. <xsl:when test="$type='string'">
  58. <xsl:text>VARCHAR</xsl:text>
  59. <xsl:call-template name="column.size"/>
  60. <xsl:call-template name="column.trailing"/>
  61. </xsl:when>
  62. <xsl:when test="$type='binary'">
  63. <xsl:text>BLOB</xsl:text>
  64. <xsl:call-template name="column.size"/>
  65. <xsl:call-template name="column.trailing"/>
  66. </xsl:when>
  67. <xsl:otherwise>
  68. <xsl:call-template name="type-error"/>
  69. </xsl:otherwise>
  70. </xsl:choose>
  71. </xsl:template>
  72. <xsl:template name="column.trailing">
  73. <xsl:variable name="signed">
  74. <xsl:call-template name="get-sign"/>
  75. </xsl:variable>
  76. <xsl:if test="$signed = 0">
  77. <xsl:text> UNSIGNED</xsl:text>
  78. </xsl:if>
  79. </xsl:template>
  80. <xsl:template match="index">
  81. <xsl:variable name="index.name">
  82. <xsl:call-template name="get-name"/>
  83. </xsl:variable>
  84. <xsl:if test="position()=1">
  85. <xsl:text>,&#x0A;</xsl:text>
  86. </xsl:if>
  87. <xsl:text> </xsl:text>
  88. <xsl:if test="unique">
  89. <xsl:text>UNIQUE </xsl:text>
  90. </xsl:if>
  91. <xsl:text>KEY </xsl:text>
  92. <xsl:if test="not($index.name='')">
  93. <xsl:value-of select="concat($index.name, ' ')"/>
  94. </xsl:if>
  95. <xsl:text>(</xsl:text>
  96. <xsl:apply-templates select="colref"/>
  97. <xsl:text>)</xsl:text>
  98. <xsl:if test="not(position()=last())">
  99. <xsl:text>,</xsl:text>
  100. <xsl:text>&#x0A;</xsl:text>
  101. </xsl:if>
  102. </xsl:template>
  103. <xsl:template name="get-userid">
  104. <xsl:param name="select" select="."/>
  105. <xsl:param name="host" select="/.."/>
  106. <xsl:text>'</xsl:text>
  107. <xsl:choose>
  108. <!-- override test -->
  109. <xsl:when test="count($select/db:username)='1'">
  110. <xsl:value-of select="normalize-space($select/db:username)"/>
  111. </xsl:when>
  112. <!-- No override, use the standard name -->
  113. <xsl:otherwise>
  114. <xsl:value-of select="normalize-space($select/username)"/>
  115. </xsl:otherwise>
  116. </xsl:choose>
  117. <xsl:text>'</xsl:text>
  118. <xsl:text>@'</xsl:text>
  119. <xsl:choose>
  120. <xsl:when test="count($host)='1'">
  121. <xsl:value-of select="normalize-space($host)"/>
  122. </xsl:when>
  123. <xsl:when test="count(db:host)='1'">
  124. <xsl:value-of select="normalize-space(db:host)"/>
  125. </xsl:when>
  126. <xsl:when test="count(host)='1'">
  127. <xsl:value-of select="normalize-space(host)"/>
  128. </xsl:when>
  129. <xsl:otherwise>
  130. <xsl:text>%</xsl:text>
  131. </xsl:otherwise>
  132. </xsl:choose>
  133. <xsl:text>'</xsl:text>
  134. </xsl:template>
  135. <!-- ################ ROW ################ -->
  136. <!-- override common template for ROW. Create INSERT statements
  137. with IGNORE keyword
  138. -->
  139. <xsl:template match="row">
  140. <xsl:if test="@vendor-controlled[1]">
  141. <xsl:text>DELETE FROM </xsl:text>
  142. <xsl:call-template name="get-name">
  143. <xsl:with-param name="select" select="parent::table"/>
  144. </xsl:call-template>
  145. <xsl:text> WHERE </xsl:text>
  146. <xsl:call-template name="row-identification"/>
  147. <xsl:text>;&#x0A;</xsl:text>
  148. </xsl:if>
  149. <xsl:text>INSERT IGNORE INTO </xsl:text>
  150. <xsl:call-template name="get-name">
  151. <xsl:with-param name="select" select="parent::table"/>
  152. </xsl:call-template>
  153. <xsl:text> (</xsl:text>
  154. <xsl:apply-templates select="value" mode="colname"/>
  155. <xsl:text>) VALUES (</xsl:text>
  156. <xsl:apply-templates select="value"/>
  157. <xsl:text>);&#x0A;</xsl:text>
  158. <xsl:if test="position()=last()">
  159. <xsl:text>&#x0A;</xsl:text>
  160. </xsl:if>
  161. </xsl:template>
  162. <!-- ################ /ROW ################ -->
  163. </xsl:stylesheet>