summaryrefslogtreecommitdiffstats
path: root/db
diff options
context:
space:
mode:
Diffstat (limited to 'db')
-rw-r--r--db/oracle/datatypes.xml30
-rw-r--r--db/oracle/output.xsl130
2 files changed, 160 insertions, 0 deletions
diff --git a/db/oracle/datatypes.xml b/db/oracle/datatypes.xml
new file mode 100644
index 0000000..45c803e
--- /dev/null
+++ b/db/oracle/datatypes.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0"?>
+<datatypes db="oracle">
+ <group label="Number" color="rgb(238,238,170)">
+ <type label="NUMERIC" length="0" sql="DECIMAL" re="INT" quote="" />
+ <type label="NUMBER" length="0" sql="DECIMAL" re="INT" quote="" />
+ <type label="Decimal" length="1" sql="DECIMAL" re="DEC" quote="" />
+ <type label="Single precision" length="0" sql="FLOAT" quote="" />
+ <type label="Double precision" length="0" sql="DOUBLE" re="DOUBLE" quote="" />
+ </group>
+
+ <group label="Character" color="rgb(255,200,200)">
+ <type label="Char" length="1" sql="CHAR" quote="'"/>
+ <type label="NCHAR" length="1" sql="NCHAR" quote="'"/>
+ <type label="Varchar2" length="1" sql="VARCHAR2" quote="'"/>
+ <type label="CLOB" length="0" sql="MEDIUMTEXT" re="TEXT" quote="'"/>
+ <type label="Binary" length="1" sql="BINARY" quote="'"/>
+ <type label="Varbinary" length="1" sql="VARBINARY" quote="'"/>
+ <type label="BLOB" length="0" sql="BLOB" re="BLOB" quote="'"/>
+ </group>
+
+ <group label="Date &amp; Time" color="rgb(200,255,200)">
+ <type label="Date" length="0" sql="DATE" quote="'" />
+ <type label="Timestamp" length="0" sql="TIMESTAMP" quote="'" />
+ </group>
+
+ <group label="Miscellaneous" color="rgb(200,200,255)">
+ <type label="ENUM" length="1" sql="ENUM" quote="" />
+ <type label="SET" length="1" sql="SET" quote="" />
+ </group>
+</datatypes>
diff --git a/db/oracle/output.xsl b/db/oracle/output.xsl
new file mode 100644
index 0000000..b0c3e59
--- /dev/null
+++ b/db/oracle/output.xsl
@@ -0,0 +1,130 @@
+<?xml version="1.0" ?>
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+<xsl:output method="text"/>
+
+<xsl:template name="replace-substring">
+ <xsl:param name="value" />
+ <xsl:param name="from" />
+ <xsl:param name="to" />
+ <xsl:choose>
+ <xsl:when test="contains($value,$from)">
+ <xsl:value-of select="substring-before($value,$from)" />
+ <xsl:value-of select="$to" />
+ <xsl:call-template name="replace-substring">
+ <xsl:with-param name="value" select="substring-after($value,$from)" />
+ <xsl:with-param name="from" select="$from" />
+ <xsl:with-param name="to" select="$to" />
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$value" />
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template match="/sql">
+
+<!-- tables -->
+ <xsl:for-each select="table">
+ <xsl:text>CREATE TABLE `</xsl:text>
+ <xsl:value-of select="@name" />
+ <xsl:text>` (
+</xsl:text>
+ <xsl:for-each select="row">
+ <xsl:text>`</xsl:text>
+ <xsl:value-of select="@name" />
+ <xsl:text>` </xsl:text>
+
+ <xsl:value-of select="datatype" />
+ <xsl:text> </xsl:text>
+
+ <xsl:if test="@null = 0">
+ <xsl:text>NOT NULL </xsl:text>
+ </xsl:if>
+
+ <xsl:if test="@autoincrement = 1">
+ <xsl:text>AUTO_INCREMENT </xsl:text>
+ </xsl:if>
+
+ <xsl:if test="default">
+ <xsl:text>DEFAULT </xsl:text>
+ <xsl:value-of select="default" />
+ <xsl:text> </xsl:text>
+ </xsl:if>
+
+ <xsl:if test="comment">
+ <xsl:text>COMMENT '</xsl:text>
+ <xsl:call-template name="replace-substring">
+ <xsl:with-param name="value" select="comment" />
+ <xsl:with-param name="from" select='"&apos;"' />
+ <xsl:with-param name="to" select='"&apos;&apos;"' />
+ </xsl:call-template>
+ <xsl:text>' </xsl:text>
+ </xsl:if>
+
+ <xsl:if test="not (position()=last())">
+ <xsl:text>,
+</xsl:text>
+ </xsl:if>
+ </xsl:for-each>
+
+<!-- keys -->
+ <xsl:for-each select="key">
+ <xsl:text>,
+</xsl:text>
+ <xsl:choose>
+ <xsl:when test="@type = 'PRIMARY'">PRIMARY KEY (</xsl:when>
+ <xsl:when test="@type = 'FULLTEXT'">FULLTEXT KEY (</xsl:when>
+ <xsl:when test="@type = 'UNIQUE'">UNIQUE KEY (</xsl:when>
+ <xsl:otherwise>KEY (</xsl:otherwise>
+ </xsl:choose>
+
+ <xsl:for-each select="part">
+ <xsl:text>`</xsl:text><xsl:value-of select="." /><xsl:text>`</xsl:text>
+ <xsl:if test="not (position() = last())">
+ <xsl:text>, </xsl:text>
+ </xsl:if>
+ </xsl:for-each>
+ <xsl:text>)</xsl:text>
+
+ </xsl:for-each>
+
+ <xsl:text>
+)</xsl:text>
+
+ <xsl:if test="comment">
+ <xsl:text> COMMENT '</xsl:text>
+ <xsl:call-template name="replace-substring">
+ <xsl:with-param name="value" select="comment" />
+ <xsl:with-param name="from" select='"&apos;"' />
+ <xsl:with-param name="to" select='"&apos;&apos;"' />
+ </xsl:call-template>
+ <xsl:text>'</xsl:text>
+ </xsl:if>
+
+ <xsl:text>;
+
+</xsl:text>
+
+ </xsl:for-each>
+
+<!-- fk -->
+ <xsl:for-each select="table">
+ <xsl:for-each select="row">
+ <xsl:for-each select="relation">
+ <xsl:text>ALTER TABLE `</xsl:text>
+ <xsl:value-of select="../../@name" />
+ <xsl:text>` ADD FOREIGN KEY (</xsl:text>
+ <xsl:value-of select="../@name" />
+ <xsl:text>) REFERENCES `</xsl:text>
+ <xsl:value-of select="@table" />
+ <xsl:text>` (`</xsl:text>
+ <xsl:value-of select="@row" />
+ <xsl:text>`);
+</xsl:text>
+ </xsl:for-each>
+ </xsl:for-each>
+ </xsl:for-each>
+
+</xsl:template>
+</xsl:stylesheet> \ No newline at end of file