Skip to content
Permalink
Browse files

Deep load features and sql dump (#471)

* Deep load features and sql dump

Misc fixes.  Plus Added new deep load features, and the ability to dump the basic sql schema out to files for source control inclusion.  Also added the ability to re-execute the views against the server to refresh their meta data.

* Deep load features and sql dump

Misc fixes. Plus Added new deep load features, and the ability to dump the basic sql schema out to files for source control inclusion. Also added the ability to re-execute the views against the server to refresh their meta data.

* Allow attach debugger

Add commented line for attaching a debugger.
Also fix default decimal and float values.
  • Loading branch information...
jeremeguenther committed Mar 4, 2019
1 parent 631eb49 commit 00b8e4b3f6143cd904dd71fe33b17298b830481e
@@ -0,0 +1,91 @@
<%@ CodeTemplate Src="..\..\TemplateLib\CommonSqlCode.cs" Debug="true" Inherits="MoM.Templates.CommonSqlCode" Language="C#" TargetLanguage="T-SQL"
Description="Generates Alter statements for all Views" ResponseEncoding="UTF-8" NoWarn="0108,0618,1572,1573,1574,0162,2002"%>

<%@ Property Name="CompanyName" Optional="True" Type="System.String" Category="General" Description="The name of your company." %>
<%@ Property Name="CompanyURL" Optional="True" Type="System.String" Category="General" Description="The URL of your company." %>

<%@ Property Name="SourceViews" Type="SchemaExplorer.ViewSchemaCollection" Optional="True" Category="Context" Description="Views that the stored procedures should be based on." %>
<%@ Property Name="SetAnsiNullsOn" Type="System.Boolean" Default="False" Category="Options" Description="If this is set to True, SET ANSI_NULLS will be ON instead of OFF." %>

<%@ Property Name="IsolationLevel" Type="TransactionIsolationLevelEnum" Default="None" Category="Options" Description="Isolation level to use in generated procedures." %>


<%@ Assembly Name="SchemaExplorer" %>
<%@ Assembly Name="System.Design" %>
<%@ Import Namespace="SchemaExplorer" %>
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.Text.RegularExpressions" %>
<%@ Import Namespace="System.Collections" %>

<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type='text/xsl' href="viewssql.xsl"?>
<root xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<database setAnsiNulls="<%=(this.SetAnsiNullsOn == true) ? "ON" : "OFF" %>"><%=(SourceViews[0].Database.Name)%></database>
<views>
<%
// loop through all views
foreach(ViewSchema view in SourceViews)
{
%>
<view owner="<%=view.Owner%>" name="<%=view.Name%>" fullname="<%=view.FullName%>">
<comments><![CDATA[<%=view.Description%>]]></comments>
<body><![CDATA[<%=RemoveCreate(view.ViewText).Trim()%>]]></body>
</view>
<%
} // end of view foreach loop
%>
</views>
</root>
<script runat="template">

public enum TransactionIsolationLevelEnum
{
None,
ReadCommitted,
ReadUncommitted,
RepeatableRead,
Serializable,
Snapshot
}

// Used to determine the style of drop statement to be used (if any)
public enum DropStyleEnum
{
Entity,
All
}

public string GetSetTransactionIsolationLevelStatement()
{
switch (IsolationLevel)
{
case TransactionIsolationLevelEnum.None:
return "";
case TransactionIsolationLevelEnum.ReadCommitted:
return "SET TRANSACTION ISOLATION LEVEL READ COMMITTED";
case TransactionIsolationLevelEnum.ReadUncommitted:
return "SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED";
case TransactionIsolationLevelEnum.RepeatableRead:
return "SET TRANSACTION ISOLATION LEVEL REPEATABLE READ";
case TransactionIsolationLevelEnum.Serializable:
return "SET TRANSACTION ISOLATION LEVEL SERIALIZABLE";
case TransactionIsolationLevelEnum.Snapshot:
return "SET TRANSACTION ISOLATION LEVEL SNAPSHOT";
default:
return "SET TRANSACTION ISOLATION LEVEL READ COMMITTED";
}
}

public string RemoveCreate(string body)
{
if (string.IsNullOrWhiteSpace(body))
return string.Empty;

int start = body.IndexOf("AS", StringComparison.OrdinalIgnoreCase);
if (start == -1)
return body;

return body.Substring(start + 3);
}

</script>
@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:sc="http://serialcoder.net"
extension-element-prefixes="msxsl sc"
xml:space="preserve"
>

<xsl:output method="text"/>

<xsl:template match="/">
USE [<xsl:value-of select="/root/database"/>]
GO
<xsl:apply-templates select="//views/view[not(@skip)]"/>
</xsl:template>

<xsl:template match="view">
SET QUOTED_IDENTIFIER ON
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS <xsl:value-of select="/root/database/@setAnsiNulls"/>
GO

<xsl:value-of select="comment"/>

ALTER VIEW [<xsl:value-of select="@owner"/>].[<xsl:value-of select="@name"/>]
AS

<xsl:value-of select="body" disable-output-escaping="yes"/>

GO

</xsl:template>


<msxsl:script implements-prefix="sc" language="Javascript">
<![CDATA[
function align(ctx,length){
var str = ' ' + ctx;
str = str.substr(str.length - length);
return str;
}
function crlf()
{
return "\r\n";
}
function spaces(nb) {
var str = '';
for(var i=0; i<nb;i++) {
str += ' ';
}
return str;
}
function FillRightSpace(ctx, width)
{
var str = spaces(width);
str = ctx + str;
return str.substr(0,width);
}
function DropCR(ctx)
{
var str = '' + ctx;
str = str.Replace("\r","");
return str;
}
]]>
</msxsl:script>

</xsl:stylesheet>
Oops, something went wrong.

0 comments on commit 00b8e4b

Please sign in to comment.
You can’t perform that action at this time.