Skip to content

Commit f77d34b

Browse files
authored
Merge pull request #15 from SQLPlayer/ver.2.3
Ver.2.3
2 parents dbe79bc + b4012e7 commit f77d34b

27 files changed

+732
-11
lines changed

App.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
33
<startup>
4-
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
55
</startup>
66
</configuration>

CAMOsoft/CAMOsoft.DbUtils/CAMOsoft.DbUtils.csproj

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<AppDesignerFolder>Properties</AppDesignerFolder>
1111
<RootNamespace>CAMOsoft.DbUtils</RootNamespace>
1212
<AssemblyName>CAMOsoft.DbUtils</AssemblyName>
13-
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
13+
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
1414
<FileAlignment>512</FileAlignment>
1515
<StartupObject>
1616
</StartupObject>
@@ -85,8 +85,12 @@
8585
<Compile Include="DbSession.cs" />
8686
<Compile Include="MsSqlCmd.cs" />
8787
<Compile Include="MsSqlSession.cs" />
88+
<Compile Include="SqlServerTypes\Loader.cs" />
8889
</ItemGroup>
8990
<ItemGroup>
91+
<Reference Include="Microsoft.SqlServer.Types, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
92+
<HintPath>..\..\packages\Microsoft.SqlServer.Types.14.0.1016.290\lib\net40\Microsoft.SqlServer.Types.dll</HintPath>
93+
</Reference>
9094
<Reference Include="System" />
9195
<Reference Include="System.Data" />
9296
<Reference Include="System.Security" />
@@ -109,4 +113,22 @@
109113
<Install>true</Install>
110114
</BootstrapperPackage>
111115
</ItemGroup>
116+
<ItemGroup>
117+
<Content Include="SqlServerTypes\readme.htm" />
118+
<Content Include="SqlServerTypes\x64\msvcr120.dll">
119+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
120+
</Content>
121+
<Content Include="SqlServerTypes\x64\SqlServerSpatial140.dll">
122+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
123+
</Content>
124+
<Content Include="SqlServerTypes\x86\msvcr120.dll">
125+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
126+
</Content>
127+
<Content Include="SqlServerTypes\x86\SqlServerSpatial140.dll">
128+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
129+
</Content>
130+
</ItemGroup>
131+
<ItemGroup>
132+
<None Include="packages.config" />
133+
</ItemGroup>
112134
</Project>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System;
2+
using System.IO;
3+
using System.Runtime.InteropServices;
4+
5+
namespace SqlServerTypes
6+
{
7+
/// <summary>
8+
/// Utility methods related to CLR Types for SQL Server
9+
/// </summary>
10+
public class Utilities
11+
{
12+
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
13+
private static extern IntPtr LoadLibrary(string libname);
14+
15+
/// <summary>
16+
/// Loads the required native assemblies for the current architecture (x86 or x64)
17+
/// </summary>
18+
/// <param name="rootApplicationPath">
19+
/// Root path of the current application. Use Server.MapPath(".") for ASP.NET applications
20+
/// and AppDomain.CurrentDomain.BaseDirectory for desktop applications.
21+
/// </param>
22+
public static void LoadNativeAssemblies(string rootApplicationPath)
23+
{
24+
var nativeBinaryPath = IntPtr.Size > 4
25+
? Path.Combine(rootApplicationPath, @"SqlServerTypes\x64\")
26+
: Path.Combine(rootApplicationPath, @"SqlServerTypes\x86\");
27+
28+
LoadNativeAssembly(nativeBinaryPath, "msvcr120.dll");
29+
LoadNativeAssembly(nativeBinaryPath, "SqlServerSpatial140.dll");
30+
}
31+
32+
private static void LoadNativeAssembly(string nativeBinaryPath, string assemblyName)
33+
{
34+
var path = Path.Combine(nativeBinaryPath, assemblyName);
35+
var ptr = LoadLibrary(path);
36+
if (ptr == IntPtr.Zero)
37+
{
38+
throw new Exception(string.Format(
39+
"Error loading {0} (ErrorCode: {1})",
40+
assemblyName,
41+
Marshal.GetLastWin32Error()));
42+
}
43+
}
44+
}
45+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<html lang="en-US">
2+
<head>
3+
<meta charset="utf-8" />
4+
<title>Microsoft.SqlServer.Types</title>
5+
<style>
6+
body {
7+
background: #fff;
8+
color: #505050;
9+
margin: 20px;
10+
}
11+
12+
#main {
13+
background: #efefef;
14+
padding: 5px 30px;
15+
}
16+
</style>
17+
</head>
18+
<body>
19+
<div id="main">
20+
<h1>Action required to load native assemblies</h1>
21+
<p>
22+
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.
23+
</p>
24+
<p>
25+
You need to add code to load the correct one of these assemblies at runtime (depending on the current architecture).
26+
</p>
27+
<h2>ASP.NET Web Sites</h2>
28+
<p>
29+
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:
30+
<pre>
31+
Default.aspx.cs:
32+
33+
public partial class _Default : System.Web.UI.Page
34+
{
35+
static bool _isSqlTypesLoaded = false;
36+
37+
public _Default()
38+
{
39+
if (!_isSqlTypesLoaded)
40+
{
41+
SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~"));
42+
_isSqlTypesLoaded = true;
43+
}
44+
45+
}
46+
}
47+
</pre>
48+
</p>
49+
<h2>ASP.NET Web Applications</h2>
50+
<p>
51+
For ASP.NET Web Applications, add the following line of code to the Application_Start method in Global.asax.cs:
52+
<pre> SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~/bin"));</pre>
53+
</p>
54+
<h2>Desktop Applications</h2>
55+
<p>
56+
For desktop applications, add the following line of code to run before any spatial operations are performed:
57+
<pre> SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);</pre>
58+
</p>
59+
</div>
60+
</body>
61+
</html>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Microsoft.SqlServer.Types" version="14.0.1016.290" targetFramework="net461" />
4+
</packages>

ChangesLog.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
SQLPlayer Data Script Writer - Changes Log
22
==========================================
33

4+
ver.2.3 @ 02/12/2020
5+
- Support for Temporal tables (#10)
6+
- Support for Time data type (#14)
7+
- Fixed: Showing the wrong number of rows in a table (#12)
8+
49
ver.2.2 @ 12/06/2020
510
- Support for Binary and Varbinary
611

DataScriptWriter.csproj

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<AppDesignerFolder>Properties</AppDesignerFolder>
1010
<RootNamespace>DataScriptWriter</RootNamespace>
1111
<AssemblyName>DataScriptWriter</AssemblyName>
12-
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
12+
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
1414
<SccProjectName>SAK</SccProjectName>
1515
<SccLocalPath>SAK</SccLocalPath>
@@ -50,6 +50,9 @@
5050
<Reference Include="DevExpress.XtraGrid.v13.2, Version=13.2.15.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />
5151
<Reference Include="DevExpress.XtraLayout.v13.2, Version=13.2.15.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
5252
<Reference Include="DevExpress.XtraPrinting.v13.2, Version=13.2.15.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
53+
<Reference Include="Microsoft.SqlServer.Types, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
54+
<HintPath>packages\Microsoft.SqlServer.Types.14.0.1016.290\lib\net40\Microsoft.SqlServer.Types.dll</HintPath>
55+
</Reference>
5356
<Reference Include="System" />
5457
<Reference Include="System.Core" />
5558
<Reference Include="System.Xml.Linq" />
@@ -85,6 +88,7 @@
8588
<Compile Include="Properties\AssemblyInfo.cs" />
8689
<Compile Include="ScriptWriter.cs" />
8790
<Compile Include="ScriptObject.cs" />
91+
<Compile Include="SqlServerTypes\Loader.cs" />
8892
<EmbeddedResource Include="ConnectDbForm.resx">
8993
<DependentUpon>ConnectDbForm.cs</DependentUpon>
9094
</EmbeddedResource>
@@ -105,6 +109,7 @@
105109
<DependentUpon>Resources.resx</DependentUpon>
106110
<DesignTime>True</DesignTime>
107111
</Compile>
112+
<None Include="packages.config" />
108113
<None Include="Properties\Settings.settings">
109114
<Generator>SettingsSingleFileGenerator</Generator>
110115
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
@@ -126,6 +131,19 @@
126131
<ItemGroup>
127132
<Content Include="Resources\if_Archive_box_data_file_storage_1886362.ico" />
128133
<Content Include="Resources\data_backup.ico" />
134+
<Content Include="SqlServerTypes\readme.htm" />
135+
<Content Include="SqlServerTypes\x64\msvcr120.dll">
136+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
137+
</Content>
138+
<Content Include="SqlServerTypes\x64\SqlServerSpatial140.dll">
139+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
140+
</Content>
141+
<Content Include="SqlServerTypes\x86\msvcr120.dll">
142+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
143+
</Content>
144+
<Content Include="SqlServerTypes\x86\SqlServerSpatial140.dll">
145+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
146+
</Content>
129147
<None Include="Resources\if_script_lightning_36406.png" />
130148
<None Include="Resources\if_exit_6035.png" />
131149
<None Include="Resources\if_connect_established_1721.png" />
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
CREATE PROCEDURE [dbo].[Populate_Application_TransactionTypes]
2+
AS
3+
BEGIN
4+
/*
5+
Table's data: [Application].[TransactionTypes]
6+
Data Source: [DEV19].[WideWorldImporters]
7+
Created on: 02/12/2020 00:13:12
8+
Scripted by: DEV19\Administrator
9+
Generated by: Data Script Writer - ver. 2.3.0.0
10+
GitHub repo URL: https://github.com/SQLPlayer/DataScriptWriter/
11+
*/
12+
PRINT 'Populating data into [Application].[TransactionTypes]';
13+
14+
IF NOT EXISTS (SELECT TOP (1) * FROM [Application].[TransactionTypes])
15+
BEGIN
16+
17+
;WITH cte_data
18+
as (SELECT [TransactionTypeID], [TransactionTypeName], [LastEditedBy] FROM
19+
(VALUES
20+
(1, N'Customer Invoice', 1)
21+
, (2, N'Customer Credit Note', 1)
22+
, (3, N'Customer Payment Received', 1)
23+
, (4, N'Customer Refund', 1)
24+
, (5, N'Supplier Invoice', 1)
25+
, (6, N'Supplier Credit Note', 1)
26+
, (7, N'Supplier Payment Issued', 1)
27+
, (8, N'Supplier Refund', 1)
28+
, (9, N'Stock Transfer', 1)
29+
, (10, N'Stock Issue', 1)
30+
, (11, N'Stock Receipt', 1)
31+
, (12, N'Stock Adjustment at Stocktake', 1)
32+
, (13, N'Customer Contra', 9)
33+
) as v ([TransactionTypeID], [TransactionTypeName], [LastEditedBy])
34+
)
35+
INSERT INTO [Application].[TransactionTypes]
36+
([TransactionTypeID], [TransactionTypeName], [LastEditedBy])
37+
SELECT [TransactionTypeID], [TransactionTypeName], [LastEditedBy]
38+
FROM cte_data;
39+
40+
END
41+
42+
-- End data of table: [Application].[TransactionTypes] --
43+
END
44+
GO
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
CREATE PROCEDURE [dbo].[Populate_Person_AddressType]
2+
AS
3+
BEGIN
4+
/*
5+
Table's data: [Person].[AddressType]
6+
Data Source: [DEV19].[AdventureWorks2014]
7+
Created on: 18/10/2019 15:00:40
8+
Scripted by: DEV19\Administrator
9+
Generated by Data Script Writer - ver. 2.0.0.0
10+
*/
11+
PRINT 'Populating data into [Person].[AddressType]';
12+
13+
IF NOT EXISTS (SELECT TOP (1) * FROM [Person].[AddressType])
14+
BEGIN
15+
16+
;WITH cte_data
17+
as (SELECT [AddressTypeID], [Name], [rowguid], [ModifiedDate] FROM
18+
(VALUES
19+
(1, 'Billing', 'b84f78b1-4efe-4a0e-8cb7-70e9f112f886', '20080430 00:00:00.000')
20+
, (2, 'Home', '41bc2ff6-f0fc-475f-8eb9-cec0805aa0f2', '20080430 00:00:00.000')
21+
, (3, 'Main Office', '8eeec28c-07a2-4fb9-ad0a-42d4a0bbc575', '20080430 00:00:00.000')
22+
, (4, 'Primary', '24cb3088-4345-47c4-86c5-17b535133d1e', '20080430 00:00:00.000')
23+
, (5, 'Shipping', 'b29da3f8-19a3-47da-9daa-15c84f4a83a5', '20080430 00:00:00.000')
24+
, (6, 'Archive', 'a67f238a-5ba2-444b-966c-0467ed9c427f', '20080430 00:00:00.000')
25+
) as v ([AddressTypeID], [Name], [rowguid], [ModifiedDate])
26+
)
27+
INSERT INTO [Person].[AddressType]
28+
([AddressTypeID], [Name], [rowguid], [ModifiedDate])
29+
SELECT [AddressTypeID], [Name], [rowguid], [ModifiedDate]
30+
FROM cte_data;
31+
32+
END
33+
34+
-- End data of table: [Person].[AddressType] --
35+
END
36+
GO
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
CREATE PROCEDURE [dbo].[Populate_Person_AddressType]
2+
AS
3+
BEGIN
4+
/*
5+
Table's data: [Person].[AddressType]
6+
Data Source: [DEV19].[AdventureWorks2014]
7+
Created on: 18/10/2019 14:59:12
8+
Scripted by: DEV19\Administrator
9+
Generated by Data Script Writer - ver. 2.0.0.0
10+
*/
11+
PRINT 'Populating data into [Person].[AddressType]';
12+
13+
IF OBJECT_ID('tempdb.dbo.#Person_AddressType') IS NOT NULL DROP TABLE #Person_AddressType;
14+
SELECT * INTO #Person_AddressType FROM [Person].[AddressType] WHERE 0=1;
15+
16+
INSERT INTO #Person_AddressType
17+
([AddressTypeID], [Name], [rowguid], [ModifiedDate])
18+
SELECT CAST([AddressTypeID] AS int) AS [AddressTypeID], [Name], [rowguid], [ModifiedDate] FROM
19+
(VALUES
20+
(1, 'Billing', 'b84f78b1-4efe-4a0e-8cb7-70e9f112f886', '20080430 00:00:00.000')
21+
, (2, 'Home', '41bc2ff6-f0fc-475f-8eb9-cec0805aa0f2', '20080430 00:00:00.000')
22+
, (3, 'Main Office', '8eeec28c-07a2-4fb9-ad0a-42d4a0bbc575', '20080430 00:00:00.000')
23+
, (4, 'Primary', '24cb3088-4345-47c4-86c5-17b535133d1e', '20080430 00:00:00.000')
24+
, (5, 'Shipping', 'b29da3f8-19a3-47da-9daa-15c84f4a83a5', '20080430 00:00:00.000')
25+
, (6, 'Archive', 'a67f238a-5ba2-444b-966c-0467ed9c427f', '20080430 00:00:00.000')
26+
) as v ([AddressTypeID], [Name], [rowguid], [ModifiedDate]);
27+
28+
29+
30+
WITH cte_data as (SELECT CAST([AddressTypeID] AS int) AS [AddressTypeID], [Name], [rowguid], [ModifiedDate] FROM [#Person_AddressType])
31+
MERGE [Person].[AddressType] as t
32+
USING cte_data as s
33+
ON t.[AddressTypeID] = s.[AddressTypeID]
34+
WHEN NOT MATCHED BY target THEN
35+
INSERT ([AddressTypeID], [Name], [rowguid], [ModifiedDate])
36+
VALUES (s.[AddressTypeID], s.[Name], s.[rowguid], s.[ModifiedDate])
37+
WHEN MATCHED THEN
38+
UPDATE SET
39+
[Name] = s.[Name], [rowguid] = s.[rowguid], [ModifiedDate] = s.[ModifiedDate]
40+
WHEN NOT MATCHED BY source THEN
41+
DELETE
42+
;
43+
44+
DROP TABLE #Person_AddressType;
45+
46+
-- End data of table: [Person].[AddressType] --
47+
END
48+
GO

0 commit comments

Comments
 (0)