Sorted the problem of generating null tests for non-nullable characters in C# entities;

Removed square brackets from SQL keywords in generated SQL (relying on quotes instead).
This commit is contained in:
sb 2008-07-21 10:00:48 +00:00
parent 2c0d8ae5ca
commit ac72992239
2 changed files with 46 additions and 17 deletions

View file

@ -8,8 +8,8 @@
Transform ADL into entity classes Transform ADL into entity classes
$Author: sb $ $Author: sb $
$Revision: 1.9 $ $Revision: 1.10 $
$Date: 2008-07-15 16:41:31 $ $Date: 2008-07-21 10:00:48 $
--> -->
<!-- WARNING WARNING WARNING: Do NOT reformat this file! <!-- WARNING WARNING WARNING: Do NOT reformat this file!
@ -61,7 +61,7 @@
// (c)2007 Cygnet Solutions Ltd // (c)2007 Cygnet Solutions Ltd
// //
// Automatically generated from application description using // Automatically generated from application description using
// adl2entityclass.xsl revision <xsl:value-of select="substring( '$Revision: 1.9 $', 10)"/> // adl2entityclass.xsl revision <xsl:value-of select="substring( '$Revision: 1.10 $', 10)"/>
// //
// <xsl:value-of select="/adl:application/@revision"/> // <xsl:value-of select="/adl:application/@revision"/>
// //
@ -85,7 +85,7 @@
/// &lt;/summary&gt; /// &lt;/summary&gt;
/// &lt;remarks&gt; /// &lt;remarks&gt;
/// Automatically generated from description of entity <xsl:value-of select="@name"/> /// Automatically generated from description of entity <xsl:value-of select="@name"/>
/// using adl2entityclass.xsl revision <xsl:value-of select="substring( '$Revision: 1.9 $', 10)"/>. /// using adl2entityclass.xsl revision <xsl:value-of select="substring( '$Revision: 1.10 $', 10)"/>.
/// Note that manually maintained parts of this class may be defined in /// Note that manually maintained parts of this class may be defined in
/// a separate file called <xsl:value-of select="@name"/>.manual.cs, q.v. /// a separate file called <xsl:value-of select="@name"/>.manual.cs, q.v.
/// ///
@ -164,26 +164,39 @@
<xsl:choose> <xsl:choose>
<xsl:when test="descendant::adl:property[@distinct='user' or @distinct='all']"> <xsl:when test="descendant::adl:property[@distinct='user' or @distinct='all']">
<xsl:for-each select="descendant::adl:property[@distinct='user' or @distinct='all']"> <xsl:for-each select="descendant::adl:property[@distinct='user' or @distinct='all']">
if ( <xsl:value-of select="@name"/> != null){
<xsl:choose> <xsl:choose>
<xsl:when test="@type='message'"> <xsl:when test="@type='message'">
if ( <xsl:value-of select="@name"/> != null){
result.Append( <xsl:value-of select="concat( @name, '.LocalText')"/>); result.Append( <xsl:value-of select="concat( @name, '.LocalText')"/>);
}
</xsl:when> </xsl:when>
<xsl:when test="@type='entity'"> <xsl:when test="@type='entity'">
<!-- TODO: this is dangerous and could potentially give rise to <!-- TODO: this is dangerous and could potentially give rise to
infinite loops; find a way of stopping it running away! --> infinite loops; find a way of stopping it running away! -->
if ( <xsl:value-of select="@name"/> != null){
result.Append( <xsl:value-of select="concat( @name, '.UserIdentifier')"/>); result.Append( <xsl:value-of select="concat( @name, '.UserIdentifier')"/>);
}
</xsl:when> </xsl:when>
<xsl:when test="@type='date'"> <xsl:when test="@type='date'">
<!-- if what we've got is just a date, we only want to see the date part of it --> <!-- if what we've got is just a date, we only want to see the date part of it -->
if ( <xsl:value-of select="@name"/> != null){
result.Append(<xsl:value-of select="@name"/>.ToString( "d")); result.Append(<xsl:value-of select="@name"/>.ToString( "d"));
}
</xsl:when> </xsl:when>
<xsl:when test="@type='time'"> <xsl:when test="@type='time'">
<!-- if what we've got is just a time, we only want to see the time part of it --> <!-- if what we've got is just a time, we only want to see the time part of it -->
if ( <xsl:value-of select="@name"/> != null){
result.Append(<xsl:value-of select="@name"/>.ToString( "t")); result.Append(<xsl:value-of select="@name"/>.ToString( "t"));
}
</xsl:when>
<xsl:when test="@required = 'true' and (@type = 'integer' or @type = 'real' or @type = 'boolean' or @type = 'money')">
<!-- can't be null because we will have generated a non-nullable type -->
result.Append(<xsl:value-of select="@name"/>.ToString();
</xsl:when> </xsl:when>
<xsl:otherwise> <xsl:otherwise>
if ( <xsl:value-of select="@name"/> != null){
result.Append(<xsl:value-of select="@name"/>); result.Append(<xsl:value-of select="@name"/>);
}
</xsl:otherwise> </xsl:otherwise>
</xsl:choose> </xsl:choose>
<xsl:choose> <xsl:choose>
@ -192,7 +205,6 @@
result.Append( ","); result.Append( ",");
</xsl:otherwise> </xsl:otherwise>
</xsl:choose> </xsl:choose>
}
</xsl:for-each> </xsl:for-each>
</xsl:when> </xsl:when>
<xsl:otherwise> <xsl:otherwise>
@ -344,18 +356,30 @@
} }
set { set {
<xsl:if test="@required='true'"> <xsl:if test="@required='true'">
if ( value == null) <!-- If we could generate a non-nullable type we have done so; otherwise,
{ must catch null -->
throw new DataRequiredException( <xsl:choose> <xsl:choose>
<xsl:when test="ifmissing[@locale=$locale]"> <xsl:when test="@type='integer'"/>
<xsl:apply-templates select="ifmissing"/> <xsl:when test="@type='real'"/>
<xsl:when test="@type='money'">
<!-- not quite certain of that - check! -->
</xsl:when> </xsl:when>
<xsl:when test="@type='boolean'"/>
<xsl:otherwise> <xsl:otherwise>
"The value for <xsl:value-of select="@name"/> may not be set to null" if ( value == null)
{
throw new DataRequiredException( <xsl:choose>
<xsl:when test="ifmissing[@locale=$locale]">
<xsl:apply-templates select="ifmissing"/>
</xsl:when>
<xsl:otherwise>
"The value for <xsl:value-of select="@name"/> may not be set to null"
</xsl:otherwise>
</xsl:choose>
);
}
</xsl:otherwise> </xsl:otherwise>
</xsl:choose> </xsl:choose>
);
}
</xsl:if> </xsl:if>
<xsl:if test="@type='defined'"> <xsl:if test="@type='defined'">
<xsl:variable name="definition"> <xsl:variable name="definition">

View file

@ -12,7 +12,7 @@
Convert ADL to MS-SQL Convert ADL to MS-SQL
$Author: sb $ $Author: sb $
$Revision: 1.8 $ $Revision: 1.9 $
--> -->
<xsl:output indent="no" encoding="UTF-8" method="text"/> <xsl:output indent="no" encoding="UTF-8" method="text"/>
@ -103,7 +103,7 @@
-- <xsl:value-of select="$product-version"/> -- <xsl:value-of select="$product-version"/>
-- --
-- Database for application <xsl:value-of select="@name"/> version <xsl:value-of select="@version"/> -- Database for application <xsl:value-of select="@name"/> version <xsl:value-of select="@version"/>
-- Generated for MS-SQL 2000+ using adl2mssql.xslt <xsl:value-of select="substring('$Revision: 1.8 $', 12)"/> -- Generated for MS-SQL 2000+ using adl2mssql.xslt <xsl:value-of select="substring('$Revision: 1.9 $', 12)"/>
-- THIS FILE IS AUTOMATICALLY GENERATED: DO NOT EDIT IT. -- THIS FILE IS AUTOMATICALLY GENERATED: DO NOT EDIT IT.
-- --
-- <xsl:value-of select="@revision"/> -- <xsl:value-of select="@revision"/>
@ -636,7 +636,12 @@
</xsl:variable> </xsl:variable>
<xsl:choose> <xsl:choose>
<xsl:when test="contains( $sqlkeywords, concat(' ', translate( $unescaped, $lcase, $ucase),' '))"> <xsl:when test="contains( $sqlkeywords, concat(' ', translate( $unescaped, $lcase, $ucase),' '))">
<xsl:value-of select="concat( '[', $unescaped, ']')"/> <!--
names which are keywords need to be escaped /either/ with square
brackets /or/ with quotes, but currently we're using quotes for all names
so don't need square brackets.
xsl:value-of select="concat( '[', $unescaped, ']')"/ -->
<xsl:value-of select="$unescaped"/>
</xsl:when> </xsl:when>
<xsl:otherwise> <xsl:otherwise>
<xsl:value-of select="$unescaped"/> <xsl:value-of select="$unescaped"/>