Skip to content

Commit

Permalink
Merge pull request #15 from SQLPlayer/ver.2.3
Browse files Browse the repository at this point in the history
Ver.2.3
  • Loading branch information
NowinskiK authored Dec 2, 2020
2 parents dbe79bc + b4012e7 commit f77d34b
Show file tree
Hide file tree
Showing 27 changed files with 732 additions and 11 deletions.
2 changes: 1 addition & 1 deletion App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
</startup>
</configuration>
24 changes: 23 additions & 1 deletion CAMOsoft/CAMOsoft.DbUtils/CAMOsoft.DbUtils.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CAMOsoft.DbUtils</RootNamespace>
<AssemblyName>CAMOsoft.DbUtils</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<StartupObject>
</StartupObject>
Expand Down Expand Up @@ -85,8 +85,12 @@
<Compile Include="DbSession.cs" />
<Compile Include="MsSqlCmd.cs" />
<Compile Include="MsSqlSession.cs" />
<Compile Include="SqlServerTypes\Loader.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.SqlServer.Types, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.SqlServer.Types.14.0.1016.290\lib\net40\Microsoft.SqlServer.Types.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Security" />
Expand All @@ -109,4 +113,22 @@
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Content Include="SqlServerTypes\readme.htm" />
<Content Include="SqlServerTypes\x64\msvcr120.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="SqlServerTypes\x64\SqlServerSpatial140.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="SqlServerTypes\x86\msvcr120.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="SqlServerTypes\x86\SqlServerSpatial140.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
</Project>
45 changes: 45 additions & 0 deletions CAMOsoft/CAMOsoft.DbUtils/SqlServerTypes/Loader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.IO;
using System.Runtime.InteropServices;

namespace SqlServerTypes
{
/// <summary>
/// Utility methods related to CLR Types for SQL Server
/// </summary>
public class Utilities
{
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr LoadLibrary(string libname);

/// <summary>
/// Loads the required native assemblies for the current architecture (x86 or x64)
/// </summary>
/// <param name="rootApplicationPath">
/// Root path of the current application. Use Server.MapPath(".") for ASP.NET applications
/// and AppDomain.CurrentDomain.BaseDirectory for desktop applications.
/// </param>
public static void LoadNativeAssemblies(string rootApplicationPath)
{
var nativeBinaryPath = IntPtr.Size > 4
? Path.Combine(rootApplicationPath, @"SqlServerTypes\x64\")
: Path.Combine(rootApplicationPath, @"SqlServerTypes\x86\");

LoadNativeAssembly(nativeBinaryPath, "msvcr120.dll");
LoadNativeAssembly(nativeBinaryPath, "SqlServerSpatial140.dll");
}

private static void LoadNativeAssembly(string nativeBinaryPath, string assemblyName)
{
var path = Path.Combine(nativeBinaryPath, assemblyName);
var ptr = LoadLibrary(path);
if (ptr == IntPtr.Zero)
{
throw new Exception(string.Format(
"Error loading {0} (ErrorCode: {1})",
assemblyName,
Marshal.GetLastWin32Error()));
}
}
}
}
61 changes: 61 additions & 0 deletions CAMOsoft/CAMOsoft.DbUtils/SqlServerTypes/readme.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<html lang="en-US">
<head>
<meta charset="utf-8" />
<title>Microsoft.SqlServer.Types</title>
<style>
body {
background: #fff;
color: #505050;
margin: 20px;
}

#main {
background: #efefef;
padding: 5px 30px;
}
</style>
</head>
<body>
<div id="main">
<h1>Action required to load native assemblies</h1>
<p>
To deploy an application that uses spatial data types to a machine that does not have 'System CLR Types for SQL Server' installed you also need to deploy the native assembly SqlServerSpatial140.dll. Both x86 (32 bit) and x64 (64 bit) versions of this assembly have been added to your project under the SqlServerTypes\x86 and SqlServerTypes\x64 subdirectories. The native assembly msvcr120.dll is also included in case the C++ runtime is not installed.
</p>
<p>
You need to add code to load the correct one of these assemblies at runtime (depending on the current architecture).
</p>
<h2>ASP.NET Web Sites</h2>
<p>
For ASP.NET Web Sites, add the following block of code to the code behind file of the Web Form where you have added Report Viewer Control:
<pre>
Default.aspx.cs:

public partial class _Default : System.Web.UI.Page
{
static bool _isSqlTypesLoaded = false;

public _Default()
{
if (!_isSqlTypesLoaded)
{
SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~"));
_isSqlTypesLoaded = true;
}

}
}
</pre>
</p>
<h2>ASP.NET Web Applications</h2>
<p>
For ASP.NET Web Applications, add the following line of code to the Application_Start method in Global.asax.cs:
<pre> SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~/bin"));</pre>
</p>
<h2>Desktop Applications</h2>
<p>
For desktop applications, add the following line of code to run before any spatial operations are performed:
<pre> SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);</pre>
</p>
</div>
</body>
</html>
4 changes: 4 additions & 0 deletions CAMOsoft/CAMOsoft.DbUtils/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.SqlServer.Types" version="14.0.1016.290" targetFramework="net461" />
</packages>
5 changes: 5 additions & 0 deletions ChangesLog.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
SQLPlayer Data Script Writer - Changes Log
==========================================

ver.2.3 @ 02/12/2020
- Support for Temporal tables (#10)
- Support for Time data type (#14)
- Fixed: Showing the wrong number of rows in a table (#12)

ver.2.2 @ 12/06/2020
- Support for Binary and Varbinary

Expand Down
20 changes: 19 additions & 1 deletion DataScriptWriter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>DataScriptWriter</RootNamespace>
<AssemblyName>DataScriptWriter</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
Expand Down Expand Up @@ -50,6 +50,9 @@
<Reference Include="DevExpress.XtraGrid.v13.2, Version=13.2.15.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />
<Reference Include="DevExpress.XtraLayout.v13.2, Version=13.2.15.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<Reference Include="DevExpress.XtraPrinting.v13.2, Version=13.2.15.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<Reference Include="Microsoft.SqlServer.Types, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.SqlServer.Types.14.0.1016.290\lib\net40\Microsoft.SqlServer.Types.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand Down Expand Up @@ -85,6 +88,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ScriptWriter.cs" />
<Compile Include="ScriptObject.cs" />
<Compile Include="SqlServerTypes\Loader.cs" />
<EmbeddedResource Include="ConnectDbForm.resx">
<DependentUpon>ConnectDbForm.cs</DependentUpon>
</EmbeddedResource>
Expand All @@ -105,6 +109,7 @@
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
Expand All @@ -126,6 +131,19 @@
<ItemGroup>
<Content Include="Resources\if_Archive_box_data_file_storage_1886362.ico" />
<Content Include="Resources\data_backup.ico" />
<Content Include="SqlServerTypes\readme.htm" />
<Content Include="SqlServerTypes\x64\msvcr120.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="SqlServerTypes\x64\SqlServerSpatial140.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="SqlServerTypes\x86\msvcr120.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="SqlServerTypes\x86\SqlServerSpatial140.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Include="Resources\if_script_lightning_36406.png" />
<None Include="Resources\if_exit_6035.png" />
<None Include="Resources\if_connect_established_1721.png" />
Expand Down
44 changes: 44 additions & 0 deletions OUTPUT/Application.TransactionTypes.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
CREATE PROCEDURE [dbo].[Populate_Application_TransactionTypes]
AS
BEGIN
/*
Table's data: [Application].[TransactionTypes]
Data Source: [DEV19].[WideWorldImporters]
Created on: 02/12/2020 00:13:12
Scripted by: DEV19\Administrator
Generated by: Data Script Writer - ver. 2.3.0.0
GitHub repo URL: https://github.com/SQLPlayer/DataScriptWriter/
*/
PRINT 'Populating data into [Application].[TransactionTypes]';

IF NOT EXISTS (SELECT TOP (1) * FROM [Application].[TransactionTypes])
BEGIN

;WITH cte_data
as (SELECT [TransactionTypeID], [TransactionTypeName], [LastEditedBy] FROM
(VALUES
(1, N'Customer Invoice', 1)
, (2, N'Customer Credit Note', 1)
, (3, N'Customer Payment Received', 1)
, (4, N'Customer Refund', 1)
, (5, N'Supplier Invoice', 1)
, (6, N'Supplier Credit Note', 1)
, (7, N'Supplier Payment Issued', 1)
, (8, N'Supplier Refund', 1)
, (9, N'Stock Transfer', 1)
, (10, N'Stock Issue', 1)
, (11, N'Stock Receipt', 1)
, (12, N'Stock Adjustment at Stocktake', 1)
, (13, N'Customer Contra', 9)
) as v ([TransactionTypeID], [TransactionTypeName], [LastEditedBy])
)
INSERT INTO [Application].[TransactionTypes]
([TransactionTypeID], [TransactionTypeName], [LastEditedBy])
SELECT [TransactionTypeID], [TransactionTypeName], [LastEditedBy]
FROM cte_data;

END

-- End data of table: [Application].[TransactionTypes] --
END
GO
36 changes: 36 additions & 0 deletions OUTPUT/Person.AddressType_INSERT.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
CREATE PROCEDURE [dbo].[Populate_Person_AddressType]
AS
BEGIN
/*
Table's data: [Person].[AddressType]
Data Source: [DEV19].[AdventureWorks2014]
Created on: 18/10/2019 15:00:40
Scripted by: DEV19\Administrator
Generated by Data Script Writer - ver. 2.0.0.0
*/
PRINT 'Populating data into [Person].[AddressType]';

IF NOT EXISTS (SELECT TOP (1) * FROM [Person].[AddressType])
BEGIN

;WITH cte_data
as (SELECT [AddressTypeID], [Name], [rowguid], [ModifiedDate] FROM
(VALUES
(1, 'Billing', 'b84f78b1-4efe-4a0e-8cb7-70e9f112f886', '20080430 00:00:00.000')
, (2, 'Home', '41bc2ff6-f0fc-475f-8eb9-cec0805aa0f2', '20080430 00:00:00.000')
, (3, 'Main Office', '8eeec28c-07a2-4fb9-ad0a-42d4a0bbc575', '20080430 00:00:00.000')
, (4, 'Primary', '24cb3088-4345-47c4-86c5-17b535133d1e', '20080430 00:00:00.000')
, (5, 'Shipping', 'b29da3f8-19a3-47da-9daa-15c84f4a83a5', '20080430 00:00:00.000')
, (6, 'Archive', 'a67f238a-5ba2-444b-966c-0467ed9c427f', '20080430 00:00:00.000')
) as v ([AddressTypeID], [Name], [rowguid], [ModifiedDate])
)
INSERT INTO [Person].[AddressType]
([AddressTypeID], [Name], [rowguid], [ModifiedDate])
SELECT [AddressTypeID], [Name], [rowguid], [ModifiedDate]
FROM cte_data;

END

-- End data of table: [Person].[AddressType] --
END
GO
48 changes: 48 additions & 0 deletions OUTPUT/Person.AddressType_MERGE.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
CREATE PROCEDURE [dbo].[Populate_Person_AddressType]
AS
BEGIN
/*
Table's data: [Person].[AddressType]
Data Source: [DEV19].[AdventureWorks2014]
Created on: 18/10/2019 14:59:12
Scripted by: DEV19\Administrator
Generated by Data Script Writer - ver. 2.0.0.0
*/
PRINT 'Populating data into [Person].[AddressType]';

IF OBJECT_ID('tempdb.dbo.#Person_AddressType') IS NOT NULL DROP TABLE #Person_AddressType;
SELECT * INTO #Person_AddressType FROM [Person].[AddressType] WHERE 0=1;

INSERT INTO #Person_AddressType
([AddressTypeID], [Name], [rowguid], [ModifiedDate])
SELECT CAST([AddressTypeID] AS int) AS [AddressTypeID], [Name], [rowguid], [ModifiedDate] FROM
(VALUES
(1, 'Billing', 'b84f78b1-4efe-4a0e-8cb7-70e9f112f886', '20080430 00:00:00.000')
, (2, 'Home', '41bc2ff6-f0fc-475f-8eb9-cec0805aa0f2', '20080430 00:00:00.000')
, (3, 'Main Office', '8eeec28c-07a2-4fb9-ad0a-42d4a0bbc575', '20080430 00:00:00.000')
, (4, 'Primary', '24cb3088-4345-47c4-86c5-17b535133d1e', '20080430 00:00:00.000')
, (5, 'Shipping', 'b29da3f8-19a3-47da-9daa-15c84f4a83a5', '20080430 00:00:00.000')
, (6, 'Archive', 'a67f238a-5ba2-444b-966c-0467ed9c427f', '20080430 00:00:00.000')
) as v ([AddressTypeID], [Name], [rowguid], [ModifiedDate]);



WITH cte_data as (SELECT CAST([AddressTypeID] AS int) AS [AddressTypeID], [Name], [rowguid], [ModifiedDate] FROM [#Person_AddressType])
MERGE [Person].[AddressType] as t
USING cte_data as s
ON t.[AddressTypeID] = s.[AddressTypeID]
WHEN NOT MATCHED BY target THEN
INSERT ([AddressTypeID], [Name], [rowguid], [ModifiedDate])
VALUES (s.[AddressTypeID], s.[Name], s.[rowguid], s.[ModifiedDate])
WHEN MATCHED THEN
UPDATE SET
[Name] = s.[Name], [rowguid] = s.[rowguid], [ModifiedDate] = s.[ModifiedDate]
WHEN NOT MATCHED BY source THEN
DELETE
;

DROP TABLE #Person_AddressType;

-- End data of table: [Person].[AddressType] --
END
GO
Loading

0 comments on commit f77d34b

Please sign in to comment.