MINI MINI MANI MO
<?xml version="1.0"?>
<!--
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
NAME
kutabcon.xsl
DESCRIPTION
XSLT stylesheet for XML => DDL conversion of table constraints
(broken out of kutable.xsl for code hygiene)
NOTES
Do NOT modify this file under any circumstance. Copy the file
if you wish to use this stylesheet with an external XML/XSL parser
MODIFIED MM/DD/YY
rapayne 10/10/17 - Bug 26895793: keep track of IOT when DWCS_CVT_IOT
is set
rapayne 08/12/17 - Bug DWCS: add support for DWCS envir.
jjanosik 12/21/16 - Bug 25260248: Check for supplemental logs when
checking for constraints
sdavidso 11/01/16 - bug24702971 for sharding, use constraints_as_alter
tbhukya 08/10/16 - Bug 24365638: Don't generate REF SCOPE for unused
columns
sdavidso 01/29/16 - bug22577904 shard P2T - missing constraints
sdavidso 02/06/15 - proj 56220 - partition transportable
tbhukya 01/05/15 - Bug 20319428: Declare referred params
bwright 08/21/13 - Bug 17312600: Remove hard tabs from DP src code
lbarton 08/15/13 - bug 16800820: valid-time temporal
lbarton 12/22/11 - 36954_dpump_tabcluster_zonemap
sdavidso 08/09/11 - FORCE_UNIQUE transform support
tbhukya 11/24/09 - Bug 8822995: Generated OID for classic export also
for xml schema tables with REF SCOPE columns.
sdavidso 10/23/09 - bug 8477142 more care with refpar constraints
mjangir 02/07/08 - Bug 6676049: filter xmltype columns with rowid
sdavidso 01/15/08 - no FK constraint for nested table
sdavidso 08/01/06 - include refpar constraints
emagrath 02/22/06 - Add SYSTEM_DEFINED clause for Import sOID SCOPE
lbarton 01/20/06 - partition transportable
-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- Top level imports -->
<xsl:import href="kucommon.xsl"/>
<xsl:import href="kuconstr.xsl"/>
<!-- Top level parameters -->
<xsl:param name="OLDEXPORT">0</xsl:param>
<xsl:param name="CONSTRAINTS">1</xsl:param>
<xsl:param name="REF_CONSTRAINTS">1</xsl:param>
<xsl:param name="CONSTRAINTS_AS_ALTER">0</xsl:param>
<!-- Templates -->
<xsl:template name="fnIsObjectTable">
<xsl:param name="Property">0</xsl:param>
<!-- *******************************************************************
Template: fnIsObjectTable - return 1 if table is object table
Parameters:
Property - value of table PROPERTY
******************************************************************** -->
<xsl:choose>
<xsl:when test="($Property mod 2)=1">1</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="fnIsIOT">
<xsl:param name="Property">0</xsl:param>
<!-- *******************************************************************
Template: fnIsIOT - return 1 if table is IOT
Parameters:
Property - value of table PROPERTY
******************************************************************** -->
<xsl:choose>
<xsl:when test="($Property mod 128)>=64">1</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="fnHasPkOID">
<xsl:param name="Property">0</xsl:param>
<!-- *******************************************************************
Template: fnHasPkOID - return 1 if table has primary key-based OID$ column
Parameters:
Property - value of table PROPERTY
******************************************************************** -->
<xsl:choose>
<xsl:when test="($Property mod 8192)>=4096">1</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="fnHasNotNull">
<xsl:param name="SchemaObjParent" select="''"/>
<!-- *******************************************************************
Template: fnHasNotNull - return 1 if table has NOT NULL constraint
on non-hidden column
Note:
col$.property:
/* 0x0020 = 32 = hidden column */
Parameters:
SchemaObjParent - parent of SCHEMA_OBJ node
******************************************************************** -->
<xsl:choose>
<xsl:when test="$SchemaObjParent/COL_LIST/COL_LIST_ITEM[(PROPERTY mod 64)<32]/CON">1</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="fnHasNonZeroPkRef">
<xsl:param name="ListParent" select="''"/>
<xsl:param name="InColList">0</xsl:param>
<xsl:param name="Nested">0</xsl:param>
<!-- *******************************************************************
Template: fnHasNonZeroPkRef - return 1 if constraint list has a
PkRef constraint with REFTYP not=0
Note:
(REFTYP mod 16)>0 = one of the interesting REFTYPs:
/* 0x01 = REF is scoped */
/* 0x02 = REF stored with rowid */
/* 0x04 = Primary key based ref */
/* 0x08 = Unscoped primary key based ref allowed */
/* 0x10 (16) = ref generated for xdb:SQLInline="false" (bug 6676049) */
not ((REFTYP mod 32) > 16 and (PROPERTY mod 64)>=32)] =
not a hidden column for a ref generated for xdb:SQLInline="false"
(bug 6676049)
Parameters:
ListParent - parent node of constraint list (e.g., CON1_LIST, CON2_LIST)
InColList - 1 = generating constraints after column list in CREATE TABLE
0 = adding constraint in ALTER TABLE
Nested - 1 = generating DDL for a nested table
Global Parameters:
CONSTRAINTS_AS_ALTER - 1 = emit constraints as ALTER TABLE statements
******************************************************************** -->
<xsl:choose>
<xsl:when test="$ListParent/PKREF_LIST/PKREF_LIST_ITEM[(REFTYP mod 16)>0 and not ((REFTYP mod 32) > 16 and (PROPERTY mod 64)>=32)]">
<xsl:choose>
<xsl:when test="(($Nested=0 and $InColList!=$CONSTRAINTS_AS_ALTER) or
($Nested=1 and $InColList=0))">1</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="fnIsRefPartitioned">
<xsl:param name="SchemaObjParent" select="''"/>
<!-- *******************************************************************
Template: fnIsRefPartitioned - return 1 if table is reference partitioned.
Parameters:
SchemaObjParent - parent of SCHEMA_OBJ node
******************************************************************** -->
<xsl:choose>
<xsl:when test="$SchemaObjParent/REFPAR_LEVEL > 0">1</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="fnHasRefPartitionedChildren">
<xsl:param name="SchemaObjParent" select="''"/>
<!-- *******************************************************************
Template: fnHasRefPartitionedChildren - return 1 if table has reference
partitioned children, i.e., if there is a table partitioned by reference
to it. If so, the table must have primary keys defined so that the child
table's fk constraint can reference it.
Note:
partobj$.flags:
/* 0x20 = table has ref ptn'ed children */
Parameters:
SchemaObjParent - parent of SCHEMA_OBJ node
******************************************************************** -->
<xsl:choose>
<xsl:when test="$SchemaObjParent/PART_OBJ and ($SchemaObjParent/PART_OBJ/PARTOBJ/FLAGS mod 64) >=32">1</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="fnIsDimensionTarget">
<xsl:param name="Property2">0</xsl:param>
<!-- *******************************************************************
Template: fnIsDimensionTarget - return 1 if table appears as a dimension
in one or more clustering clauses. The table must have a PK/UK constraint
Parameters:
Property2 - value of table PROPERTY2
******************************************************************** -->
<xsl:choose>
<xsl:when test="($Property2 mod 536870912)>=268435456">1</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="fnHasCON0Constraints">
<xsl:param name="ListParent" select="''"/>
<!-- *******************************************************************
Template: fnHasCON0Constraints - return 1 if table has CON0 constraints
Parameters:
ListParent - parent node of constraint list (e.g., CON1_LIST, CON2_LIST)
******************************************************************** -->
<xsl:choose>
<xsl:when test="$ListParent/CON0_LIST/CON0_LIST_ITEM">1</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="fnHasCON1Constraints">
<xsl:param name="ListParent" select="''"/>
<!-- *******************************************************************
Template: fnHasCON1Constraints - return 1 if table has CON1 constraints that
aren't OID or SETID or internally generated constr for valid time temporal
or are supplemental log types
Parameters:
ListParent - parent node of constraint list (e.g., CON1_LIST, CON2_LIST)
******************************************************************** -->
<!--
SUPPLEMENTAL LOG info -
from catmettypes.sql ku$_constraint1_t.contype
- supplemental log groups (w/ keys) (12),
- supplemental log data (no keys) (14,15,16,17)
-->
<xsl:variable name="SuppLog" select="$ListParent/CON1_LIST/CON1_LIST_ITEM[CONTYPE='12' or
CONTYPE='14' or CONTYPE='15' or CONTYPE='16' or
CONTYPE='17']"/>
<xsl:choose>
<xsl:when test="$ListParent/CON1_LIST/CON1_LIST_ITEM[(COL_LIST/COL_LIST_ITEM/OID_OR_SETID=0) and (FLAGS mod 4096) < 2048]">1</xsl:when>
<xsl:when test="$SuppLog">1</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="fnHasCON2Constraints">
<xsl:param name="ListParent" select="''"/>
<!-- *******************************************************************
Template: fnHasCON2Constraints - return 1 if table has CON2 constraints
Parameters:
ListParent - parent node of constraint list (e.g., CON1_LIST, CON2_LIST)
******************************************************************** -->
<xsl:choose>
<xsl:when test="$ListParent/CON2_LIST/CON2_LIST_ITEM">1</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="GenTableConstraints">
<xsl:param name="SchemaObjParent" select="''"/>
<xsl:param name="ListParent" select="''"/>
<xsl:param name="InColList">0</xsl:param>
<xsl:param name="CommaNeeded">0</xsl:param>
<xsl:param name="Property">0</xsl:param>
<xsl:param name="IsObjectTable">0</xsl:param>
<xsl:param name="IsIOT">0</xsl:param>
<xsl:param name="HasPkOID">0</xsl:param>
<xsl:param name="HasNotNull">0</xsl:param>
<xsl:param name="HasNonZeroPkRef">0</xsl:param>
<xsl:param name="IsRefPartitioned">0</xsl:param>
<xsl:param name="HasRefPartitionedChildren">0</xsl:param>
<xsl:param name="IsDimensionTarget">0</xsl:param>
<xsl:param name="HasCON0Constraints">0</xsl:param>
<xsl:param name="HasCON1Constraints">0</xsl:param>
<xsl:param name="HasCON2Constraints">0</xsl:param>
<xsl:param name="Nested">0</xsl:param>
<xsl:param name="FullName" select='""'/>
<!-- *******************************************************************
Template: GenTableConstraints - Generate Table Constraints
Parameters:
SchemaObjParent - parent of SCHEMA_OBJ node
ListParent - parent node of constraint list (e.g., CON1_LIST, CON2_LIST)
InColList - 1 = generating constraints after column list in CREATE TABLE
0 = adding constraint in ALTER TABLE
CommaNeeded - 1 = comma needed before first constraint
(e.g., when columns have been emitted and we must
emit a comma before putting out the constraints
Property - value of table PROPERTY
IsObjectTable - 1 = table is object table
IsIOT - 1 = table is IOT
HasPkOID - 1 = table has primary key-based OID$ column
HasNotNull - 1 = table has NOT NULL constraint on non-hidden column
HasNonZeroPkRef - 1 = constraint list has a PkRef constraint with
REFTYP not=0
IsRefPartitioned - 1 = table is reference partitioned.
HasRefPartitionedChildren - 1 = table has reference partitioned children
IsDimensionTarget - 1 = table appears as a dimension in one or more
clustering clauses
HasCON0Constraints - 1 = table has CON0 constraints
HasCON1Constraints - 1 = table has CON1 constraints
HasCON2Constraints - 1 = table has CON2 constraints
Nested - 1 = generating DDL for a nested table
Global Parameters:
CONSTRAINTS - 1 = emit constraints
REF_CONSTRAINTS - 1 = emit referential constraints
CONSTRAINTS_AS_ALTER - 1 = emit constraints as ALTER TABLE statements
EXPORT - 1 = generate export-specific DDL
SQLTERMINATOR - 1 = emit SQL terminator (;) after statement
PRETTY - 1 = pretty-print output
Notes:
A hierarchy of templates is invoked - each template decides when
and how each 'class' of constraint can be generated.
MUST keep the hierarchy of conditions in synch with template
TablePropertyParen!!!
Constraint types handled:
1 - Table Check - General - named, no Key cols, expr
(deferred Not NULL also)
2 - Primary Key - Idx cols - named, Key cols
3 - Unique Key - Idx cols - named, Key cols
4 - Referential (Foreign Key) - Col match - named, Key cols (2 sets)
5 - View WITH CHECK OPTION - View ctrl - named, clause in query
6 - View WITH READ ONLY - View ctrl - unnamed, clause in query
7 - Column Not Null - Col value - named, no Key cols
8 - Cluster hash expression - Hash expr - unnamed, ignored
9 - Scoped REF - REF match - unnamed, in REFCON, ignored
10 - REF with ROWID - REF value - unnamed, in REFCON, ignored
11 - REF/Attribute Not Null - Col value - named, no Key cols
12 - Log groups supp. logging - Log ctrl - named, Key cols, col attr.
13 - Allow PKref vals in REF col - REF value - unnamed, in REFCON, ignored
14 - Primary Key supp. logging - Log ctrl - unnamed, implied Key cols
15 - Unique Key supp. logging - Log ctrl - unnamed, implied Key cols
16 - Foreign Key supp. logging - Log ctrl - unnamed, implied Key cols
17 - ALL column supp. logging - Log ctrl - unnamed, implied Key cols
The following classes of constraints are generated in the following order
according to these rules:
[key: CON (CONSTRAINTS), EXP (EXPORT), REF_CON (REF_CONSTRAINTS)]
Class rule
============================ ==========================================
Object tbl col/attr NOT NULL - if CON / EXP, in CREATE (COL/CON0)
Primary keys for Iots/PkOIDs - always, in CREATE (CON1)
REFs, PkREFs - always, in CREATE or ALTER (PKREF)
ALTER only for Nested Tables
Non keyed, excluding NOT NULL- if CON, in CREATE or ALTER (CON0)
Other Primary keys - if CON, in CREATE or ALTER (CON1)
Unique keys/Table Check - if CON, in CREATE or ALTER (CON1)
Supplemental Log Groups/Data - if CON, in CREATE or ALTER (CON1)
Referential - if REF_CON, in CREATE or ALTER (CON2)
ALTER only for Nested Tables
******************************************************************** -->
<!--
NOT NULL constraints for object tables.
(Relational Table NOT NULLs are generated as part of Column defs,
see kucolumn.xsl)
(bit 0x0001 (01) of tab$.property = object table
bit 0x0020 (32) of col$.property = hidden column)
If Non-referential constraints or Export behavior -
Outer tbl: always in CREATE (could be in ALTER TABLE).
Nestd tbl: only in CREATE.
Note: The Schema Object Parent node has the COL_LIST
-->
<!-- Anything to generate?
locList1 - list of potential objects
locGenerate1 - 1 = there are objects to generate
-->
<xsl:variable name="locList1" select="$SchemaObjParent/COL_LIST/COL_LIST_ITEM[(PROPERTY mod 64)<32]//CON"/>
<xsl:variable name="locGenerate1">
<xsl:choose>
<xsl:when test="$CONSTRAINTS=0 and $EXPORT=0">0</xsl:when>
<xsl:when test="$IsObjectTable= 1 and $HasNotNull=1 and $InColList=1 and $locList1">1</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="TabPart" select="TABPART"/>
<xsl:if test="$locGenerate1=1">
<xsl:for-each select="$locList1">
<xsl:call-template name="DoCON_LIST_ITEM">
<xsl:with-param name="SchemaObjParent" select="$SchemaObjParent"/>
<xsl:with-param name="FullName" select="$FullName"/>
<xsl:with-param name="InColList">1</xsl:with-param>
<xsl:with-param name="CommaNeeded" select="$CommaNeeded"/>
<xsl:with-param name="Property" select="$Property"/>
<xsl:with-param name="Position" select="position()"/>
<xsl:with-param name="P2T_Node" select="$TabPart"/>
</xsl:call-template>
</xsl:for-each>
</xsl:if>
<!-- do we need a comma?
1. Yes if we came in needing one.
2. Yes if we just generated something.
3. Otherwise no.
-->
<xsl:variable name="locCommaNeeded1">
<xsl:choose>
<xsl:when test="$CommaNeeded=1">1</xsl:when>
<xsl:when test="$locGenerate1=1">1</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- PRIMARY KEY for IOTs/pkOIDs (CON1_LIST)
All tbl: in CREATE.
tab$.property bit 0x0040 (64) - IOT
bit 0x1000 (4096) - has pkoid column
contype 2 = primary key
-->
<!-- Anything to generate?
locList2 - list of potential objects
locGenerate2 - 1 = there are objects to generate
-->
<xsl:variable name="locList2" select="$ListParent/CON1_LIST/CON1_LIST_ITEM[CONTYPE='2']"/>
<xsl:variable name="locGenerate2">
<xsl:choose>
<xsl:when test="$InColList=1 and ($IsIOT=1 or $HasPkOID=1) and ($locList2)">1</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:if test="$locGenerate2=1">
<xsl:for-each select="$locList2">
<xsl:call-template name="DoCON_LIST_ITEM">
<xsl:with-param name="SchemaObjParent" select="$SchemaObjParent"/>
<xsl:with-param name="FullName" select="$FullName"/>
<xsl:with-param name="InColList">1</xsl:with-param>
<xsl:with-param name="CommaNeeded" select="$locCommaNeeded1"/>
<xsl:with-param name="Property" select="$Property"/>
<xsl:with-param name="Position" select="position()"/>
<xsl:with-param name="P2T_Node" select="$TabPart"/>
</xsl:call-template>
</xsl:for-each>
</xsl:if>
<!-- do we need a comma?
1. Yes if we came in needing one.
2. Yes if we just generated something.
3. Otherwise no.
-->
<xsl:variable name="locCommaNeeded2">
<xsl:choose>
<xsl:when test="$locCommaNeeded1=1">1</xsl:when>
<xsl:when test="$locGenerate2=1">1</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- REFs and PKREFs (PKREF_LIST)
Always generated.
Outer tbl: in CREATE or ALTER TABLE.
Nestd tbl: only in ALTER TABLE (Due to Scoped REFs).
Only non 0 type, excluding SCOPEd REF in CREATE if also a Foreign Key
and dumping Referential constraints
Also exclude ref generated for xdb:SQLInline="false" AND
Exclude unused columns
-->
<!-- Anything to generate?
locList3 - list of potential objects
locGenerate3 - 1 = there are objects to generate
-->
<xsl:variable name="locList3" select="$ListParent/PKREF_LIST/PKREF_LIST_ITEM[
(REFTYP mod 16)>0
and
not ((REFTYP mod 2)=1 and $REF_CONSTRAINTS=1 and
$InColList=1 and FOREIGNKEY=1)
and
not ((REFTYP mod 32)>16 and (PROPERTY mod 64)>=32)
and ((PROPERTY mod 65536)<32768)]"/>
<xsl:variable name="locGenerate3">
<xsl:choose>
<xsl:when test="((($Nested=0 and $InColList!=$CONSTRAINTS_AS_ALTER) or
($Nested=1 and $InColList=0)) and $HasNonZeroPkRef=1)
and $locList3">1</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:if test="$locGenerate3=1">
<xsl:for-each select="$locList3">
<xsl:sort select="INTCOL_NUM" data-type="number"/>
<xsl:call-template name="DoPKREF_LIST_ITEM">
<xsl:with-param name="SchemaObjParent" select="$SchemaObjParent"/>
<xsl:with-param name="FullName" select="$FullName"/>
<xsl:with-param name="ListParent" select="$ListParent"/>
<xsl:with-param name="InColList" select="$InColList"/>
<xsl:with-param name="CommaNeeded" select="$locCommaNeeded2"/>
<xsl:with-param name="Position" select="position()"/>
</xsl:call-template>
</xsl:for-each>
</xsl:if>
<!-- do we need a comma?
1. Yes if we came in needing one.
2. Yes if we just generated something.
3. Otherwise no.
-->
<xsl:variable name="locCommaNeeded3">
<xsl:choose>
<xsl:when test="$locCommaNeeded2=1">1</xsl:when>
<xsl:when test="$locGenerate3=1">1</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- 'Non key' constraints (CON0_LIST)
Only if Non referential constraints.
All tbl: in CREATE or ALTER TABLE.
(NOT NULLs have already been excluded, so presently none for tables)
-->
<!-- Anything to generate?
locList4 - list of potential objects
locGenerate4 - 1 = there are objects to generate
-->
<xsl:variable name="locList4" select="$ListParent/CON0_LIST/CON0_LIST_ITEM"/>
<xsl:variable name="locGenerate4">
<xsl:choose>
<xsl:when test="$CONSTRAINTS=1 and
$InColList!=$CONSTRAINTS_AS_ALTER and
$HasCON0Constraints=1 and
$locList4">1</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:if test="$locGenerate4=1">
<xsl:for-each select="$locList4">
<xsl:sort select="CON_NUM" data-type="number"/>
<xsl:call-template name="DoCON_LIST_ITEM">
<xsl:with-param name="SchemaObjParent" select="$SchemaObjParent"/>
<xsl:with-param name="FullName" select="$FullName"/>
<xsl:with-param name="InColList" select="$InColList"/>
<xsl:with-param name="CommaNeeded" select="$locCommaNeeded3"/>
<xsl:with-param name="Property" select="$Property"/>
<xsl:with-param name="Position" select="position()"/>
<xsl:with-param name="P2T_Node" select="$TabPart"/>
</xsl:call-template>
</xsl:for-each>
</xsl:if>
<!-- do we need a comma?
1. Yes if we came in needing one.
2. Yes if we just generated something.
3. Otherwise no.
-->
<xsl:variable name="locCommaNeeded4">
<xsl:choose>
<xsl:when test="$locCommaNeeded3=1">1</xsl:when>
<xsl:when test="$locGenerate4=1">1</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- CON1_LIST: Table check,
Primary Key for non IOT/PkOID,
Unique Key for non-OID or SETID -->
<!-- Anything to generate?
locList5 - list of potential objects
exclude
OID or SETID
internally generated constr for valid time temporal
contype values in CON1_LIST:
table check (condition-no keys) (1),
primary key (2),
unique key (3),
supplemental log groups (w/ keys) (12),
supplemental log data (no keys) (14,15,16,17)
locGenerate5 - 1 = there are objects to generate
- normal case: user asked for constraints and there are some
- for data pump force pk/uk constraints for dimension tables
-->
<xsl:variable name="locList5" select="$ListParent/CON1_LIST/CON1_LIST_ITEM[
COL_LIST/COL_LIST_ITEM/OID_OR_SETID=0 and
(FLAGS mod 4096) < 2048 and
not ((CONTYPE='2' and ($IsIOT=1 or $HasPkOID=1)) or
CONTYPE='12' or CONTYPE='14' or CONTYPE='15' or
CONTYPE='16' or CONTYPE='17')]"/>
<xsl:variable name="locGenerate5">
<xsl:choose>
<xsl:when test="$CONSTRAINTS=1 and $InColList!=$CONSTRAINTS_AS_ALTER and
$locList5">1</xsl:when>
<xsl:when test="$IsDimensionTarget=1 and $EXPORT=1 and $InColList=1">1</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:if test="$locGenerate5=1">
<xsl:for-each select="$locList5">
<xsl:sort select="CON_NUM" data-type="number"/>
<xsl:call-template name="DoCON_LIST_ITEM">
<xsl:with-param name="SchemaObjParent" select="$SchemaObjParent"/>
<xsl:with-param name="FullName" select="$FullName"/>
<xsl:with-param name="InColList" select="$InColList"/>
<xsl:with-param name="CommaNeeded" select="$locCommaNeeded4"/>
<xsl:with-param name="Property" select="$Property"/>
<xsl:with-param name="Position" select="position()"/>
<xsl:with-param name="P2T_Node" select="$TabPart"/>
</xsl:call-template>
</xsl:for-each>
</xsl:if>
<!-- do we need a comma?
1. Yes if we came in needing one.
2. Yes if we just generated something.
3. Otherwise no.
-->
<xsl:variable name="locCommaNeeded5">
<xsl:choose>
<xsl:when test="$locCommaNeeded4=1">1</xsl:when>
<xsl:when test="$locGenerate5=1">1</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- CON1_LIST: pk/uk constraints for tables with ref partn children -->
<!-- Anything to generate?
locList5a - list of potential objects
locGenerate5a - 1 = there are objects to generate
-->
<xsl:variable name="locList5a" select="$ListParent/CON1_LIST/CON1_LIST_ITEM[
COL_LIST/COL_LIST_ITEM/OID_OR_SETID=0 and
(CONTYPE='2' or CONTYPE='3') and
((FLAGS mod 2048) >= 1024)]"/>
<xsl:variable name="locGenerate5a">
<xsl:choose>
<xsl:when test="$CONSTRAINTS=0 and $InColList=1 and $EXPORT=1 and $HasRefPartitionedChildren=1 and $locList5a">1</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:if test="$locGenerate5a=1">
<xsl:for-each select="$locList5a">
<xsl:sort select="CON_NUM" data-type="number"/>
<xsl:call-template name="DoCON_LIST_ITEM">
<xsl:with-param name="SchemaObjParent" select="$SchemaObjParent"/>
<xsl:with-param name="FullName" select="$FullName"/>
<xsl:with-param name="InColList" select="$InColList"/>
<xsl:with-param name="CommaNeeded" select="$locCommaNeeded5"/>
<xsl:with-param name="Property" select="$Property"/>
<xsl:with-param name="Position" select="position()"/>
<xsl:with-param name="P2T_Node" select="$TabPart"/>
</xsl:call-template>
</xsl:for-each>
</xsl:if>
<!-- do we need a comma?
1. Yes if we came in needing one.
2. Yes if we just generated something.
3. Otherwise no.
-->
<xsl:variable name="locCommaNeeded5a">
<xsl:choose>
<xsl:when test="$locCommaNeeded5=1">1</xsl:when>
<xsl:when test="$locGenerate5a=1">1</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- CON1_LIST: Supplemental Log Groups/Log Data -->
<!-- Anything to generate?
locList6 - list of potential objects
contype values in CON1_LIST:
table check (condition-no keys) (1),
primary key (2),
unique key (3),
supplemental log groups (w/ keys) (12),
supplemental log data (no keys) (14,15,16,17)
locGenerate6 - 1 = there are objects to generate
-->
<xsl:variable name="locList6" select="$ListParent/CON1_LIST/CON1_LIST_ITEM[CONTYPE='12' or
CONTYPE='14' or CONTYPE='15' or CONTYPE='16' or
CONTYPE='17']"/>
<xsl:variable name="locGenerate6">
<xsl:choose>
<xsl:when test="$CONSTRAINTS=1 and $InColList!=$CONSTRAINTS_AS_ALTER and
$locList6">1</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:if test="$locGenerate6=1">
<xsl:for-each select="$locList6">
<xsl:sort select="CON_NUM" data-type="number"/>
<xsl:call-template name="DoCON_LIST_ITEM">
<xsl:with-param name="SchemaObjParent" select="$SchemaObjParent"/>
<xsl:with-param name="FullName" select="$FullName"/>
<xsl:with-param name="InColList" select="$InColList"/>
<xsl:with-param name="CommaNeeded" select="$locCommaNeeded5a"/>
<xsl:with-param name="Property" select="$Property"/>
<xsl:with-param name="Position" select="position()"/>
<xsl:with-param name="P2T_Node" select="$TabPart"/>
</xsl:call-template>
</xsl:for-each>
</xsl:if>
<!-- do we need a comma?
1. Yes if we came in needing one.
2. Yes if we just generated something.
3. Otherwise no.
-->
<xsl:variable name="locCommaNeeded6">
<xsl:choose>
<xsl:when test="$locCommaNeeded5a=1">1</xsl:when>
<xsl:when test="$locGenerate6=1">1</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- CON2_LIST: Foreign key constraints
(but not those needed for refpar tables) -->
<!-- Anything to generate?
locList7 - list of potential objects
locGenerate7 - 1 = there are objects to generate
- Only if referential constraints.
Outer tbl: in CREATE or ALTER TABLE
Nestd tbl: only in ALTER TABLE (NESTED_TABLE_ID refs SETID of self)
-->
<xsl:variable name="locList7" select="$ListParent/CON2_LIST/CON2_LIST_ITEM[(FLAGS mod 1024) < 512]"/>
<xsl:variable name="locGenerate7">
<xsl:choose>
<xsl:when test="$REF_CONSTRAINTS=1 and
(($Nested=0 and $InColList!=$CONSTRAINTS_AS_ALTER) or
($Nested=1 and $InColList=0)) and $locList7">1</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:if test="$locGenerate7=1">
<xsl:for-each select="$locList7">
<xsl:sort select="CON_NUM" data-type="number"/>
<xsl:call-template name="DoCON_LIST_ITEM">
<xsl:with-param name="SchemaObjParent" select="$SchemaObjParent"/>
<xsl:with-param name="FullName" select="$FullName"/>
<xsl:with-param name="InColList" select="$InColList"/>
<xsl:with-param name="CommaNeeded" select="$locCommaNeeded6"/>
<xsl:with-param name="Property" select="$Property"/>
<xsl:with-param name="Position" select="position()"/>
<xsl:with-param name="P2T_Node" select="$TabPart"/>
</xsl:call-template>
</xsl:for-each>
</xsl:if>
<!-- do we need a comma?
1. Yes if we came in needing one.
2. Yes if we just generated something.
3. Otherwise no.
-->
<xsl:variable name="locCommaNeeded7">
<xsl:choose>
<xsl:when test="$locCommaNeeded6=1">1</xsl:when>
<xsl:when test="$locGenerate7=1">1</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- CON2_LIST: Foreign key constraints needed for refpar tables) -->
<!-- Anything to generate?
locList8 - list of potential objects
/* 0x200 (512) constraint is a partitioning constraint */
locGenerate8 - 1 = there are objects to generate
-->
<xsl:variable name="locList8" select="$ListParent/CON2_LIST/CON2_LIST_ITEM[$Nested=0 and ((FLAGS mod 1024) >= 512)]"/>
<xsl:variable name="locGenerate8">
<xsl:choose>
<xsl:when test="$IsRefPartitioned=1 and $InColList=1 and $locList8">1</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:if test="$locGenerate8=1">
<xsl:for-each select="$locList8">
<xsl:sort select="CON_NUM" data-type="number"/>
<xsl:call-template name="DoCON_LIST_ITEM">
<xsl:with-param name="SchemaObjParent" select="$SchemaObjParent"/>
<xsl:with-param name="FullName" select="$FullName"/>
<xsl:with-param name="InColList" select="$InColList"/>
<xsl:with-param name="CommaNeeded" select="$locCommaNeeded7"/>
<xsl:with-param name="Property" select="$Property"/>
<xsl:with-param name="Position" select="position()"/>
<xsl:with-param name="P2T_Node" select="$TabPart"/>
</xsl:call-template>
</xsl:for-each>
</xsl:if>
</xsl:template>
<xsl:template name="DoCON_LIST_ITEM">
<xsl:param name="SchemaObjParent" select="''"/>
<xsl:param name="FullName" select='""'/>
<xsl:param name="InColList">0</xsl:param>
<xsl:param name="CommaNeeded">0</xsl:param>
<xsl:param name="Property">0</xsl:param>
<xsl:param name="Position">0</xsl:param>
<xsl:param name="P2T_Node" select="''"/>
<!-- *******************************************************************
Template: DoCON_LIST_ITEM
Gen. out-of-line constraint as ALTER TABLE ADD or in CREATE TABLE
(all constraints other than REFs/pkREFs).
Provides statement termination, list item comma separation,
object name for NOT NULL.
Parameters:
SchemaObjParent - parent of SCHEMA_OBJ node
InColList - 1 = generating constraints after column list in CREATE TABLE
0 = adding constraint in ALTER TABLE
CommaNeeded - 1 = comma needed before first constraint
(e.g., when columns have been emitted and we must
emit a comma before putting out the constraints
Property - value of table PROPERTY
Position - position of COL_LIST_ITEM in COL_LIST
******************************************************************** -->
<xsl:choose>
<xsl:when test="$InColList=0">
<!-- ALTER TABLE ADD -->
<xsl:call-template name="DoParse">
<xsl:with-param name="Verb">ALTER</xsl:with-param>
<xsl:with-param name="ObjectType">TABLE</xsl:with-param>
<xsl:with-param name="SchemaNode" select="$SchemaObjParent/SCHEMA_OBJ/OWNER_NAME"/>
<xsl:with-param name="NameNode" select="$SchemaObjParent/SCHEMA_OBJ/NAME"/>
</xsl:call-template>
<xsl:text>
ALTER TABLE </xsl:text>
<xsl:call-template name="QuoteObject">
<xsl:with-param name="Schema" select="$SchemaObjParent/SCHEMA_OBJ/OWNER_NAME"/>
<xsl:with-param name="Object" select="$FullName"/>
</xsl:call-template>
<xsl:text> ADD</xsl:text>
<xsl:call-template name="DoConstraint">
<xsl:with-param name="TAB_CONSTRAINT">1</xsl:with-param>
<xsl:with-param name="Property" select="$Property"/>
<xsl:with-param name="ConstraintNode" select="current()"/>
<xsl:with-param name="ColListNode" select="$SchemaObjParent/COL_LIST"/>
<xsl:with-param name="P2T_Node" select="$P2T_Node"/>
</xsl:call-template>
<xsl:if test="$SQLTERMINATOR=1">
<xsl:text>;</xsl:text>
<!-- Terminate the SQL statement -->
</xsl:if>
</xsl:when>
<xsl:otherwise>
<!-- CREATE TABLE (In column list) -->
<xsl:if test="$CommaNeeded=1 and $Position=1">
<xsl:text>, </xsl:text>
<xsl:if test="$PRETTY=1">
<xsl:text>
	</xsl:text>
</xsl:if>
</xsl:if>
<!-- Object table column/attribute name for NOT NULL -->
<xsl:if test="CONTYPE='7' or CONTYPE='11'">
<xsl:text> </xsl:text>
<xsl:call-template name="ColNameOrAttr">
<xsl:with-param name="ColItem" select=".."/>
</xsl:call-template>
</xsl:if>
<xsl:call-template name="DoConstraint">
<xsl:with-param name="TAB_CONSTRAINT">1</xsl:with-param>
<xsl:with-param name="Property" select="$Property"/>
<xsl:with-param name="ConstraintNode" select="current()"/>
<xsl:with-param name="ColListNode" select="$SchemaObjParent/COL_LIST"/>
<xsl:with-param name="P2T_Node" select="$P2T_Node"/>
</xsl:call-template>
<xsl:if test="not($Position=last())">
<xsl:text>, </xsl:text>
<xsl:if test="$PRETTY=1">
<xsl:text>
	</xsl:text>
</xsl:if>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="DoPKREF_LIST_ITEM">
<xsl:param name="SchemaObjParent" select="''"/>
<xsl:param name="ListParent" select="''"/>
<xsl:param name="InColList">0</xsl:param>
<xsl:param name="CommaNeeded">0</xsl:param>
<xsl:param name="Position">0</xsl:param>
<xsl:variable name="TableName">
<xsl:choose>
<xsl:when test="$FORCE_UNIQUE=1">
<xsl:text>"</xsl:text>
<xsl:value-of select="$SchemaObjParent/SCHEMA_OBJ/OWNER_NAME"/>
<xsl:text>".KU$</xsl:text>
<xsl:value-of select="$SchemaObjParent/NTAB_NUM"/>
<xsl:value-of select='"NT"'/>
<xsl:value-of select="$SchemaObjParent/INTCOL_NUM"/>
<xsl:value-of select='" "'/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="$SchemaObjParent/SCHEMA_OBJ"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- *******************************************************************
Template: DoPKREF_LIST_ITEM
Gen. out-of-line REF/pkREF constr. as ALTER TABLE ADD or in CREATE TABLE.
Provides statement termination, list item comma separation,
special formatting.
(This is DoCON_LIST_ITEM/DoConstraint combined for REFs).
Parameters:
SchemaObjParent - parent of SCHEMA_OBJ node
ListParent - parent node of constraint list (e.g., CON1_LIST, CON2_LIST)
InColList - 1 = generating constraints after column list in CREATE TABLE
0 = adding constraint in ALTER TABLE
CommaNeeded - 1 = comma needed before first constraint
(e.g., when columns have been emitted and we must
emit a comma before putting out the constraints
Property - value of table PROPERTY
Position - position of PKREF_LIST_ITEM in PKREF_LIST
******************************************************************** -->
<!--
... All REFs with non 0 type add REF constraints ...
reftyp number not null /* REF type flag */
/* 0x01 = REF is scoped */
/* 0x02 = REF stored with rowid */
/* 0x04 = Primary key based ref */
/* 0x08 = Allow unscoped Primary key based ref */
... Except that SCOPE is skipped if col. list FOREIGN KEY for that REF ...
-->
<xsl:if test="$InColList=1">
<!-- Setup if In column list -->
<xsl:if test="$CommaNeeded=1 and $Position=1">
<xsl:text>, </xsl:text>
<xsl:if test="$PRETTY=1">
<xsl:text>
</xsl:text>
</xsl:if>
</xsl:if>
</xsl:if>
<xsl:choose>
<xsl:when test="(REFTYP mod 2)=1">
<!-- Scoped, possibly pkREF -->
<xsl:choose>
<!-- In column list or stand alone -->
<xsl:when test="$InColList=0">
<!-- Stand alone -->
<xsl:call-template name="DoParse">
<xsl:with-param name="Verb">ALTER</xsl:with-param>
<xsl:with-param name="ObjectType">TABLE</xsl:with-param>
<xsl:with-param name="SchemaNode" select="$SchemaObjParent/SCHEMA_OBJ/OWNER_NAME"/>
<xsl:with-param name="NameNode" select="$SchemaObjParent/SCHEMA_OBJ/NAME"/>
</xsl:call-template>
<xsl:text>
ALTER TABLE </xsl:text>
<xsl:apply-templates select="$SchemaObjParent/SCHEMA_OBJ"/>
<xsl:text>ADD SCOPE FOR (</xsl:text>
<xsl:call-template name="ColNameOrAttr">
<xsl:with-param name="ColItem" select="current()"/>
</xsl:call-template>
<xsl:text>) IS </xsl:text>
<xsl:choose>
<!-- Refer to Scope by OID or Name -->
<!-- Classic export also uses MdApi to export xml schema tables -->
<xsl:when test="$EXPORT=1 or $OLDEXPORT=1">
<!-- OID for Export -->
<xsl:text>OID '</xsl:text>
<xsl:value-of select="SCHEMA_OBJ/OID"/>
<xsl:text>'</xsl:text>
<xsl:choose>
<xsl:when test="(REFTYP mod 8)>=5">
<!-- pkREF requires pkey cols -->
<xsl:text> USER_DEFINED (</xsl:text>
<xsl:for-each select="PK_COL_LIST/PK_COL_LIST_ITEM">
<xsl:call-template name="ColNameOrAttr">
<xsl:with-param name="ColItem" select="current()"/>
</xsl:call-template>
<xsl:if test="not(position()=last())">
<xsl:text>, </xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:text>)</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:if test="FOREIGNKEY=1">
<!-- sREF with FOREIGN KEY constraint requires exploded cols -->
<xsl:text> SYSTEM_DEFINED</xsl:text>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<!-- Scope is table name for others -->
<xsl:apply-templates select="SCHEMA_OBJ"/>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="$SQLTERMINATOR=1">
<xsl:text>;</xsl:text>
<!-- Terminate the SQL statement -->
</xsl:if>
</xsl:when>
<!-- Stand alone -->
<xsl:otherwise>
<!-- Scoped, In column list -->
<xsl:if test="$PRETTY=1">
<xsl:text>	</xsl:text>
</xsl:if>
<xsl:text>SCOPE FOR (</xsl:text>
<xsl:call-template name="ColNameOrAttr">
<xsl:with-param name="ColItem" select="current()"/>
</xsl:call-template>
<xsl:text>) IS </xsl:text>
<xsl:choose>
<!--Scope by OID or Name (see above) -->
<xsl:when test="$EXPORT=1">
<xsl:text>OID '</xsl:text>
<xsl:value-of select="SCHEMA_OBJ/OID"/>
<xsl:text>'</xsl:text>
<xsl:choose>
<xsl:when test="(REFTYP mod 8)>=5">
<xsl:if test="$PRETTY=1">
<xsl:text>
	 </xsl:text>
</xsl:if>
<xsl:text> USER_DEFINED (</xsl:text>
<xsl:for-each select="PK_COL_LIST/PK_COL_LIST_ITEM">
<xsl:call-template name="ColNameOrAttr">
<xsl:with-param name="ColItem" select="current()"/>
</xsl:call-template>
<xsl:if test="not(position()=last())">
<xsl:text>, </xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:text>)</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:if test="FOREIGNKEY=1">
<xsl:if test="$PRETTY=1">
<xsl:text>
	 </xsl:text>
</xsl:if>
<xsl:text> SYSTEM_DEFINED</xsl:text>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="SCHEMA_OBJ"/>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="not($Position=last())">
<xsl:text>, </xsl:text>
<xsl:if test="$PRETTY=1">
<xsl:text>
</xsl:text>
</xsl:if>
</xsl:if>
</xsl:otherwise>
<!-- In column list -->
</xsl:choose>
</xsl:when>
<!-- Scoped -->
<xsl:otherwise>
<!-- Not scoped -->
<xsl:if test="(REFTYP mod 4)=2">
<!-- ROWID hint -->
<xsl:choose>
<!-- In column list or stand alone -->
<xsl:when test="$InColList=0">
<!-- Stand alone -->
<xsl:call-template name="DoParse">
<xsl:with-param name="Verb">ALTER</xsl:with-param>
<xsl:with-param name="ObjectType">TABLE</xsl:with-param>
<xsl:with-param name="SchemaNode" select="$SchemaObjParent/SCHEMA_OBJ/OWNER_NAME"/>
<xsl:with-param name="NameNode" select="$SchemaObjParent/SCHEMA_OBJ/NAME"/>
</xsl:call-template>
<xsl:text>
ALTER TABLE </xsl:text>
<xsl:value-of select="$TableName"/>
<xsl:text>ADD REF (</xsl:text>
<xsl:call-template name="ColNameOrAttr">
<xsl:with-param name="ColItem" select="current()"/>
</xsl:call-template>
<xsl:text>) WITH ROWID</xsl:text>
<xsl:if test="$SQLTERMINATOR=1">
<xsl:text>;</xsl:text>
<!-- Terminate the SQL statement -->
</xsl:if>
</xsl:when>
<xsl:otherwise>
<!-- ROWID, In column list -->
<xsl:if test="$PRETTY=1">
<xsl:text>	</xsl:text>
</xsl:if>
<xsl:text>REF (</xsl:text>
<xsl:call-template name="ColNameOrAttr">
<xsl:with-param name="ColItem" select="current()"/>
</xsl:call-template>
<xsl:text>) WITH ROWID</xsl:text>
<xsl:choose>
<xsl:when test="(REFTYP mod 16)=10">
<!-- ALLOW also? -->
<xsl:text>, </xsl:text>
<!-- Yes, always comma seperate -->
<xsl:if test="$PRETTY=1">
<xsl:text>
</xsl:text>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<!-- No - prepare for any next REF item -->
<xsl:if test="not($Position=last())">
<xsl:text>, </xsl:text>
<xsl:if test="$PRETTY=1">
<xsl:text>
</xsl:text>
</xsl:if>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
<!-- In column list -->
</xsl:choose>
</xsl:if>
<!-- ROWID syntax -->
<xsl:if test="(REFTYP mod 16)>=8">
<!-- ALLOW PRIMARY KEY -->
<xsl:choose>
<!-- In column list or stand alone -->
<xsl:when test="$InColList=0">
<!-- Stand alone -->
<xsl:call-template name="DoParse">
<xsl:with-param name="Verb">ALTER</xsl:with-param>
<xsl:with-param name="ObjectType">TABLE</xsl:with-param>
<xsl:with-param name="SchemaNode" select="$SchemaObjParent/SCHEMA_OBJ/OWNER_NAME"/>
<xsl:with-param name="NameNode" select="$SchemaObjParent/SCHEMA_OBJ/NAME"/>
</xsl:call-template>
<xsl:text>
ALTER TABLE </xsl:text>
<xsl:value-of select="$TableName"/>
<xsl:text>ADD REF (</xsl:text>
<xsl:call-template name="ColNameOrAttr">
<xsl:with-param name="ColItem" select="current()"/>
</xsl:call-template>
<xsl:text>) ALLOW PRIMARY KEY</xsl:text>
<xsl:if test="$SQLTERMINATOR=1">
<xsl:text>;</xsl:text>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<!-- In column list -->
<xsl:if test="$PRETTY=1">
<xsl:text>	</xsl:text>
</xsl:if>
<xsl:text>REF (</xsl:text>
<xsl:call-template name="ColNameOrAttr">
<xsl:with-param name="ColItem" select="current()"/>
</xsl:call-template>
<xsl:text>) ALLOW PRIMARY KEY</xsl:text>
<xsl:if test="not($Position=last())">
<xsl:text>, </xsl:text>
<xsl:if test="$PRETTY=1">
<xsl:text>
</xsl:text>
</xsl:if>
</xsl:if>
</xsl:otherwise>
<!-- In column list -->
</xsl:choose>
</xsl:if>
<!-- ALLOW syntax -->
</xsl:otherwise>
<!-- Not scoped -->
</xsl:choose>
</xsl:template>
<xsl:template name="fnHasTableProperties">
<xsl:param name="IsObjectTable">0</xsl:param>
<xsl:param name="IsIOT">0</xsl:param>
<xsl:param name="HasPkOID">0</xsl:param>
<xsl:param name="HasNotNull">0</xsl:param>
<xsl:param name="HasNonZeroPkRef">0</xsl:param>
<xsl:param name="IsRefPartitioned">0</xsl:param>
<xsl:param name="HasRefPartitionedChildren">0</xsl:param>
<xsl:param name="IsDimensionTarget">0</xsl:param>
<xsl:param name="HasCON0Constraints">0</xsl:param>
<xsl:param name="HasCON1Constraints">0</xsl:param>
<xsl:param name="HasCON2Constraints">0</xsl:param>
<xsl:param name="Nested">0</xsl:param>
<!-- *******************************************************************
Template: fnHasTableProperties - return 1 if we will generate
clauses that need parens around them, e.g.,
col list for relational table
constraints
nested table storage clauses
Parameters:
IsObjectTable - 1 = table is object table
IsIOT - 1 = table is IOT
HasPkOID - 1 = table has primary key-based OID$ column
HasNotNull - 1 = table has NOT NULL constraint on non-hidden column
HasNonZeroPkRef - 1 = constraint list has a PkRef constraint with
REFTYP not=0
IsRefPartitioned - 1 = table is reference partitioned.
HasRefPartitionedChildren - 1 = table has reference partitioned children
IsDimensionTarget - 1 = table appears as a dimension in one or more
clustering clauses
HasCON0Constraints - 1 = table has CON0 constraints
HasCON1Constraints - 1 = table has CON1 constraints
HasCON2Constraints - 1 = table has CON2 constraints
Nested - 1 = generating DDL for a nested table
Global Parameters:
CONSTRAINTS - 1 = emit constraints
REF_CONSTRAINTS - 1 = emit referential constraints
CONSTRAINTS_AS_ALTER - 1 = emit constraints as ALTER TABLE statements
EXPORT - 1 = generate export-specific DDL
Explanation of the cases:
1. If the table is not a nested table or an object table, then
we are going to generate a column list, so parens are needed.
2. For IOTs we must include the primary key constraint, so parens needed.
3. If the table has a primary key-based OID$ column, then we need
to generate the primary key constraint.
4. Non-null constraint on a non-hidden column in an object table.
For relational tables the NOT NULL is declared inline; for object tables
it must be out of line (because the DDL doesn't include a column list).
We always generate this constraint for data pump (EXPORT=1),
but we can omit it if the user doesn't want constraints.
5. If the table is reference partitioned, we must generate a FK constraint.
6. If the table has reference partitioned children, we must generate
a PK constraint (if there is one).
7. If the table appears as a dimension in a clustering clause, then it
must have a PK/UK constraint
8. In the previous cases we had to include the constraint definition
in the CREATE TABLE ddl. For the remaining cases we can add the
constraint in an ALTER TABLE. So if we got this far, don't need parens.
9. There is a PkRef constraint with REFTYP not=0.
10. The user wants constraints and we have CON0 or CON1 constraints.
11. The user wants fk constraints and we have CON2 constraints (but not
for a nested table).
12. Otherwise we don't need parens.
******************************************************************** -->
<xsl:choose>
<xsl:when test="$IsObjectTable=0 and $Nested=0">1</xsl:when>
<xsl:when test="$IsIOT=1">1</xsl:when>
<xsl:when test="$HasPkOID=1">1</xsl:when>
<xsl:when test="$IsObjectTable=1 and ($CONSTRAINTS=1 or $EXPORT=1) and $HasNotNull=1">1</xsl:when>
<xsl:when test="$IsRefPartitioned=1">1</xsl:when>
<xsl:when test="$HasRefPartitionedChildren=1 and $HasCON1Constraints=1">1</xsl:when>
<xsl:when test="$IsDimensionTarget=1">1</xsl:when>
<xsl:when test="$CONSTRAINTS_AS_ALTER=1">0</xsl:when>
<xsl:when test="$HasNonZeroPkRef=1">1</xsl:when>
<xsl:when test="$CONSTRAINTS=1 and ($HasCON0Constraints=1 or $HasCON1Constraints=1)">1</xsl:when>
<xsl:when test="$REF_CONSTRAINTS=1 and $Nested=0 and $HasCON2Constraints=1">1</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="TablePropertyParen">
<xsl:param name="OpenParen">1</xsl:param>
<xsl:param name="Nested">0</xsl:param>
<xsl:param name="Storage">0</xsl:param>
<!-- *******************************************************************
Template: TablePropertyParen - emit the parens around the relational or
object properties.
Parameters:
OpenParen - 1 = emit '('
else ')'
Nested - 1 = generating DDL for a nested table
Storage - 1 = emitting storage table properties for nested table
Global Parameters:
PRETTY - 1 = pretty-print output
******************************************************************** -->
<xsl:if test="$Nested=0 and $Storage=0 and $PRETTY=1">
<xsl:choose>
<xsl:when test="$OpenParen=1">
<xsl:text> </xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>
 </xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
<xsl:call-template name="EmitParen">
<xsl:with-param name="OpenParen" select="$OpenParen"/>
</xsl:call-template>
<xsl:if test="$Nested=1 and $Storage=0 and $OpenParen=0 and $PRETTY=1">
<xsl:text>
</xsl:text>
</xsl:if>
</xsl:template>
<xsl:template name="EmitParen">
<xsl:param name="OpenParen">1</xsl:param>
<!-- *******************************************************************
Template: EmitParen
Emit open or close paren for table properties/nested storage
Parameters:
OpenParen - 1 = emit '('
else ')'
******************************************************************** -->
<xsl:choose>
<xsl:when test="$OpenParen=1">(</xsl:when>
<xsl:otherwise>) </xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
OHA YOOOO