Skip to content

Commit

Permalink
1.0.0-beta-sun-build69 Version:
Browse files Browse the repository at this point in the history
      Fix issue 25: #25

      Usage:

      var database = await SqlServerDatabaseFactory.ImportAsync("Your connection string!");

      Wiki: https://github.com/hherzl/CatFactory.SqlServer/wiki
  • Loading branch information
hherzl committed Apr 19, 2023
1 parent 6ddaa81 commit 7eba582
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 51 deletions.
33 changes: 14 additions & 19 deletions CatFactory.SqlServer/CatFactory.SqlServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,35 @@

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Version>1.0.0-beta-sun-build68</Version>
<Version>1.0.0-beta-sun-build69</Version>
<Authors>H. Herzl</Authors>
<Company>Herzl Corp.</Company>
<Description>CatFactory package for SQL Server</Description>
<RepositoryUrl>https://github.com/hherzl/CatFactory.SqlServer</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>SQL Server Scaffolding Stored Procedures</PackageTags>
<PackageReleaseNotes>
1.0.0-beta-sun-build68 Version:
1.0.0-beta-sun-build69 Version:

Upgrade for .NET 6
Fix issue 20: https://github.com/hherzl/CatFactory.SqlServer/issues/20
Fix issue 21: https://github.com/hherzl/CatFactory.SqlServer/issues/21
Fix issue 22: https://github.com/hherzl/CatFactory.SqlServer/issues/22
Fix issue 23: https://github.com/hherzl/CatFactory.SqlServer/issues/23
Fix issue 24: https://github.com/hherzl/CatFactory.SqlServer/issues/24
Fix issue 25: https://github.com/hherzl/CatFactory.SqlServer/issues/25

Usage:

var database = await SqlServerDatabaseFactory.ImportAsync("Your connection string!");

Wiki: https://github.com/hherzl/CatFactory.SqlServer/wiki
</PackageReleaseNotes>
<PackageProjectUrl>https://github.com/hherzl/CatFactory.SqlServer</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/hherzl/CatFactory.SqlServer/blob/master/LICENSE</PackageLicenseUrl>
</PropertyGroup>
<PackageProjectUrl>https://github.com/hherzl/CatFactory.SqlServer</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/hherzl/CatFactory.SqlServer/blob/master/LICENSE</PackageLicenseUrl>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile>bin\Debug\net6.0\CatFactory.SqlServer.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile>bin\Debug\net6.0\CatFactory.SqlServer.xml</DocumentationFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CatFactory" Version="1.0.0-beta-sun-build32" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.5" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CatFactory" Version="1.0.0-beta-sun-build32" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.5" />
</ItemGroup>

</Project>
</Project>
64 changes: 32 additions & 32 deletions CatFactory.SqlServer/CodeFactory/SqlStoredProcedureCodeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ public override void Translating()
/// <returns></returns>
protected IEnumerable<ILine> GetDropProcedureLines(string procedureName)
{
yield return new CodeLine("if object_id('{0}', 'P') is not null", procedureName);
yield return new CodeLine("IF OBJECT_ID('{0}', 'P') IS NOT NULL", procedureName);

yield return new CodeLine("{0}drop procedure {1}", Indent(1), procedureName);
yield return new CodeLine("{0}DROP PROCEDURE {1}", Indent(1), procedureName);

yield return new CodeLine("go");
yield return new CodeLine("GO");
}

/// <summary>
Expand All @@ -115,7 +115,7 @@ protected virtual IEnumerable<ILine> GetLinesForGetAllStoredProcedure()

Lines.Add(new EmptyLine());

yield return new CodeLine("create procedure {0}", procedureName);
yield return new CodeLine("CREATE PROCEDURE {0}", procedureName);

var constraints = Table.ForeignKeys.Where(constraint => constraint.Key != null && constraint.Key.Count == 1).ToList();

Expand All @@ -125,12 +125,12 @@ protected virtual IEnumerable<ILine> GetLinesForGetAllStoredProcedure()
var columns = Table.GetColumnsFromConstraint(foreignKey).ToList();

if (columns.Count == 1)
yield return new CodeLine("{0}{1} {2} = null{3}", Indent(1), Database.GetParameterName(columns.First()), columns.First().Type, i < constraints.Count - 1 ? "," : string.Empty);
yield return new CodeLine("{0}{1} {2} = NULL{3}", Indent(1), Database.GetParameterName(columns.First()), columns.First().Type, i < constraints.Count - 1 ? "," : string.Empty);
}

yield return new CodeLine("as");
yield return new CodeLine("AS");

yield return new CodeLine("{0}select", Indent(1));
yield return new CodeLine("{0}SELECT", Indent(1));

for (var i = 0; i < Table.Columns.Count; i++)
{
Expand All @@ -139,21 +139,21 @@ protected virtual IEnumerable<ILine> GetLinesForGetAllStoredProcedure()
yield return new CodeLine("{0}{1}{2}", Indent(2), Database.GetObjectName(column), i < Table.Columns.Count - 1 ? "," : string.Empty);
}

yield return new CodeLine("{0}from", Indent(1));
yield return new CodeLine("{0}FROM", Indent(1));

yield return new CodeLine("{0}{1}", Indent(2), Database.GetObjectName(Table));

if (constraints.Count > 0)
{
yield return new CodeLine("{0}where", Indent(1));
yield return new CodeLine("{0}WHERE", Indent(1));

for (var i = 0; i < constraints.Count; i++)
{
var foreignKey = constraints[i];
var columns = Table.GetColumnsFromConstraint(foreignKey).ToList();

if (columns.Count == 1)
yield return new CodeLine("{0}({1} is null or {2} = {1}){3}", Indent(2), Database.GetParameterName(columns.First()), Database.NamingConvention.GetObjectName(columns.First().Name), i < constraints.Count - 1 ? " and" : string.Empty);
yield return new CodeLine("{0}({1} IS NULL OR {2} = {1}){3}", Indent(2), Database.GetParameterName(columns.First()), Database.NamingConvention.GetObjectName(columns.First().Name), i < constraints.Count - 1 ? " AND" : string.Empty);
}
}

Expand All @@ -172,7 +172,7 @@ protected virtual IEnumerable<ILine> GetLinesForGetStoredProcedure()

Lines.Add(new EmptyLine());

yield return new CodeLine("create procedure {0}", procedureName);
yield return new CodeLine("CREATE PROCEDURE {0}", procedureName);

if (Table.PrimaryKey != null)
{
Expand All @@ -186,9 +186,9 @@ protected virtual IEnumerable<ILine> GetLinesForGetStoredProcedure()
}
}

yield return new CodeLine("as");
yield return new CodeLine("AS");

yield return new CodeLine("{0}select", Indent(1));
yield return new CodeLine("{0}SELECT", Indent(1));

for (var i = 0; i < Table.Columns.Count; i++)
{
Expand All @@ -197,11 +197,11 @@ protected virtual IEnumerable<ILine> GetLinesForGetStoredProcedure()
yield return new CodeLine("{0}{1}{2}", Indent(2), Database.GetObjectName(column), i < Table.Columns.Count - 1 ? "," : string.Empty);
}

yield return new CodeLine("{0}from", Indent(1));
yield return new CodeLine("{0}FROM", Indent(1));

yield return new CodeLine("{0}{1}", Indent(2), Database.GetObjectName(Table));

yield return new CodeLine("{0}where", Indent(1));
yield return new CodeLine("{0}WHERE", Indent(1));

if (Table.PrimaryKey != null)
{
Expand All @@ -213,7 +213,7 @@ protected virtual IEnumerable<ILine> GetLinesForGetStoredProcedure()
}
}

yield return new CodeLine("go");
yield return new CodeLine("GO");
}

/// <summary>
Expand All @@ -228,18 +228,18 @@ protected virtual IEnumerable<ILine> GetLinesForInsertIntoStoredProcedure()

Lines.Add(new EmptyLine());

yield return new CodeLine("create procedure {0}", procedureName);
yield return new CodeLine("CREATE PROCEDURE {0}", procedureName);

for (var i = 0; i < Table.Columns.Count; i++)
{
var column = Table.Columns[i];

yield return new CodeLine("{0}{1} {2}{3}{4}", Indent(1), Database.GetParameterName(column), GetType(column), Table.Identity != null && Table.Identity.Name == column.Name ? " output" : string.Empty, i < Table.Columns.Count - 1 ? "," : string.Empty);
yield return new CodeLine("{0}{1} {2}{3}{4}", Indent(1), Database.GetParameterName(column), GetType(column), Table.Identity != null && Table.Identity.Name == column.Name ? " OUTPUT" : string.Empty, i < Table.Columns.Count - 1 ? "," : string.Empty);
}

yield return new CodeLine("as");
yield return new CodeLine("AS");

yield return new CodeLine("{0}insert into {1}", Indent(1), Database.GetObjectName(Table));
yield return new CodeLine("{0}INSERT INTO {1}", Indent(1), Database.GetObjectName(Table));

yield return new CodeLine("{0}(", Indent(1));

Expand All @@ -254,7 +254,7 @@ protected virtual IEnumerable<ILine> GetLinesForInsertIntoStoredProcedure()

yield return new CodeLine("{0})", Indent(1));

yield return new CodeLine("{0}values", Indent(1));
yield return new CodeLine("{0}VALUES", Indent(1));

yield return new CodeLine("{0}(", Indent(1));

Expand All @@ -271,7 +271,7 @@ protected virtual IEnumerable<ILine> GetLinesForInsertIntoStoredProcedure()
{
yield return new EmptyLine();

yield return new CodeLine("{0}select {1} = scope_identity()", Indent(1), Database.GetParameterName(Table.Identity.Name));
yield return new CodeLine("{0}SELECT {1} = SCOPE_IDENTITY()", Indent(1), Database.GetParameterName(Table.Identity.Name));
}

yield return new CodeLine("go");
Expand All @@ -289,7 +289,7 @@ protected virtual IEnumerable<ILine> GetLinesForUpdateStoredProcedure()

Lines.Add(new EmptyLine());

yield return new CodeLine("create procedure {0}", procedureName);
yield return new CodeLine("CREATE PROCEDURE {0}", procedureName);

for (var i = 0; i < Table.Columns.Count; i++)
{
Expand All @@ -298,13 +298,13 @@ protected virtual IEnumerable<ILine> GetLinesForUpdateStoredProcedure()
yield return new CodeLine("{0}{1} {2}{3}", Indent(1), Database.GetParameterName(column), GetType(column), i < Table.Columns.Count - 1 ? "," : string.Empty);
}

yield return new CodeLine("as");
yield return new CodeLine("AS");

yield return new CodeLine("{0}update", Indent(1));
yield return new CodeLine("{0}UPDATE", Indent(1));

yield return new CodeLine("{0}{1}", Indent(2), Database.GetObjectName(Table));

yield return new CodeLine("{0}set", Indent(1));
yield return new CodeLine("{0}SET", Indent(1));

var columns = Table.GetColumnsFromConstraint(Table.PrimaryKey).ToList();

Expand All @@ -315,7 +315,7 @@ protected virtual IEnumerable<ILine> GetLinesForUpdateStoredProcedure()
yield return new CodeLine("{0}{1} = {2}{3}", Indent(2), Database.GetObjectName(column), Database.GetParameterName(column), i < columns.Count - 1 ? "," : string.Empty);
}

yield return new CodeLine("{0}where", Indent(1));
yield return new CodeLine("{0}WHERE", Indent(1));

if (Table.PrimaryKey != null)
{
Expand All @@ -327,7 +327,7 @@ protected virtual IEnumerable<ILine> GetLinesForUpdateStoredProcedure()
}
}

yield return new CodeLine("go");
yield return new CodeLine("GO");
}

/// <summary>
Expand All @@ -342,7 +342,7 @@ protected virtual IEnumerable<ILine> GetLinesForDeleteStoredProcedure()

Lines.Add(new EmptyLine());

yield return new CodeLine("create procedure {0}", procedureName);
yield return new CodeLine("CREATE PROCEDURE {0}", procedureName);

if (Table.PrimaryKey != null)
{
Expand All @@ -356,9 +356,9 @@ protected virtual IEnumerable<ILine> GetLinesForDeleteStoredProcedure()
}
}

yield return new CodeLine("as");
yield return new CodeLine("AS");

yield return new CodeLine("{0}delete from", Indent(1));
yield return new CodeLine("{0}DELETE FROM", Indent(1));

yield return new CodeLine("{0}{1}", Indent(2), Database.GetObjectName(Table));

Expand All @@ -374,7 +374,7 @@ protected virtual IEnumerable<ILine> GetLinesForDeleteStoredProcedure()
}
}

yield return new CodeLine("go");
yield return new CodeLine("GO");
}
}
}

0 comments on commit 7eba582

Please sign in to comment.