mysql.xsl 5.1 KB

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