소스 검색

- do not use xsl namespaces to override element values anymore (it does
not seem to work reliably across xsltproc upgrades)

if you need to override the value of an element then use db attribute:
<name db="mysql">abc</name>

Jan Janak 19 년 전
부모
커밋
689952f5f9

+ 8 - 8
doc/stylesheets/dbschema/xsl/common.xsl

@@ -1,12 +1,12 @@
 <?xml version='1.0'?>
 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
-	xmlns:db="#"
 	version='1.0'>
     
     <xsl:key name="column_id" match="column" use="@id|xml:id"/>
 
     <xsl:param name="prefix" select="_"/>
     <xsl:param name="dir" select="mm"/>
+    <xsl:param name="db" select="_"/>
 
     <xsl:variable name="sign-prefix">unsigned </xsl:variable>
     
@@ -22,8 +22,8 @@
 	<xsl:param name="select" select="."/>
 	<xsl:choose>
 	    <!-- override test -->
-	    <xsl:when test="count($select/db:name)='1'">
-		<xsl:value-of select="normalize-space($select/db:name)"/>
+	    <xsl:when test="count($select/name[@db=$db])='1'">
+		<xsl:value-of select="normalize-space($select/name[@db=$db])"/>
 	    </xsl:when>
 	    <!-- No override, use the standard name -->
 	    <xsl:otherwise>
@@ -92,8 +92,8 @@
     <xsl:template name="get-type-string">
 	<xsl:param name="select" select="."/>
 	<xsl:choose>
-	    <xsl:when test="count($select/db:type)='1'">
-		<xsl:value-of select="translate(normalize-space($select/db:type),
+	    <xsl:when test="count($select/type[@db=$db])='1'">
+		<xsl:value-of select="translate(normalize-space($select/type[@db=$db]),
 		  'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>
 	    </xsl:when>
 	    <xsl:otherwise>
@@ -136,7 +136,7 @@
     <xsl:template name="get-null">
 	<xsl:param name="select" select="."/>
 	<xsl:choose>
-	    <xsl:when test="count($select/db:null)='1'">1</xsl:when>
+	    <xsl:when test="count($select/null[@db=$db])='1'">1</xsl:when>
 	    <xsl:when test="count($select/null)='1'">1</xsl:when>
 	    <xsl:otherwise>0</xsl:otherwise>
 	</xsl:choose>
@@ -145,8 +145,8 @@
     <xsl:template name="get-size">
 	<xsl:param name="select" select="."/>
 	<xsl:choose>
-	    <xsl:when test="count($select/db:size)='1'">
-		<xsl:value-of select="normalize-space($select/db:size)"/>
+	    <xsl:when test="count($select/size[@db=$db])='1'">
+		<xsl:value-of select="normalize-space($select/size[@db=$db])"/>
 	    </xsl:when>
 	    <xsl:otherwise>
 		<xsl:value-of select="normalize-space($select/size)"/>

+ 7 - 8
doc/stylesheets/dbschema/xsl/dbtext.xsl

@@ -1,8 +1,7 @@
 <?xml version='1.0'?>
 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                 version='1.0'
-                xmlns:xi="http://www.w3.org/2001/XInclude"
-                xmlns:db="http://iptel.org/dbschema/dbtext">
+                xmlns:xi="http://www.w3.org/2001/XInclude">
 
     <xsl:import href="common.xsl"/>
     <xsl:output method="text" indent="no" omit-xml-declaration="yes"/>
@@ -36,8 +35,8 @@
 	<xsl:call-template name="get-name"/>
 	<xsl:text>(</xsl:text>
 	<xsl:choose>
-	    <xsl:when test="db:type">
-		<xsl:value-of select="normalize-space(db:type)"/>
+	    <xsl:when test="type[@db=$db]">
+		<xsl:value-of select="normalize-space(type[@db=$db])"/>
 	    </xsl:when>
 	    <xsl:when test="$type='char' or 
 		            $type='short' or 
@@ -103,16 +102,16 @@
 		<xsl:with-param name="value">
 		    <xsl:choose>
 			<!-- If we have db-specific value, use it -->
-			<xsl:when test="$row/db:value[@col=$id]">
-			    <xsl:value-of select="normalize-space($row/db:value[@col=$id])"/>
+			<xsl:when test="$row/value[@col=$id and @db=$db]">
+			    <xsl:value-of select="normalize-space($row/value[@col=$id and @db=$db])"/>
 			</xsl:when>
 			<!-- No db-specific value, try generic -->
 			<xsl:when test="$row/value[@col=$id]">
 			    <xsl:value-of select="normalize-space($row/value[@col=$id])"/>
 			</xsl:when>
 			<!-- No value at all, try db-specific default value for the column -->
-			<xsl:when test="db:default">
-			    <xsl:value-of select="normalize-space(db:default)"/>
+			<xsl:when test="default[@db=$db]">
+			    <xsl:value-of select="normalize-space(default[@db=$db])"/>
 			</xsl:when>
 			<!-- Try generic default value for the column -->
 			<xsl:when test="default">

+ 8 - 9
doc/stylesheets/dbschema/xsl/mysql.xsl

@@ -1,7 +1,6 @@
 <?xml version='1.0'?>
 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                 version='1.0'
-                xmlns:db="http://iptel.org/dbschema/mysql"
 >
 
     <xsl:import href="sql.xsl"/>
@@ -12,9 +11,9 @@
     
     <xsl:template name="table.close">
 	<xsl:text>)</xsl:text>
-	<xsl:if test="db:type">
+	<xsl:if test="type[@db=$db]">
 	    <xsl:text> Type=</xsl:text>
-	    <xsl:value-of select="normalize-space(db:type)"/>
+	    <xsl:value-of select="normalize-space(type[@db=$db])"/>
 	</xsl:if>
 	<xsl:text>;&#x0A;&#x0A;</xsl:text>	
     </xsl:template>
@@ -25,8 +24,8 @@
 	</xsl:variable>
 
 	<xsl:choose>
-	    <xsl:when test="db:type">
-		<xsl:value-of select="normalize-space(db:type)"/>
+	    <xsl:when test="type[@db=$db]">
+		<xsl:value-of select="normalize-space(type[@db=$db])"/>
 	    </xsl:when>
 	    <xsl:when test="$type='char'">
 		<xsl:text>TINYINT</xsl:text>
@@ -120,8 +119,8 @@
 	<xsl:text>'</xsl:text>
 	<xsl:choose>
 	    <!-- override test -->
-	    <xsl:when test="count($select/db:username)='1'">
-		<xsl:value-of select="normalize-space($select/db:username)"/>
+	    <xsl:when test="count($select/username[@db=$db])='1'">
+		<xsl:value-of select="normalize-space($select/username[@db=$db])"/>
 	    </xsl:when>
 	    <!-- No override, use the standard name -->
 	    <xsl:otherwise>
@@ -135,8 +134,8 @@
 	    <xsl:when test="count($host)='1'">
 		<xsl:value-of select="normalize-space($host)"/>
 	    </xsl:when>
-	    <xsl:when test="count(db:host)='1'">
-		<xsl:value-of select="normalize-space(db:host)"/>
+	    <xsl:when test="count(host[@db=$db])='1'">
+		<xsl:value-of select="normalize-space(host[@db=$db])"/>
 	    </xsl:when>
 	    <xsl:when test="count(host)='1'">
 		<xsl:value-of select="normalize-space(host)"/>

+ 172 - 2
doc/stylesheets/dbschema/xsl/oracle.xsl

@@ -1,9 +1,179 @@
 <?xml version='1.0'?>
 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                 version='1.0'
-                xmlns:xi="http://www.w3.org/2001/XInclude"
-                xmlns:db="http://iptel.org/dbschema/oracle">
+                xmlns:db="http://iptel.org/dbschema/oracle"
+>
 
     <xsl:import href="sql.xsl"/>
 
+    <xsl:template match="database" mode="drop">
+	<xsl:apply-templates mode="drop"/>
+    </xsl:template>
+    
+    <xsl:template name="table.close">
+	<xsl:text>)</xsl:text>
+	<xsl:text>;&#x0A;&#x0A;</xsl:text>	
+    </xsl:template>
+
+    <xsl:template name="column.type">
+	<xsl:variable name="type">
+	    <xsl:call-template name="get-type"/>
+	</xsl:variable>
+
+	<xsl:choose>
+	    <xsl:when test="db:type">
+		<xsl:value-of select="normalize-space(db:type)"/>
+	    </xsl:when>
+	    <xsl:when test="$type='char'">
+		<xsl:text>TINYINT</xsl:text>
+		<xsl:call-template name="column.size"/>
+		<xsl:call-template name="column.trailing"/>
+	    </xsl:when>
+	    <xsl:when test="$type='short'">
+		<xsl:text>SMALLINT</xsl:text>
+		<xsl:call-template name="column.size"/>
+		<xsl:call-template name="column.trailing"/>
+	    </xsl:when>
+	    <xsl:when test="$type='int'">
+		<xsl:text>INT</xsl:text>
+		<xsl:call-template name="column.size"/>
+		<xsl:call-template name="column.trailing"/>
+	    </xsl:when>
+	    <xsl:when test="$type='long'">
+		<xsl:text>BIGINT</xsl:text>
+		<xsl:call-template name="column.size"/>
+		<xsl:call-template name="column.trailing"/>
+	    </xsl:when>
+	    <xsl:when test="$type='datetime'">
+		<xsl:text>DATETIME</xsl:text>
+		<xsl:call-template name="column.size"/>
+		<xsl:call-template name="column.trailing"/>
+	    </xsl:when>
+	    <xsl:when test="$type='double'">
+		<xsl:text>DOUBLE</xsl:text>
+		<xsl:call-template name="column.size"/>
+		<xsl:call-template name="column.trailing"/>
+	    </xsl:when>
+	    <xsl:when test="$type='float'">
+		<xsl:text>FLOAT</xsl:text>
+		<xsl:call-template name="column.size"/>
+		<xsl:call-template name="column.trailing"/>
+	    </xsl:when>
+	    <xsl:when test="$type='string'">
+		<xsl:text>VARCHAR</xsl:text>
+		<xsl:call-template name="column.size"/>
+		<xsl:call-template name="column.trailing"/>
+	    </xsl:when>
+	    <xsl:when test="$type='binary'">
+		<xsl:text>BLOB</xsl:text>
+		<xsl:call-template name="column.size"/>
+		<xsl:call-template name="column.trailing"/>
+	    </xsl:when>
+	    <xsl:otherwise>
+		<xsl:call-template name="type-error"/>
+	    </xsl:otherwise>
+	</xsl:choose>
+    </xsl:template>
+
+    <xsl:template name="column.trailing">
+	<xsl:variable name="signed">
+	    <xsl:call-template name="get-sign"/>
+	</xsl:variable>
+	
+	<xsl:if test="$signed = 0">
+	    <xsl:text> UNSIGNED</xsl:text>
+	</xsl:if>
+    </xsl:template>
+
+    <xsl:template match="index">
+	<xsl:variable name="index.name">
+	    <xsl:call-template name="get-name"/>
+	</xsl:variable>
+
+	<xsl:if test="position()=1">
+	    <xsl:text>,&#x0A;</xsl:text>
+	</xsl:if>
+	<xsl:text>    </xsl:text>
+	<xsl:if test="unique">
+	    <xsl:text>UNIQUE </xsl:text>
+	</xsl:if>
+	<xsl:text>KEY </xsl:text>
+	<xsl:if test="not($index.name='')">
+	    <xsl:value-of select="concat($index.name, ' ')"/>
+	</xsl:if>
+	<xsl:text>(</xsl:text>
+	<xsl:apply-templates select="colref"/>
+	<xsl:text>)</xsl:text>
+	<xsl:if test="not(position()=last())">
+	    <xsl:text>,</xsl:text>
+	    <xsl:text>&#x0A;</xsl:text>
+	</xsl:if>
+    </xsl:template>
+
+    <xsl:template name="get-userid">
+	<xsl:param name="select" select="."/>
+	<xsl:param name="host" select="/.."/>
+	<xsl:text>'</xsl:text>
+	<xsl:choose>
+	    <!-- override test -->
+	    <xsl:when test="count($select/db:username)='1'">
+		<xsl:value-of select="normalize-space($select/db:username)"/>
+	    </xsl:when>
+	    <!-- No override, use the standard name -->
+	    <xsl:otherwise>
+		<xsl:value-of select="normalize-space($select/username)"/>
+	    </xsl:otherwise>
+	</xsl:choose>
+	<xsl:text>'</xsl:text>
+
+	<xsl:text>@'</xsl:text>
+	<xsl:choose>
+	    <xsl:when test="count($host)='1'">
+		<xsl:value-of select="normalize-space($host)"/>
+	    </xsl:when>
+	    <xsl:when test="count(db:host)='1'">
+		<xsl:value-of select="normalize-space(db:host)"/>
+	    </xsl:when>
+	    <xsl:when test="count(host)='1'">
+		<xsl:value-of select="normalize-space(host)"/>
+	    </xsl:when>
+	    <xsl:otherwise>
+		<xsl:text>%</xsl:text>
+	    </xsl:otherwise>
+	</xsl:choose>
+	<xsl:text>'</xsl:text>
+    </xsl:template>
+
+<!-- ################ ROW ################  -->
+
+    <!-- override common template for ROW. Create INSERT statements 
+         with IGNORE keyword
+      -->
+    <xsl:template match="row">
+	<xsl:if test="@vendor-controlled[1]">
+	    <xsl:text>DELETE FROM </xsl:text>	    
+	    <xsl:call-template name="get-name">
+		<xsl:with-param name="select" select="parent::table"/>
+	    </xsl:call-template>
+	    <xsl:text> WHERE </xsl:text>	    
+	    <xsl:call-template name="row-identification"/>
+	    <xsl:text>;&#x0A;</xsl:text>	    
+	</xsl:if>
+
+	<xsl:text>INSERT IGNORE INTO </xsl:text>
+	<xsl:call-template name="get-name">
+	    <xsl:with-param name="select" select="parent::table"/>
+	</xsl:call-template>
+	<xsl:text> (</xsl:text>
+	<xsl:apply-templates select="value" mode="colname"/>
+	<xsl:text>) VALUES (</xsl:text>
+	<xsl:apply-templates select="value"/>
+	<xsl:text>);&#x0A;</xsl:text>
+	<xsl:if test="position()=last()">
+	    <xsl:text>&#x0A;</xsl:text>	    
+	</xsl:if>
+    </xsl:template>
+
+<!-- ################ /ROW ################  -->
+
 </xsl:stylesheet>

+ 8 - 9
doc/stylesheets/dbschema/xsl/postgres.xsl

@@ -2,7 +2,6 @@
 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                 version='1.0'
                 xmlns:xi="http://www.w3.org/2001/XInclude"
-                xmlns:db="http://iptel.org/dbschema/postgres"
 >
 
     <xsl:import href="sql.xsl"/>
@@ -32,8 +31,8 @@
 	</xsl:variable>
 
 	<xsl:choose>
-	    <xsl:when test="db:type">
-		<xsl:value-of select="normalize-space(db:type)"/>
+	    <xsl:when test="type[@db=$db]">
+		<xsl:value-of select="normalize-space(type[@db=$db])"/>
 	    </xsl:when>
 	    <xsl:when test="$type='char'">
 		<xsl:text>SMALLINT</xsl:text>
@@ -162,8 +161,8 @@
 	<xsl:param name="select" select="."/>
 	<xsl:choose>
 	    <!-- override test -->
-	    <xsl:when test="count($select/db:username)='1'">
-		<xsl:value-of select="normalize-space($select/db:username)"/>
+	    <xsl:when test="count($select/username[@db=$db])='1'">
+		<xsl:value-of select="normalize-space($select/username[@db=$db])"/>
 	    </xsl:when>
 	    <!-- No override, use the standard name -->
 	    <xsl:otherwise>
@@ -176,8 +175,8 @@
 	<xsl:param name="select" select="."/>
 	<xsl:choose>
 	    <!-- override test -->
-	    <xsl:when test="count($select/db:privileges)='1'">
-		<xsl:value-of select="normalize-space($select/db:privileges)"/>
+	    <xsl:when test="count($select/privileges[@db=$db])='1'">
+		<xsl:value-of select="normalize-space($select/privileges[@db=$db])"/>
 	    </xsl:when>
 	    <!-- No override, use the standard name -->
 	    <xsl:otherwise>
@@ -198,9 +197,9 @@
 	<xsl:text>CREATE USER </xsl:text>
 	<xsl:call-template name="get-userid"/>
 	<xsl:choose>
-	    <xsl:when test="count(db:password)='1'">
+	    <xsl:when test="count(password[@db=$db])='1'">
 		<xsl:text> PASSWORD '</xsl:text>
-		<xsl:value-of select="normalize-space(db:password)"/>
+		<xsl:value-of select="normalize-space(password[@db=$db])"/>
 		<xsl:text>'</xsl:text>
 	    </xsl:when>
 	    <xsl:when test="count(password)='1'">

+ 3 - 4
doc/stylesheets/dbschema/xsl/sql.xsl

@@ -1,6 +1,5 @@
 <?xml version='1.0'?>
 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
-		xmlns:db="#"
                 version='1.0'
 >
 
@@ -104,15 +103,15 @@
 	</xsl:if>
 
 	<xsl:choose>
-	    <xsl:when test="db:default">
+	    <xsl:when test="default[@db=$db]">
 		<xsl:text> DEFAULT </xsl:text>
 		<xsl:choose>
-		    <xsl:when test="db:default/null">
+		    <xsl:when test="default[@db=$db]/null">
 			<xsl:text>NULL</xsl:text>
 		    </xsl:when>
 		    <xsl:otherwise>
 			<xsl:text>'</xsl:text>
-			<xsl:value-of select="db:default"/>
+			<xsl:value-of select="default[@db=$db]"/>
 			<xsl:text>'</xsl:text>
 		    </xsl:otherwise>
 		</xsl:choose>