SuperX-Kernmodul
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

87 lines
2.9 KiB

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:import href="constraint.xsl" />
<xsl:import href="index.xsl" />
<xsl:import href="column.xsl" />
<xsl:template name="create_table">
<xsl:param name="dbsystem"/>
<xsl:call-template name="log">
<xsl:with-param name="msg" select="concat('Erzeuge Tabelle ',@name) " />
</xsl:call-template>
<xsl:variable name="tabname"><xsl:value-of select="@name" /></xsl:variable>
<xsl:text>create table </xsl:text>
<!-- klappt nicht bei PG 8.3
<xsl:if test="$dbsystem='POSTGRES'">
<xsl:text>if not exists </xsl:text>
</xsl:if>-->
<xsl:value-of select="@name" />
<xsl:text>(
</xsl:text>
<xsl:call-template name="columnschema">
<xsl:with-param name="dbsystem" select="$dbsystem"/>
</xsl:call-template>
<xsl:if test="$dbsystem !='HSQLDB' or count(columns/column [(@type='serial' or @type='SERIAL')])=0">
<xsl:for-each select="primaryKeys/rs/row">
<xsl:if test="position() = 1">
<xsl:call-template name="sx_constraint1">
<xsl:with-param name="dbsystem" select="$dbsystem"/>
</xsl:call-template>
</xsl:if>
<xsl:for-each select="fld">
<xsl:if test="@name ='column_name'">
<xsl:value-of select="." />
</xsl:if>
</xsl:for-each>
<xsl:if test="position() &lt; last()">
<xsl:text>, </xsl:text>
</xsl:if>
<xsl:if test="position() = last()">
<xsl:call-template name="sx_constraint2">
<xsl:with-param name="dbsystem" select="$dbsystem"/>
</xsl:call-template>
</xsl:if>
</xsl:for-each>
</xsl:if>
<!-- für informix muss die Syntax von foreign keys noch angepaßt werden! z.B.
alter table gang_ca_werte add constraint
(foreign key (gang_cnw_tid) references gang_cnw on delete cascade constraint fk_ca_cnw) ;
--><xsl:if test="$dbsystem='POSTGRES'">
<xsl:for-each select="../data-integrity/relation [@to=$tabname and @createForeignKey='true']">
<xsl:text>, constraint </xsl:text><xsl:value-of select="concat('fk_',$tabname,'_',position())"/>
<xsl:text> foreign key (</xsl:text><xsl:value-of select="relation-column/@to"/>
<xsl:text>) references </xsl:text><xsl:value-of select="@from"/>
<xsl:text>(</xsl:text><xsl:value-of select="relation-column/@from"/><xsl:text>)</xsl:text>
</xsl:for-each>
</xsl:if>
<xsl:text>
) </xsl:text>
<xsl:if test="$dbsystem='INFORMIX' and @informixparam!=''">
<xsl:value-of select="@informixparam"/>
</xsl:if>
<xsl:text>
;
</xsl:text>
<xsl:if test="description != '' and $dbsystem ='POSTGRES'">
comment on table <xsl:value-of select="@name" /> is '<xsl:value-of select="description" />';
</xsl:if>
<xsl:for-each select="columns/column">
<xsl:if test="@description !='' and $dbsystem ='POSTGRES'">
comment on column <xsl:value-of select="$tabname" />.<xsl:value-of select="@name" /> is '<xsl:value-of select="normalize-space(@description)" />';
</xsl:if>
</xsl:for-each>
<xsl:for-each select="indexes/index">
<xsl:call-template name="create_index" />
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>