├── .gitignore
├── Build
└── Scripts
│ ├── main.msbuild
│ └── properties-repository-specific.msbuild
├── License.txt
├── README.md
├── Source
├── .gitignore
├── .nuget
│ ├── NuGet.Config
│ ├── NuGet.exe
│ ├── NuGet.targets
│ └── packages.config
├── DatabaseHelper.sln
├── Mirabeau.MsSql.Library.IntegrationTests
│ ├── BulkInsertTest.cs
│ ├── CreateTable.txt
│ ├── DatabaseExecutionTests.cs
│ ├── DateTimeParameterIntegrationTests.cs
│ ├── DeadlockIntegrationTest.cs
│ ├── GlobalSuppressions.cs
│ ├── Mirabeau.MsSql.Library.IntegrationTests.csproj
│ ├── Mirabeau.MsSql.Library.IntegrationTests.ruleset
│ ├── Properties
│ │ ├── AssemblyInfo.cs
│ │ ├── Resources.Designer.cs
│ │ └── Resources.resx
│ └── packages.config
├── Mirabeau.MsSql.Library.UnitTests
│ ├── DatabaseHelperTests.cs
│ ├── DbDataReaderHelperTests.cs
│ ├── ExpectedSqlQuery.txt
│ ├── GlobalSuppressions.cs
│ ├── Mirabeau.MsSql.Library.UnitTests.csproj
│ ├── Mirabeau.MsSql.Library.UnitTests.ruleset
│ ├── OverrideTests.cs
│ ├── Properties
│ │ ├── AssemblyInfo.cs
│ │ ├── Resources.Designer.cs
│ │ └── Resources.resx
│ ├── SqlDebugHelperTests.cs
│ ├── SqlParameterExtensionsTests.cs
│ └── packages.config
├── Mirabeau.MsSql.Library
│ ├── DatabaseHelper.cs
│ ├── GlobalSuppressions.cs
│ ├── IMSqlHelper.cs
│ ├── IParameterCache.cs
│ ├── Mirabeau.MsSql.Library.csproj
│ ├── Mirabeau.MsSql.Library.nuspec
│ ├── Mirabeau.MsSql.Library.snk
│ ├── MsSqlHelper.cs
│ ├── ObjectDataReader.cs
│ ├── ParameterCache.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── SqlDebugHelper.cs
│ ├── SqlGenerator.cs
│ ├── SqlParameterExtensions.cs
│ ├── SqlParameterFactory.cs
│ └── packages.config
├── Mirabeau.MySql.Library.IntegrationTests
│ ├── DatabaseExecutionTests.cs
│ ├── Mirabeau.MySql.Library.IntegrationTests.csproj
│ ├── Mirabeau.MySql.Library.IntegrationTests.ruleset
│ ├── Properties
│ │ ├── AssemblyInfo.cs
│ │ ├── Resources.Designer.cs
│ │ └── Resources.resx
│ ├── SqlScripts
│ │ ├── CreateProcedure.sql
│ │ ├── CreateTable.sql
│ │ └── InsertIntoTable.sql
│ ├── TempTable.cs
│ ├── app.config
│ └── packages.config
├── Mirabeau.MySql.Library.UnitTests
│ ├── Mirabeau.MySql.Library.UnitTests.csproj
│ ├── Mirabeau.MySql.Library.UnitTests.ruleset
│ ├── MySqlParameterExtensionsTests.cs
│ ├── MySqlParameterFactoryTests.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── app.config
│ └── packages.config
├── Mirabeau.MySql.Library
│ ├── DatabaseHelper.cs
│ ├── GlobalSuppressions.cs
│ ├── IMySqlHelper.cs
│ ├── Mirabeau.MySql.Library.csproj
│ ├── Mirabeau.MySql.Library.nuspec
│ ├── Mirabeau.MySql.Library.snk
│ ├── MySqlHelper.cs
│ ├── MySqlParameterExtensions.cs
│ ├── MySqlParameterFactory.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── app.config
│ └── packages.config
├── Mirabeau.Sql
│ ├── DatabaseHelper.cs
│ ├── DbDataReaderHelper.cs
│ ├── GlobalSuppressions.cs
│ ├── IDatabaseHelper.cs
│ ├── Mirabeau.Sql.Library.snk
│ ├── Mirabeau.Sql.csproj
│ ├── ParameterFactory.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── String.Resources.Designer.cs
│ ├── String.Resources.resx
│ ├── StringExtensions.cs
│ └── TaskExtentions.cs
└── packages
│ └── repositories.config
├── appveyor.yml
├── mssql-icon.png
├── mysql-icon.png
└── releaseversion.txt
/.gitignore:
--------------------------------------------------------------------------------
1 | Source/packages/
2 | msbuild-by-convention/
3 | *.metaproj
4 | *.tmp
5 |
--------------------------------------------------------------------------------
/Build/Scripts/properties-repository-specific.msbuild:
--------------------------------------------------------------------------------
1 |
2 |
3 | $(BaseDirectory)Source\
4 | Library
5 |
6 |
--------------------------------------------------------------------------------
/License.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2014, Mirabeau B.V.
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5 |
6 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7 |
8 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9 |
10 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
11 |
12 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # The SqlHelper #
2 | ### What is this repository for? ###
3 |
4 | This is a helper assembly to make accessing the database easier. It helps you creating SqlParameters, executing queries and stored procedures and reading from the DataReader object.
5 | This assembly has proven itself by being used for several clients and is based on the Microsoft Data Access Application Block for .NET.
6 |
7 | Currently it supports both MsSql and MySql databases.
8 | The base sourcecode was taken from the Microsoft .NET Data Access Application Block v2.0 and improved to support the latest .net Frameworks and has build in support for asynchronous programming (async/await)
9 | There is also a now-static version (MsSqlHelper : IMsSqlHelper & MySqlHelper : IMySqlHelper)
10 |
11 | There is also an option to generate Sql-staments for queries and stored procedure with parameter declaration to debug your queries in Sql Server Managerment studio (Sql-server only).
12 |
13 | Build status| Coverage Status| NuGet downloads (MSSql) | NuGet downloads (MYSQL)
14 | ----------- | -------------- | --------------- | ---------------
15 | [](https://ci.appveyor.com/project/jeroenpot/sqlhelper)|[](https://coveralls.io/github/jeroenpot/SqlHelper?branch=)|[](https://www.nuget.org/packages/MsSqlHelper)|[](https://www.nuget.org/packages/MySqlHelper)
16 |
17 | ### Examples ###
18 | #### Sql parameters ####
19 | ```C#
20 | // This extention is available for the common value types and the DateTime object
21 | int value = 3;
22 | SqlParameter sqlParameter1 = value.CreateSqlParameter("SqlParameterName");
23 |
24 | string stringValue = "some value";
25 | SqlParameter sqlParameter2 = stringValue.CreateSqlParameter("ParameterName");
26 |
27 | // Sets the parameter value to DBNull.Value
28 | int? nullableValue = null;
29 | SqlParameter sqlParameter3 = nullableValue.CreateSqlParameter("ParameterName");
30 |
31 | // If you have a parameter that is not supported out of the box, there is a generic method for you:
32 | ulong otherValue = 123;
33 | SqlParameterExtensions.CreateSqlParameter(otherValue, "ParameterName");
34 | ```
35 |
36 | #### Executing queries ####
37 | ```C#
38 | string connectionString = "my database connection string";
39 |
40 | var parameters = new List
41 | {
42 | 1234.CreateSqlParameter("Parameter1"),
43 | "parmeter2value".CreateSqlParameter("Parameter2")
44 | };
45 |
46 | using (
47 | IDataReader dataReader = DatabaseHelper.ExecuteReader(connectionString, CommandType.StoredProcedure,
48 | "MyStoredProcedure", parameters))
49 | {
50 | while (dataReader.Read())
51 | {
52 | // Datareader helper
53 | // For not-nullable columns:
54 | int column1 = dataReader["databaseColumn1"].GetDbValueOrDefaultForValueType();
55 |
56 | // For nullable columns:
57 | int? column2 = dataReader["databaseColumn2"].GetDbValueForNullableValueType();
58 | }
59 | }
60 |
61 | // Transactions
62 | using (var sqlConnection = new SqlConnection(connectionString))
63 | {
64 | sqlConnection.Open();
65 | using (var sqlTransaction = sqlConnection.BeginTransaction())
66 | {
67 | DatabaseHelper.ExecuteScalar(sqlTransaction, CommandType.StoredProcedure, "StoredProcedureName1");
68 | DatabaseHelper.ExecuteScalar(sqlTransaction, CommandType.StoredProcedure, "StoredProcedureName2");
69 | sqlTransaction.Commit();
70 | }
71 | }
72 | ```
73 | #### Generate Executable Sql Statements (sql-server only) ####
74 | ```C#
75 | float? nullable = null;
76 | decimal decimalValue = 123.456m;
77 | string sql = "sp_test";
78 |
79 | IList parameters = new List();
80 | parameters.Add(0.CreateSqlParameter("value1"));
81 | parameters.Add("hello world".CreateSqlParameter("value2"));
82 | parameters.Add(nullable.CreateSqlParameter("value3"));
83 | parameters.Add(decimalValue.CreateSqlParameter("value4"));
84 |
85 | string executableSql = SqlDebugHelper.CreateExecutableSqlStatement(sql, parameters);
86 | // Results in
87 | //EXEC sp_test @value1 = 0, @value2 = N'hello world', @value3 = null, @value4 = 123.456"));
88 | ```
89 |
90 | ### How do I get set up? ###
91 |
92 | Build the project, or get the nuget package:
93 | ```sh
94 | Install-Package MsSqlHelper
95 | ```
96 |
97 | ```sh
98 | Install-Package MySqlHelper
99 | ```
100 |
101 | If you have long running queries and need to change the connection timeout you can set the config value SqlCommandTimeout in te appsettings (in seconds)
102 | ```sh
103 |
104 | ```
105 |
106 | ### Contribution guidelines ###
107 | * Pull request should be made to develop branch.
108 | * Comments, methods and variables in english.
109 | * Create unittests where possible.
110 | * Try to stick to the existing coding style.
111 | * Give a short description in the pull request what you're doing and why.
112 |
113 |
--------------------------------------------------------------------------------
/Source/.gitignore:
--------------------------------------------------------------------------------
1 | Thumbs.db
2 | *.obj
3 | *.pdb
4 | *.user
5 | *.aps
6 | *.pch
7 | *.vspscc
8 | *_i.c
9 | *_p.c
10 | *.ncb
11 | *.suo
12 | *.sln.docstates
13 | *.tlb
14 | *.tlh
15 | *.bak
16 | *.cache
17 | *.ilk
18 | *.log
19 | [Bb]in
20 | [Dd]ebug*/
21 | *.lib
22 | *.sbr
23 | obj/
24 | [Rr]elease*/
25 | App_Data*/
26 | App_Code*/
27 | App_Plugins*/
28 | App_Browsers*/
29 | bin*/
30 | media/*
31 | _ReSharper*/
32 | [Tt]est[Rr]esult*
33 | *.vssscc
34 | $tf*/
35 | .sass-cache
36 |
--------------------------------------------------------------------------------
/Source/.nuget/NuGet.Config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Source/.nuget/NuGet.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeroenpot/SqlHelper/a72fed0cc4a3276854fa33b13692806a60140fb4/Source/.nuget/NuGet.exe
--------------------------------------------------------------------------------
/Source/.nuget/NuGet.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(MSBuildProjectDirectory)\..\
5 |
6 |
7 | false
8 |
9 |
10 | false
11 |
12 |
13 | true
14 |
15 |
16 | false
17 |
18 |
19 |
20 |
21 |
22 |
26 |
27 |
28 |
29 |
30 | $([System.IO.Path]::Combine($(SolutionDir), ".nuget"))
31 | $([System.IO.Path]::Combine($(ProjectDir), "packages.config"))
32 |
33 |
34 |
35 |
36 | $(SolutionDir).nuget
37 | packages.config
38 |
39 |
40 |
41 |
42 | $(NuGetToolsPath)\NuGet.exe
43 | @(PackageSource)
44 |
45 | "$(NuGetExePath)"
46 | mono --runtime=v4.0.30319 $(NuGetExePath)
47 |
48 | $(TargetDir.Trim('\\'))
49 |
50 | -RequireConsent
51 | -NonInteractive
52 |
53 |
54 | $(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir "$(SolutionDir) "
55 | $(NuGetCommand) pack "$(ProjectPath)" -Properties Configuration=$(Configuration) $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols
56 |
57 |
58 |
59 | RestorePackages;
60 | $(BuildDependsOn);
61 |
62 |
63 |
64 |
65 | $(BuildDependsOn);
66 | BuildPackage;
67 |
68 |
69 |
70 |
71 |
72 |
73 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
88 |
89 |
92 |
93 |
94 |
95 |
97 |
98 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
130 |
131 |
132 |
133 |
--------------------------------------------------------------------------------
/Source/.nuget/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Source/DatabaseHelper.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2013
4 | VisualStudioVersion = 12.0.40629.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mirabeau.Sql", "Mirabeau.Sql\Mirabeau.Sql.csproj", "{0D304D74-5711-401F-9E23-0485524821E2}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mirabeau.MsSql.Library.UnitTests", "Mirabeau.MsSql.Library.UnitTests\Mirabeau.MsSql.Library.UnitTests.csproj", "{E602608D-DA5D-4430-960A-694D1FD8D2A2}"
9 | EndProject
10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{A626A63D-B130-4569-8EB9-0E1F9CFA74DA}"
11 | ProjectSection(SolutionItems) = preProject
12 | .nuget\NuGet.Config = .nuget\NuGet.Config
13 | .nuget\NuGet.exe = .nuget\NuGet.exe
14 | .nuget\NuGet.targets = .nuget\NuGet.targets
15 | EndProjectSection
16 | EndProject
17 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mirabeau.MsSql.Library.IntegrationTests", "Mirabeau.MsSql.Library.IntegrationTests\Mirabeau.MsSql.Library.IntegrationTests.csproj", "{EE337C58-D756-441D-A91B-80A94A2FD627}"
18 | EndProject
19 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mirabeau.MsSql.Library", "Mirabeau.MsSql.Library\Mirabeau.MsSql.Library.csproj", "{B7EF69F5-0582-4C03-B8D0-ADE4060ED8FC}"
20 | EndProject
21 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mirabeau.MySql.Library", "Mirabeau.MySql.Library\Mirabeau.MySql.Library.csproj", "{AADED218-6603-4ED4-8BBA-0F994CC62286}"
22 | EndProject
23 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mirabeau.MySql.Library.IntegrationTests", "Mirabeau.MySql.Library.IntegrationTests\Mirabeau.MySql.Library.IntegrationTests.csproj", "{589BA55B-D937-41CF-97D2-1B6CB23E7437}"
24 | EndProject
25 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mirabeau.MySql.Library.UnitTests", "Mirabeau.MySql.Library.UnitTests\Mirabeau.MySql.Library.UnitTests.csproj", "{67477434-4E6E-46C5-811A-249A321914A2}"
26 | EndProject
27 | Global
28 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
29 | Debug|Any CPU = Debug|Any CPU
30 | Release|Any CPU = Release|Any CPU
31 | EndGlobalSection
32 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
33 | {0D304D74-5711-401F-9E23-0485524821E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
34 | {0D304D74-5711-401F-9E23-0485524821E2}.Debug|Any CPU.Build.0 = Debug|Any CPU
35 | {0D304D74-5711-401F-9E23-0485524821E2}.Release|Any CPU.ActiveCfg = Release|Any CPU
36 | {0D304D74-5711-401F-9E23-0485524821E2}.Release|Any CPU.Build.0 = Release|Any CPU
37 | {E602608D-DA5D-4430-960A-694D1FD8D2A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
38 | {E602608D-DA5D-4430-960A-694D1FD8D2A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
39 | {E602608D-DA5D-4430-960A-694D1FD8D2A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
40 | {E602608D-DA5D-4430-960A-694D1FD8D2A2}.Release|Any CPU.Build.0 = Release|Any CPU
41 | {EE337C58-D756-441D-A91B-80A94A2FD627}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
42 | {EE337C58-D756-441D-A91B-80A94A2FD627}.Debug|Any CPU.Build.0 = Debug|Any CPU
43 | {EE337C58-D756-441D-A91B-80A94A2FD627}.Release|Any CPU.ActiveCfg = Release|Any CPU
44 | {EE337C58-D756-441D-A91B-80A94A2FD627}.Release|Any CPU.Build.0 = Release|Any CPU
45 | {B7EF69F5-0582-4C03-B8D0-ADE4060ED8FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
46 | {B7EF69F5-0582-4C03-B8D0-ADE4060ED8FC}.Debug|Any CPU.Build.0 = Debug|Any CPU
47 | {B7EF69F5-0582-4C03-B8D0-ADE4060ED8FC}.Release|Any CPU.ActiveCfg = Release|Any CPU
48 | {B7EF69F5-0582-4C03-B8D0-ADE4060ED8FC}.Release|Any CPU.Build.0 = Release|Any CPU
49 | {AADED218-6603-4ED4-8BBA-0F994CC62286}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
50 | {AADED218-6603-4ED4-8BBA-0F994CC62286}.Debug|Any CPU.Build.0 = Debug|Any CPU
51 | {AADED218-6603-4ED4-8BBA-0F994CC62286}.Release|Any CPU.ActiveCfg = Release|Any CPU
52 | {AADED218-6603-4ED4-8BBA-0F994CC62286}.Release|Any CPU.Build.0 = Release|Any CPU
53 | {589BA55B-D937-41CF-97D2-1B6CB23E7437}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
54 | {589BA55B-D937-41CF-97D2-1B6CB23E7437}.Debug|Any CPU.Build.0 = Debug|Any CPU
55 | {589BA55B-D937-41CF-97D2-1B6CB23E7437}.Release|Any CPU.ActiveCfg = Release|Any CPU
56 | {589BA55B-D937-41CF-97D2-1B6CB23E7437}.Release|Any CPU.Build.0 = Release|Any CPU
57 | {67477434-4E6E-46C5-811A-249A321914A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
58 | {67477434-4E6E-46C5-811A-249A321914A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
59 | {67477434-4E6E-46C5-811A-249A321914A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
60 | {67477434-4E6E-46C5-811A-249A321914A2}.Release|Any CPU.Build.0 = Release|Any CPU
61 | EndGlobalSection
62 | GlobalSection(SolutionProperties) = preSolution
63 | HideSolutionNode = FALSE
64 | EndGlobalSection
65 | EndGlobal
66 |
--------------------------------------------------------------------------------
/Source/Mirabeau.MsSql.Library.IntegrationTests/BulkInsertTest.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Data;
4 | using System.Data.SqlClient;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 | using NUnit.Framework;
9 |
10 | namespace Mirabeau.MsSql.Library.IntegrationTests
11 | {
12 | [TestFixture, Explicit]
13 | public class BulkInsertTest
14 | {
15 | private string connectionString = "insert connection string here";
16 |
17 | [TestFixtureSetUp]
18 | public void Setup()
19 | {
20 | DatabaseHelper.ExecuteNonQuery(connectionString, CommandType.Text, Properties.Resources.CreateTable);
21 | }
22 |
23 | [Test]
24 | public void ShouldInsertBulk()
25 | {
26 | var people = CreateSamplePeople(10000);
27 |
28 | using (var bulkCopy = new SqlBulkCopy(connectionString))
29 | {
30 | bulkCopy.DestinationTableName = "People";
31 | bulkCopy.ColumnMappings.Add("Name", "NAME");
32 | bulkCopy.ColumnMappings.Add("DateOfBirth", "Date");
33 |
34 | new MsSqlHelper().BulkInsert(people, bulkCopy);
35 | }
36 | }
37 |
38 | private static IEnumerable CreateSamplePeople(int count)
39 | {
40 | return Enumerable.Range(1, count)
41 | .Select(i => new Person
42 | {
43 | Name = "Person" + i,
44 | DateOfBirth = new DateTime(
45 | 1950 + (i%50),
46 | ((i*3)%12) + 1,
47 | ((i*7)%29) + 1)
48 | });
49 | }
50 | }
51 |
52 | internal class Person
53 | {
54 | public string Name { get; set; }
55 | public DateTime DateOfBirth { get; set; }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/Source/Mirabeau.MsSql.Library.IntegrationTests/CreateTable.txt:
--------------------------------------------------------------------------------
1 | IF OBJECT_ID('People') IS NOT NULL
2 | DROP TABLE People
3 |
4 | CREATE TABLE People
5 | (
6 | Id int not null identity(1, 1) primary key,
7 | NAME varchar(100) not null,
8 | Date datetime not null
9 | )
10 |
--------------------------------------------------------------------------------
/Source/Mirabeau.MsSql.Library.IntegrationTests/DatabaseExecutionTests.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Data;
3 | using System.Data.Common;
4 | using System.Data.SqlClient;
5 | using NUnit.Framework;
6 |
7 | namespace Mirabeau.MsSql.Library.IntegrationTests
8 | {
9 | [TestFixture, Explicit("Requires SQL-server master database.")]
10 | public class DatabaseExecutionTests
11 | {
12 | // Set this connection string to any sql server and point to the master database.
13 | private const string Connectionstring = "Server=TEST-DB1;Database=master;Integrated Security=true";
14 | private const string StoredProcedureName = "[sys].[sp_oledb_language]";
15 | private const string Query = "SELECT COUNT(*) FROM sys.objects WHERE type = @type";
16 |
17 | readonly IEnumerable _parametersList = new List();
18 | readonly SqlParameter[] _parametersArray = new SqlParameter[0];
19 | private SqlConnection _sqlConnection;
20 |
21 | [TestFixtureSetUp]
22 | public void SetUpFixture()
23 | {
24 | _sqlConnection = new SqlConnection(Connectionstring);
25 | }
26 |
27 | [Test]
28 | public void ShouldExecuteReader()
29 | {
30 | using (var reader = DatabaseHelper.ExecuteReader(Connectionstring, "[sys].[sp_datatype_info]", -7, 1))
31 | {
32 | while (reader.Read())
33 | {
34 | }
35 | }
36 |
37 | using (var reader = DatabaseHelper.ExecuteReader(_sqlConnection, CommandType.StoredProcedure, StoredProcedureName))
38 | {
39 | while (reader.Read())
40 | {
41 | }
42 | }
43 |
44 | using (var reader = DatabaseHelper.ExecuteReader(_sqlConnection, CommandType.StoredProcedure, StoredProcedureName, _parametersList))
45 | {
46 | while (reader.Read())
47 | {
48 | }
49 | }
50 |
51 | using (var reader = DatabaseHelper.ExecuteReader(_sqlConnection, CommandType.StoredProcedure, StoredProcedureName, _parametersArray))
52 | {
53 | while (reader.Read())
54 | {
55 | }
56 | }
57 |
58 | using (var reader = DatabaseHelper.ExecuteReader(Connectionstring, CommandType.StoredProcedure, StoredProcedureName))
59 | {
60 | while (reader.Read())
61 | {
62 | }
63 | }
64 |
65 | using (var reader = DatabaseHelper.ExecuteReader(Connectionstring, CommandType.StoredProcedure, StoredProcedureName, _parametersList))
66 | {
67 | while (reader.Read())
68 | {
69 | }
70 | }
71 |
72 | using (var reader = DatabaseHelper.ExecuteReader(Connectionstring, CommandType.StoredProcedure, StoredProcedureName, _parametersArray))
73 | {
74 | while (reader.Read())
75 | {
76 | }
77 | }
78 |
79 | using (var transaction = _sqlConnection.BeginTransaction())
80 | {
81 | using (var reader = DatabaseHelper.ExecuteReader(transaction, CommandType.StoredProcedure, StoredProcedureName))
82 | {
83 | while (reader.Read())
84 | {
85 | }
86 | }
87 |
88 | using (var reader = DatabaseHelper.ExecuteReader(transaction, CommandType.StoredProcedure, StoredProcedureName, _parametersList))
89 | {
90 | while (reader.Read())
91 | {
92 | }
93 | }
94 |
95 | using (var reader = DatabaseHelper.ExecuteReader(transaction, CommandType.StoredProcedure, StoredProcedureName, _parametersArray))
96 | {
97 | while (reader.Read())
98 | {
99 | }
100 | }
101 |
102 | transaction.Rollback();
103 | }
104 | }
105 |
106 | [Test]
107 | public void ShouldExecuteReaderStoredSql()
108 | {
109 | using (var reader = DatabaseHelper.ExecuteReader(Connectionstring, CommandType.Text, Query, "s".CreateSqlParameter("type")))
110 | {
111 | while (reader.Read())
112 | {
113 | }
114 | }
115 | }
116 |
117 | [Test]
118 | public async void ShouldExecuteReaderAsyncStoredProcedure()
119 | {
120 | using (DbDataReader sqlDataReader = await DatabaseHelper.ExecuteReaderAsync(Connectionstring, CommandType.StoredProcedure, StoredProcedureName))
121 | {
122 | while (await sqlDataReader.ReadAsync())
123 | {
124 | }
125 | }
126 | }
127 |
128 | [Test]
129 | public void ShouldExecuteNonQueryStoredProcedure()
130 | {
131 | DatabaseHelper.ExecuteNonQuery(Connectionstring, CommandType.StoredProcedure, StoredProcedureName);
132 | DatabaseHelper.ExecuteNonQuery(Connectionstring, CommandType.StoredProcedure, StoredProcedureName, _parametersArray);
133 | DatabaseHelper.ExecuteNonQuery(_sqlConnection, CommandType.StoredProcedure, StoredProcedureName);
134 |
135 | }
136 |
137 | [Test]
138 | public async void ShouldExecuteNonQueryAsyncStoredProcedure()
139 | {
140 | await DatabaseHelper.ExecuteNonQueryAsync(Connectionstring, CommandType.StoredProcedure, StoredProcedureName);
141 | await DatabaseHelper.ExecuteNonQueryAsync(Connectionstring, CommandType.StoredProcedure, StoredProcedureName, _parametersArray);
142 | await DatabaseHelper.ExecuteNonQueryAsync(_sqlConnection, CommandType.StoredProcedure, StoredProcedureName);
143 | }
144 |
145 | [Test]
146 | public void ShouldExecuteDataSetStoredProcedure()
147 | {
148 | DatabaseHelper.ExecuteDataSet(Connectionstring, CommandType.StoredProcedure, StoredProcedureName);
149 | DatabaseHelper.ExecuteDataSet(_sqlConnection, CommandType.StoredProcedure, StoredProcedureName);
150 | }
151 |
152 | [Test]
153 | public void ShouldExecuteScalarQuery()
154 | {
155 | int i = (int)DatabaseHelper.ExecuteScalar(Connectionstring, CommandType.Text, Query, "S".CreateSqlParameter("type"));
156 |
157 | Assert.That(i, Is.GreaterThan(0));
158 | }
159 | }
160 | }
161 |
--------------------------------------------------------------------------------
/Source/Mirabeau.MsSql.Library.IntegrationTests/DateTimeParameterIntegrationTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Data;
4 | using System.Data.SqlClient;
5 | using NUnit.Framework;
6 |
7 | namespace Mirabeau.MsSql.Library.IntegrationTests
8 | {
9 | [TestFixture, Explicit("Requires SQL-server master database.")]
10 | public class DateTimeParameterIntegrationTests
11 | {
12 | private const string Connectionstring = "Server=TEST-DB1;Database=master;Integrated Security=true";
13 |
14 | private readonly MsSqlHelper _sqlHelper = new MsSqlHelper();
15 |
16 |
17 | [TestFixtureSetUp]
18 | public void Setup()
19 | {
20 | string createTable =
21 | "CREATE TABLE dbo.tmp_dates (id int not null, d1 date NULL, d2 datetime NULL, d3 datetime2(7) NULL, d4 datetimeoffset(7) NULL)";
22 |
23 | _sqlHelper.ExecuteNonQuery(Connectionstring, CommandType.Text, createTable);
24 | }
25 |
26 | [Test]
27 | public void ShouldInsertUtcDatesCorrectly()
28 | {
29 | IList parameters = new List();
30 | parameters.Add(1.CreateSqlParameter("id"));
31 | parameters.Add(DateTime.UtcNow.CreateSqlParameter("d1", SqlDbType.Date));
32 | parameters.Add(DateTime.UtcNow.CreateSqlParameter("d2", SqlDbType.DateTime));
33 | parameters.Add(DateTime.UtcNow.CreateSqlParameter("d3", SqlDbType.DateTime2));
34 | parameters.Add(DateTime.UtcNow.CreateSqlParameter("d4", SqlDbType.DateTimeOffset));
35 |
36 | string insert =
37 | "INSERT INTO dbo.tmp_dates (id, d1, d2, d3 , d4) VALUES(@id, @d1, @d2, @d3, @d4)";
38 |
39 | _sqlHelper.ExecuteNonQuery(Connectionstring, CommandType.Text, insert, parameters);
40 | }
41 |
42 | [Test]
43 | public void ShouldInsertNowDatesCorrectly()
44 | {
45 | IList parameters = new List();
46 | parameters.Add(2.CreateSqlParameter("id"));
47 | parameters.Add(DateTime.Now.CreateSqlParameter("d1", SqlDbType.Date));
48 | parameters.Add(DateTime.Now.CreateSqlParameter("d2", SqlDbType.DateTime));
49 | parameters.Add(DateTime.Now.CreateSqlParameter("d3", SqlDbType.DateTime2));
50 | parameters.Add(DateTime.Now.CreateSqlParameter("d4", SqlDbType.DateTimeOffset));
51 |
52 | string insert =
53 | "INSERT INTO dbo.tmp_dates (id, d1, d2, d3 , d4) VALUES(@id, @d1, @d2, @d3, @d4)";
54 |
55 | _sqlHelper.ExecuteNonQuery(Connectionstring, CommandType.Text, insert, parameters);
56 | }
57 |
58 | [TestFixtureTearDown]
59 | public void TearDown()
60 | {
61 | string dropTable = "drop table dbo.tmp_dates";
62 | _sqlHelper.ExecuteNonQuery(Connectionstring, CommandType.Text, dropTable);
63 |
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/Source/Mirabeau.MsSql.Library.IntegrationTests/DeadlockIntegrationTest.cs:
--------------------------------------------------------------------------------
1 | using System.Data;
2 | using System.Data.SqlClient;
3 | using NUnit.Framework;
4 |
5 | namespace Mirabeau.MsSql.Library.IntegrationTests
6 | {
7 | [TestFixture]
8 | public class DeadlockIntegrationTest
9 | {
10 | [Test, Ignore]
11 | public async void ShouldNotDeadlock()
12 | {
13 | // Not all library code used to have .ConfigureAwait(false);
14 | // This caused this code to run forever. Async test, opening async connection, running the sync db commands which use the async versions internally.
15 | // See these topics for more information about .ConfigureAwait(false);
16 | // http://stackoverflow.com/questions/13489065/best-practice-to-call-configureawait-for-all-server-side-code/13489639#13489639
17 | // http://blog.stephencleary.com/2012/07/dont-block-on-async-code.html
18 |
19 | string connectionstring = "Server=.;Database=master;Integrated Security=true";
20 |
21 | SqlConnection conn = new SqlConnection(connectionstring);
22 | await conn.OpenAsync();
23 |
24 | string query = "select top 1 TABLE_NAME from information_schema.tables";
25 | DatabaseHelper.ExecuteDataSet(connectionstring, CommandType.Text, query);
26 | DatabaseHelper.ExecuteNonQuery(connectionstring, CommandType.Text, query);
27 | DatabaseHelper.ExecuteScalar(connectionstring, CommandType.Text, query);
28 | using (var dbReader = DatabaseHelper.ExecuteReader(connectionstring, CommandType.Text, query))
29 | {
30 | if (dbReader.HasRows)
31 | {
32 | while (dbReader.Read())
33 | {
34 | }
35 | }
36 | }
37 |
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/Source/Mirabeau.MsSql.Library.IntegrationTests/GlobalSuppressions.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeroenpot/SqlHelper/a72fed0cc4a3276854fa33b13692806a60140fb4/Source/Mirabeau.MsSql.Library.IntegrationTests/GlobalSuppressions.cs
--------------------------------------------------------------------------------
/Source/Mirabeau.MsSql.Library.IntegrationTests/Mirabeau.MsSql.Library.IntegrationTests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {EE337C58-D756-441D-A91B-80A94A2FD627}
8 | Library
9 | Properties
10 | Mirabeau.MsSql.Library.IntegrationTests
11 | Mirabeau.MsSql.Library.IntegrationTests
12 | v4.5
13 | 512
14 | ..\
15 | true
16 |
17 |
18 | true
19 | full
20 | false
21 | bin\Debug\
22 | DEBUG;TRACE
23 | prompt
24 | 4
25 | Mirabeau.MsSql.Library.IntegrationTests.ruleset
26 |
27 |
28 | pdbonly
29 | true
30 | bin\Release\
31 | TRACE
32 | prompt
33 | 4
34 | Mirabeau.MsSql.Library.IntegrationTests.ruleset
35 |
36 |
37 |
38 | ..\packages\Microsoft.SqlServer.Types.11.0.2\lib\net20\Microsoft.SqlServer.Types.dll
39 | True
40 |
41 |
42 | ..\packages\NUnit.2.6.4\lib\nunit.framework.dll
43 | True
44 |
45 |
46 | ..\packages\RhinoMocks.3.6.1\lib\net\Rhino.Mocks.dll
47 | True
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 | True
66 | True
67 | Resources.resx
68 |
69 |
70 |
71 |
72 | {B7EF69F5-0582-4C03-B8D0-ADE4060ED8FC}
73 | Mirabeau.MsSql.Library
74 |
75 |
76 | {0d304d74-5711-401f-9e23-0485524821e2}
77 | Mirabeau.Sql
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 | ResXFileCodeGenerator
90 | Resources.Designer.cs
91 |
92 |
93 |
94 |
95 |
96 |
97 | This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
98 |
99 |
100 |
101 |
108 |
--------------------------------------------------------------------------------
/Source/Mirabeau.MsSql.Library.IntegrationTests/Mirabeau.MsSql.Library.IntegrationTests.ruleset:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
--------------------------------------------------------------------------------
/Source/Mirabeau.MsSql.Library.IntegrationTests/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 |
4 | // General Information about an assembly is controlled through the following
5 | // set of attributes. Change these attribute values to modify the information
6 | // associated with an assembly.
7 | [assembly: AssemblyTitle("Mirabeau.MsSql.Library.IntegrationTests")]
8 | [assembly: AssemblyDescription("")]
9 | [assembly: AssemblyConfiguration("")]
10 | [assembly: AssemblyCompany("Mirabeau BV")]
11 | [assembly: AssemblyProduct("Mirabeau.MsSql.Library.IntegrationTests")]
12 | [assembly: AssemblyCopyright("Copyright © Mirabeau BV 2015")]
13 | [assembly: AssemblyTrademark("")]
14 | [assembly: AssemblyCulture("")]
15 |
16 | // Setting ComVisible to false makes the types in this assembly not visible
17 | // to COM components. If you need to access a type in this assembly from
18 | // COM, set the ComVisible attribute to true on that type.
19 | [assembly: ComVisible(false)]
20 |
21 | // The following GUID is for the ID of the typelib if this project is exposed to COM
22 | [assembly: Guid("9d8e67b5-5b16-40a7-b6a2-4edccf46d0ea")]
23 |
24 | // Version information for an assembly consists of the following four values:
25 | //
26 | // Major Version
27 | // Minor Version
28 | // Build Number
29 | // Revision
30 | //
31 | // You can specify all the values or you can default the Build and Revision Numbers
32 | // by using the '*' as shown below:
33 | // [assembly: AssemblyVersion("1.0.*")]
34 | [assembly: AssemblyVersion("1.0.0.0")]
35 | [assembly: AssemblyFileVersion("1.0.0.0")]
36 |
--------------------------------------------------------------------------------
/Source/Mirabeau.MsSql.Library.IntegrationTests/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace Mirabeau.MsSql.Library.IntegrationTests.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// Returns the cached ResourceManager instance used by this class.
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Mirabeau.MsSql.Library.IntegrationTests.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// Overrides the current thread's CurrentUICulture property for all
51 | /// resource lookups using this strongly typed resource class.
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 |
63 | ///
64 | /// Looks up a localized string similar to .
65 | ///
66 | internal static string CreateTable {
67 | get {
68 | return ResourceManager.GetString("CreateTable", resourceCulture);
69 | }
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/Source/Mirabeau.MsSql.Library.IntegrationTests/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
121 |
122 | ..\createtable.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8
123 |
124 |
--------------------------------------------------------------------------------
/Source/Mirabeau.MsSql.Library.IntegrationTests/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Source/Mirabeau.MsSql.Library.UnitTests/DatabaseHelperTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Data;
3 | using System.Data.SqlClient;
4 | using NUnit.Framework;
5 |
6 | namespace Mirabeau.MsSql.Library.UnitTests
7 | {
8 | public class DatabaseHelperTests
9 | {
10 | [TestFixture]
11 | internal class ExecuteNonQueryArgumentTests
12 | {
13 | private readonly IMsSqlHelper _sqlHelper = new MsSqlHelper();
14 |
15 | private readonly SqlConnection _connection = new SqlConnection("Data Source=.; Initial Catalog=X; User Id=Y; Password=######;");
16 |
17 | [TestCase(null)]
18 | [TestCase("")]
19 | [TestCase(" ")]
20 | public void ShouldThrowArgumentExceptionForConnectionstring(string connectionstring)
21 | {
22 | Assert.That(() => _sqlHelper.ExecuteNonQuery(connectionstring, CommandType.Text, "select"), Throws.TypeOf());
23 | }
24 |
25 | [TestCase(null)]
26 | [TestCase("")]
27 | [TestCase(" ")]
28 | public void AsyncShouldThrowArgumentExceptionForConnectionstring(string connectionstring)
29 | {
30 | Assert.That(async () => await _sqlHelper.ExecuteNonQueryAsync(connectionstring, CommandType.Text, "select"), Throws.TypeOf());
31 | }
32 |
33 | [Test]
34 | public void ShouldNotThrowNullReferenceExceptionForSqlConnection()
35 | {
36 | SqlConnection connection = null;
37 |
38 | // ReSharper disable once ExpressionIsAlwaysNull
39 | Assert.That(() => _sqlHelper.ExecuteNonQuery(connection, CommandType.Text, "select"), Throws.TypeOf());
40 | }
41 |
42 | [Test]
43 | public void AsyncShouldNotThrowNullReferenceExceptionForSqlConnection()
44 | {
45 | SqlConnection connection = null;
46 |
47 | // ReSharper disable once ExpressionIsAlwaysNull
48 | Assert.That(async () => await _sqlHelper.ExecuteNonQueryAsync(connection, CommandType.Text, "select"), Throws.TypeOf());
49 | }
50 |
51 | [TestCase(null)]
52 | [TestCase("")]
53 | [TestCase(" ")]
54 | public void ShouldNotThrowNullReferenceExceptionForEmptyCommand(string command)
55 | {
56 | Assert.That(() => _sqlHelper.ExecuteNonQuery(_connection, CommandType.Text, command), Throws.TypeOf());
57 | }
58 |
59 | [TestCase(null)]
60 | [TestCase("")]
61 | [TestCase(" ")]
62 | public void AsyncShouldNotThrowNullReferenceExceptionForEmptyCommand(string command)
63 | {
64 | Assert.That(async () => await _sqlHelper.ExecuteNonQueryAsync(_connection, CommandType.Text, command), Throws.TypeOf());
65 | }
66 |
67 | [Test]
68 | public void ShouldNotThrowNullReferenceExceptionForEmptyConnectionAndNoParameters()
69 | {
70 | SqlConnection connection = null;
71 |
72 | // ReSharper disable once ExpressionIsAlwaysNull
73 | Assert.That(() => _sqlHelper.ExecuteNonQuery(connection, "spname"), Throws.TypeOf());
74 | }
75 |
76 | [Test]
77 | public void AsyncShouldNotThrowNullReferenceExceptionForEmptyConnectionAndNoParameters()
78 | {
79 | SqlConnection connection = null;
80 |
81 | // ReSharper disable once ExpressionIsAlwaysNull
82 | Assert.That(async () => await _sqlHelper.ExecuteNonQueryAsync(connection, "spname"), Throws.TypeOf());
83 | }
84 |
85 | [Test]
86 | public void ShouldNotThrowNullReferenceExceptionForEmptyConnectionWithParameters()
87 | {
88 | SqlConnection connection = null;
89 |
90 | Assert.That(() => _sqlHelper.ExecuteNonQuery(connection, "spname", 0.CreateSqlParameter("parameter")), Throws.TypeOf());
91 | }
92 |
93 | [Test]
94 | public void AsyncShouldNotThrowNullReferenceExceptionForEmptyConnectionWithParameters()
95 | {
96 | SqlConnection connection = null;
97 |
98 | Assert.That(async () => await _sqlHelper.ExecuteNonQueryAsync(connection, "spname", 0.CreateSqlParameter("parameter")), Throws.TypeOf());
99 | }
100 |
101 | [TestCase(null)]
102 | [TestCase("")]
103 | [TestCase(" ")]
104 | public void ShouldThrowArgumentExceptionWhenProcedureNameIsNullOrEmpty(string storedProcedureName)
105 | {
106 | SqlConnection connection = new SqlConnection("Data Source=.; Initial Catalog=X; User Id=Y; Password=######;");
107 |
108 | Assert.That(() => _sqlHelper.ExecuteNonQuery(connection, storedProcedureName), Throws.TypeOf());
109 | }
110 |
111 | [TestCase(null)]
112 | [TestCase("")]
113 | [TestCase(" ")]
114 | public void AsyncShouldThrowArgumentExceptionWhenProcedureNameIsNullOrEmpty(string storedProcedureName)
115 | {
116 | SqlConnection connection = new SqlConnection("Data Source=.; Initial Catalog=X; User Id=Y; Password=######;");
117 |
118 | Assert.That(async () => await _sqlHelper.ExecuteNonQueryAsync(connection, storedProcedureName), Throws.TypeOf());
119 | }
120 |
121 | [Test]
122 | public void ShouldNotThrowArgumentNullExceptionWhenTransactionIsNull()
123 | {
124 | SqlTransaction transaction = null;
125 |
126 | // ReSharper disable once ExpressionIsAlwaysNull
127 | Assert.That(() => _sqlHelper.ExecuteNonQuery(transaction, "spname"), Throws.TypeOf());
128 | }
129 |
130 | [Test]
131 | public void AsyncShouldThrowArgumentNullExceptionWhenTransactionIsNull()
132 | {
133 | SqlTransaction transaction = null;
134 |
135 | // ReSharper disable once ExpressionIsAlwaysNull
136 | Assert.That(async () => await _sqlHelper.ExecuteNonQueryAsync(transaction, "spname"), Throws.TypeOf());
137 | }
138 |
139 | [TestCase(null)]
140 | [TestCase("")]
141 | public void ShouldThrowArgumentExceptionWhenProcedureNameIsNullOrEmptyAndParametersAreGiven(string storedProcedure)
142 | {
143 | SqlConnection connection = new SqlConnection("Data Source=.; Initial Catalog=X; User Id=Y; Password=######;");
144 |
145 | Assert.That(() => _sqlHelper.ExecuteNonQuery(connection, storedProcedure, 1), Throws.TypeOf());
146 | }
147 |
148 | [TestCase(null)]
149 | [TestCase("")]
150 | public void AsyncShouldThrowArgumentExceptionWhenProcedureNameIsNullOrEmptyAndParametersAreGiven(string storedProcedure)
151 | {
152 | SqlConnection connection = new SqlConnection("Data Source=.; Initial Catalog=X; User Id=Y; Password=######;");
153 |
154 | Assert.That(async () => await _sqlHelper.ExecuteNonQueryAsync(connection, storedProcedure, 1), Throws.TypeOf());
155 | }
156 |
157 | [Test]
158 | public void ShouldThrowArgumentNullForConnectionExceptionForExecuteScalar()
159 | {
160 | SqlConnection connection = null;
161 |
162 | Assert.That(() => _sqlHelper.ExecuteScalar(connection, "spname"), Throws.TypeOf());
163 | }
164 |
165 | [TestCase(null)]
166 | [TestCase("")]
167 | [TestCase(" ")]
168 | public void ShouldThrowArgumentExceptionForConnectionstringForExecuteScalar(string connectionstring)
169 | {
170 | Assert.That(() => _sqlHelper.ExecuteScalar(connectionstring, CommandType.Text, "select"), Throws.TypeOf());
171 | }
172 | }
173 | }
174 | }
175 |
--------------------------------------------------------------------------------
/Source/Mirabeau.MsSql.Library.UnitTests/DbDataReaderHelperTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | using Mirabeau.Sql;
4 |
5 | using NUnit.Framework;
6 |
7 | namespace Mirabeau.MsSql.Library.UnitTests
8 | {
9 | ///
10 | /// Test class for the database reader.
11 | ///
12 | public class DbDataReaderHelperTests
13 | {
14 | [TestFixture]
15 | internal class GetDbValueOrDefaultForValueTypeTests
16 | {
17 | [Test]
18 | public void ShouldReturnCorrectValueWhenValueIsNotDbNullAndTypeIsInt()
19 | {
20 | // Arrange
21 | object input = 1;
22 |
23 | // Act
24 | var value = input.GetDbValueOrDefaultForValueType();
25 |
26 | // Assert
27 | Assert.That(value, Is.EqualTo(1).And.TypeOf());
28 | }
29 |
30 | [Test]
31 | public void ShouldReturnDefaultValueWhenValueIsDbNullAndTypeIsInt()
32 | {
33 | // Arrange
34 | object input = DBNull.Value;
35 |
36 | // Act
37 | var value = input.GetDbValueOrDefaultForValueType();
38 |
39 | // Assert
40 | Assert.That(value, Is.EqualTo(0).And.TypeOf());
41 | }
42 |
43 | [Test]
44 | public void ShouldReturnCorrectValueWhenValueIsNotDbNullAndTypeIsBool()
45 | {
46 | // Arrange
47 | object input = true;
48 |
49 | // Act
50 | var value = input.GetDbValueOrDefaultForValueType();
51 |
52 | // Assert
53 | Assert.That(value, Is.True.And.TypeOf());
54 | }
55 |
56 | [Test]
57 | public void ShouldReturnDefaultValueWhenValueIsDbNullAndTypeIsBool()
58 | {
59 | // Arrange
60 | object input = DBNull.Value;
61 |
62 | // Act
63 | var value = input.GetDbValueOrDefaultForValueType();
64 |
65 | // Assert
66 | Assert.That(value, Is.False.And.TypeOf());
67 | }
68 | }
69 |
70 | [TestFixture]
71 | internal class GetDbValueForNullableValueType
72 | {
73 | [Test]
74 | public void ShouldReturnCorrectValueWhenValueIsNotDbNullAndTypeIsInt()
75 | {
76 | // Arrange
77 | object input = 1;
78 |
79 | // Act
80 | var value = input.GetDbValueForNullableValueType();
81 |
82 | // Assert
83 | Assert.That(value, Is.EqualTo(1).And.TypeOf());
84 | }
85 |
86 | [Test]
87 | public void ShouldReturnDefaultValueWhenValueIsDbNullAndTypeIsInt()
88 | {
89 | // Arrange
90 | object input = DBNull.Value;
91 |
92 | // Act
93 | var value = input.GetDbValueForNullableValueType();
94 |
95 | // Assert
96 | Assert.That(value, Is.Null);
97 | }
98 |
99 | [Test]
100 | public void ShouldReturnCorrectValueWhenValueIsNotDbNullAndTypeIsBool()
101 | {
102 | // Arrange
103 | object input = true;
104 |
105 | // Act
106 | var value = input.GetDbValueForNullableValueType();
107 |
108 | // Assert
109 | Assert.That(value, Is.True.And.TypeOf());
110 | }
111 |
112 | [Test]
113 | public void ShouldReturnDefaultValueWhenValueIsDbNullAndTypeIsBool()
114 | {
115 | // Arrange
116 | object input = DBNull.Value;
117 |
118 | // Act
119 | var value = input.GetDbValueForNullableValueType();
120 |
121 | // Assert
122 | Assert.That(value, Is.Null);
123 | }
124 | }
125 |
126 | [TestFixture]
127 | internal class GetDbValueOrNullForReferenceType
128 | {
129 | [Test]
130 | public void ShouldReturnCorrectValueWhenValueIsNotDbNullAndTypeIsInt()
131 | {
132 | // Arrange
133 | object input = "test";
134 |
135 | // Act
136 | var value = input.GetDbValueOrNullForReferenceType();
137 |
138 | // Assert
139 | Assert.That(value, Is.EqualTo("test").And.TypeOf());
140 | }
141 |
142 | [Test]
143 | public void ShouldReturnDefaultValueWhenValueIsDbNullAndTypeIsInt()
144 | {
145 | // Arrange
146 | object input = DBNull.Value;
147 |
148 | // Act
149 | var value = input.GetDbValueOrNullForReferenceType();
150 |
151 | // Assert
152 | Assert.That(value, Is.Null);
153 | }
154 | }
155 | }
156 | }
157 |
--------------------------------------------------------------------------------
/Source/Mirabeau.MsSql.Library.UnitTests/ExpectedSqlQuery.txt:
--------------------------------------------------------------------------------
1 | declare @value1 Int = 0
2 | declare @value2 NVarChar(11) = N'hello world'
3 | declare @value3 NVarChar = null
4 | declare @value4 Decimal = 123.456
5 | declare @value5 Bit = 1
6 | declare @value6 Decimal(10,2) = 321.12
7 | declare @value7 DateTime = convert(datetime,'2010-12-31T23:59:59.0000000', 127)
8 | Select * FROM [dbo].[TableX] Where Column1 > @value1 and Column2 = @value2 and Column3 = @value3 and Column4 = @value4 and Column5 = @value5 and Column6 = @value6 and Column7 = @value7
--------------------------------------------------------------------------------
/Source/Mirabeau.MsSql.Library.UnitTests/Mirabeau.MsSql.Library.UnitTests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 9.0.30729
7 | 2.0
8 | {E602608D-DA5D-4430-960A-694D1FD8D2A2}
9 | Library
10 | Properties
11 | Mirabeau.MsSql.Library.UnitTests
12 | Mirabeau.MsSql.Library.UnitTests
13 | v4.5
14 | 512
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 | false
24 |
25 |
26 |
27 |
28 |
29 |
30 | 3.5
31 | publish\
32 | true
33 | Disk
34 | false
35 | Foreground
36 | 7
37 | Days
38 | false
39 | false
40 | true
41 | 0
42 | 1.0.0.%2a
43 | false
44 | false
45 | true
46 |
47 | ..\
48 | true
49 |
50 |
51 | true
52 | full
53 | false
54 | bin\Debug\
55 | DEBUG;TRACE
56 | prompt
57 | 4
58 | false
59 |
60 |
61 | Mirabeau.MsSql.Library.UnitTests.ruleset
62 | false
63 |
64 |
65 | pdbonly
66 | true
67 | bin\Release\
68 | TRACE
69 | prompt
70 | 4
71 | Mirabeau.MsSql.Library.UnitTests.ruleset
72 | true
73 | false
74 |
75 |
76 |
77 | ..\packages\Microsoft.SqlServer.Types.11.0.2\lib\net20\Microsoft.SqlServer.Types.dll
78 | True
79 |
80 |
81 | ..\packages\NUnit.2.6.4\lib\nunit.framework.dll
82 | True
83 |
84 |
85 | ..\packages\RhinoMocks.3.6.1\lib\net\Rhino.Mocks.dll
86 | True
87 |
88 |
89 |
90 | 3.5
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 | True
102 | True
103 | Resources.resx
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 | {b7ef69f5-0582-4c03-b8d0-ade4060ed8fc}
112 | Mirabeau.MsSql.Library
113 |
114 |
115 | {0D304D74-5711-401F-9E23-0485524821E2}
116 | Mirabeau.Sql
117 |
118 |
119 |
120 |
121 | False
122 | .NET Framework 3.5 SP1 Client Profile
123 | false
124 |
125 |
126 | False
127 | .NET Framework 3.5 SP1
128 | true
129 |
130 |
131 | False
132 | Windows Installer 3.1
133 | true
134 |
135 |
136 |
137 |
138 |
139 | Designer
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 | ResXFileCodeGenerator
148 | Resources.Designer.cs
149 |
150 |
151 |
152 |
153 |
160 |
--------------------------------------------------------------------------------
/Source/Mirabeau.MsSql.Library.UnitTests/Mirabeau.MsSql.Library.UnitTests.ruleset:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
--------------------------------------------------------------------------------
/Source/Mirabeau.MsSql.Library.UnitTests/OverrideTests.cs:
--------------------------------------------------------------------------------
1 | using System.Data;
2 | using NUnit.Framework;
3 | using Rhino.Mocks;
4 |
5 | namespace Mirabeau.MsSql.Library.UnitTests
6 | {
7 | [TestFixture]
8 | public class OverrideTests
9 | {
10 | [Test]
11 | public void ShouldUseOverridenIMsSqlHelper()
12 | {
13 | var sqlHelper = MockRepository.GenerateMock();
14 | sqlHelper.Expect(m => m.ExecuteDataSet("x", CommandType.Text, "y")).Repeat.Once();
15 | DatabaseHelper.MsSqlHelper = sqlHelper;
16 |
17 | DatabaseHelper.ExecuteDataSet("x", CommandType.Text, "y");
18 |
19 | sqlHelper.VerifyAllExpectations();
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Source/Mirabeau.MsSql.Library.UnitTests/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("Mirabeau.MsSql.Library.UnitTests")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Mirabeau BV")]
12 | [assembly: AssemblyProduct("Mirabeau.MsSql.Library.UnitTests")]
13 | [assembly: AssemblyCopyright("Copyright © Mirabeau BV 2015")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("d1c4ad8e-2ec7-48d1-8282-9f9cf7df7810")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 | [assembly: CLSCompliant(false)]
--------------------------------------------------------------------------------
/Source/Mirabeau.MsSql.Library.UnitTests/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace Mirabeau.MsSql.Library.UnitTests.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// Returns the cached ResourceManager instance used by this class.
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Mirabeau.MsSql.Library.UnitTests.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// Overrides the current thread's CurrentUICulture property for all
51 | /// resource lookups using this strongly typed resource class.
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 |
63 | ///
64 | /// Looks up a localized string similar to declare @value1 Int = 0
65 | ///declare @value2 NVarChar(11) = N'hello world'
66 | ///Select * FROM [dbo].[TableX] Where Column1 > @value1 and Column2 = @value2.
67 | ///
68 | internal static string ExpectedSqlQuery {
69 | get {
70 | return ResourceManager.GetString("ExpectedSqlQuery", resourceCulture);
71 | }
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/Source/Mirabeau.MsSql.Library.UnitTests/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
121 |
122 | ..\expectedsqlquery.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8
123 |
124 |
--------------------------------------------------------------------------------
/Source/Mirabeau.MsSql.Library.UnitTests/SqlDebugHelperTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Data;
4 | using System.Data.SqlClient;
5 | using System.Diagnostics;
6 | using Microsoft.SqlServer.Types;
7 | using NUnit.Framework;
8 |
9 | namespace Mirabeau.MsSql.Library.UnitTests
10 | {
11 | [TestFixture]
12 | public class SqlDebugHelperTests
13 | {
14 | [SetUp]
15 | public void Setup()
16 | {
17 | SqlDebugHelper.SqlGenerator = new SqlGenerator();
18 | }
19 |
20 | [Test]
21 | public void ShouldCreateExecutableQuery()
22 | {
23 | DateTime dt = new DateTime(2010, 12, 31, 23, 59, 59);
24 | float? nullable = null;
25 | decimal decimalValue = 123.456m;
26 |
27 | string sql =
28 | "Select * FROM [dbo].[TableX] Where Column1 > @value1 and Column2 = @value2 and Column3 = @value3 and Column4 = @value4 and Column5 = @value5 and Column6 = @value6 and Column7 = @value7";
29 |
30 | IList parameters = new List();
31 | parameters.Add(0.CreateSqlParameter("value1"));
32 | parameters.Add("hello world".CreateSqlParameter("value2"));
33 | parameters.Add(nullable.CreateSqlParameter("value3"));
34 | parameters.Add(decimalValue.CreateSqlParameter("value4"));
35 | parameters.Add(true.CreateSqlParameter("value5"));
36 | var sqlParameter = 321.12m.CreateSqlParameter("value6");
37 | sqlParameter.Size = 10;
38 | sqlParameter.Precision = 2;
39 | parameters.Add(sqlParameter);
40 | parameters.Add(dt.CreateSqlParameter("value7", SqlDbType.DateTime));
41 |
42 | string executableSql = SqlDebugHelper.CreateExecutableSqlStatement(sql, parameters);
43 | Trace.WriteLine(executableSql);
44 | }
45 |
46 | [Test]
47 | public void ShouldCreateExecutableStoredProcedure()
48 | {
49 | float? nullable = null;
50 | decimal decimalValue = 123.456m;
51 | string sql = "sp_test";
52 |
53 | IList parameters = new List();
54 | parameters.Add(0.CreateSqlParameter("value1"));
55 | parameters.Add("hello world".CreateSqlParameter("value2"));
56 | parameters.Add(nullable.CreateSqlParameter("value3"));
57 | parameters.Add(decimalValue.CreateSqlParameter("value4"));
58 |
59 |
60 | string executableSql = SqlDebugHelper.CreateExecutableSqlStatement(sql, parameters);
61 | Trace.WriteLine(executableSql);
62 | Assert.That(executableSql,
63 | Is.EqualTo("EXEC sp_test @value1 = 0, @value2 = N'hello world', @value3 = null, @value4 = 123.456"));
64 | }
65 |
66 | [Test]
67 | public void ShouldFormatDatesInIso8601Format()
68 | {
69 | DateTime dt = new DateTime(2015, 12, 31, 23, 59, 10).AddMilliseconds(12345);
70 | var parameter = dt.CreateSqlParameter("param", SqlDbType.DateTime);
71 |
72 | string executableSql = SqlDebugHelper.CreateExecutableSqlStatement("my_sp", parameter);
73 | Trace.WriteLine(executableSql);
74 | Assert.That(executableSql,
75 | Is.EqualTo("EXEC my_sp @param = convert(datetime,'2015-12-31 23:59:22:345', 121)"));
76 | }
77 |
78 | [Test]
79 | public void ShouldNotUseNPrefixForVarchar()
80 | {
81 | var parameter = "test".CreateSqlParameter("param");
82 | parameter.SqlDbType = SqlDbType.VarChar;
83 |
84 | string executableSql = SqlDebugHelper.CreateExecutableSqlStatement("my_sp", parameter);
85 | Trace.WriteLine(executableSql);
86 | Assert.That(executableSql, Is.EqualTo("EXEC my_sp @param = 'test'"));
87 | }
88 |
89 | [Test]
90 | public void ShouldHandleParameterlessQuery()
91 | {
92 | var query = "select * from my_table";
93 | string executableSql = SqlDebugHelper.CreateExecutableSqlStatement(query, CommandType.Text, null);
94 |
95 | Assert.That(executableSql, Is.EqualTo(query));
96 | }
97 |
98 | [Test]
99 | public void ShouldHandleParameterlessStoredProcedure()
100 | {
101 | var query = "my_sp";
102 | string executableSql = SqlDebugHelper.CreateExecutableSqlStatement(query, CommandType.StoredProcedure, null);
103 |
104 | Assert.That(executableSql, Is.EqualTo("EXEC my_sp "));
105 | }
106 |
107 | [Test]
108 | public void ShouldIgnoreNullValuedSqlParameters()
109 | {
110 | var list = new List() { null, null, null };
111 | string sp = SqlDebugHelper.CreateExecutableSqlStatement("sp", list);
112 |
113 | Assert.That(sp, Is.EqualTo("EXEC sp "));
114 | }
115 |
116 | [Test]
117 | public void ShouldThrowExceptionIfSqlIsNull()
118 | {
119 | Assert.That(() => SqlDebugHelper.CreateExecutableSqlStatement(null, null),
120 | Throws.Exception.TypeOf());
121 |
122 | Assert.That(() => SqlDebugHelper.CreateExecutableSqlStatement(null, CommandType.StoredProcedure, null),
123 | Throws.Exception.TypeOf());
124 | }
125 |
126 | [Test]
127 | public void ShouldCreateCustomImplementation()
128 | {
129 | SqlDebugHelper.SqlGenerator = new CustomerGenerator();
130 |
131 | var parameter = "test".CreateSqlParameter("param");
132 | parameter.SqlDbType = SqlDbType.VarChar;
133 |
134 | string executableSql = SqlDebugHelper.CreateExecutableSqlStatement("my_sp", parameter);
135 | Trace.WriteLine(executableSql);
136 | Assert.That(executableSql, Is.EqualTo("EXEC my_sp @param = 'ConstantValue'"));
137 | }
138 |
139 | [Test]
140 | public void ShouldHandleGeometry()
141 | {
142 | var geom = SqlGeometry.Point(52.123, 5.321, 4326).CreateSqlParameter("geom");
143 | var geof = SqlGeography.Point(52.123, 5.321, 4326).CreateSqlParameter("geof");
144 |
145 | IList parameters = new List();
146 | parameters.Add(geom);
147 | parameters.Add(geof);
148 |
149 | var executableSqlStatement = SqlDebugHelper.CreateExecutableSqlStatement("insert into geo VALUES (@geom, @geof)", parameters);
150 | Trace.WriteLine(executableSqlStatement);
151 | }
152 |
153 | class CustomerGenerator : SqlGenerator
154 | {
155 | ///
156 | /// Formats the value of the the sql parameter to text.
157 | ///
158 | ///
159 | ///
160 | ///
161 | protected override string GetParameterValue(SqlParameter sqlParameter)
162 | {
163 | return "'ConstantValue'";
164 | }
165 | }
166 | }
167 | }
168 |
--------------------------------------------------------------------------------
/Source/Mirabeau.MsSql.Library.UnitTests/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Source/Mirabeau.MsSql.Library/GlobalSuppressions.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeroenpot/SqlHelper/a72fed0cc4a3276854fa33b13692806a60140fb4/Source/Mirabeau.MsSql.Library/GlobalSuppressions.cs
--------------------------------------------------------------------------------
/Source/Mirabeau.MsSql.Library/IParameterCache.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Data.Common;
3 | using System.Data.SqlClient;
4 |
5 | namespace Mirabeau.MsSql.Library
6 | {
7 | ///
8 | ///
9 | ///
10 | public interface IParameterCache
11 | {
12 | ///
13 | /// Retrieves the set of SqlParameters appropriate for the stored procedure
14 | ///
15 | /// The connection string.
16 | /// Name of the stored procedure.
17 | ///
18 | IList GetStoredProcedureParameterSet(string connectionString, string storedProcedureName);
19 | ///
20 | /// Retrieves the set of SqlParameters appropriate for the stored procedure
21 | ///
22 | /// The connection string.
23 | /// The connection.
24 | /// Name of the stored procedure.
25 | ///
26 | IList GetStoredProcedureParameterSet(DbTransaction connectionString, DbConnection connection, string storedProcedureName);
27 |
28 | ///
29 | /// Retrieves the set of SqlParameters appropriate for the stored procedure
30 | ///
31 | ///
32 | /// This method will query the database for this information, and then store it in a cache for future requests.
33 | ///
34 | /// A valid SqlTransaction object
35 | /// A valid SqlConnection object
36 | /// The name of the stored procedure
37 | /// A boolean value indicating whether the return value parameter should be included in the results
38 | /// The .
39 | IList GetStoredProcedureParameterSet(DbTransaction connectionString, DbConnection connection, string storedProcedureName, bool includeReturnValueParameter);
40 | }
41 | }
--------------------------------------------------------------------------------
/Source/Mirabeau.MsSql.Library/Mirabeau.MsSql.Library.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {B7EF69F5-0582-4C03-B8D0-ADE4060ED8FC}
8 | Library
9 | Properties
10 | Mirabeau.MsSql.Library
11 | Mirabeau.MsSql.Library
12 | v4.5
13 | 512
14 | ..\
15 | true
16 |
17 |
18 | true
19 | full
20 | false
21 | bin\Debug\
22 | DEBUG;TRACE
23 | prompt
24 | 4
25 | true
26 | bin\Debug\Mirabeau.MsSql.Library.xml
27 | AllRules.ruleset
28 |
29 |
30 | pdbonly
31 | true
32 | bin\Release\
33 | TRACE
34 | prompt
35 | 4
36 |
37 |
38 | true
39 |
40 |
41 | Mirabeau.MsSql.Library.snk
42 |
43 |
44 |
45 | ..\packages\Microsoft.SqlServer.Types.11.0.2\lib\net20\Microsoft.SqlServer.Types.dll
46 | True
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 | {0d304d74-5711-401f-9e23-0485524821e2}
73 | Mirabeau.Sql
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 | This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
85 |
86 |
87 |
88 |
95 |
--------------------------------------------------------------------------------
/Source/Mirabeau.MsSql.Library/Mirabeau.MsSql.Library.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | MsSqlHelper
5 | $version$
6 | MsSqlHelper
7 | Jeroen Pot,Dorus Verhoeckx,Sander Kinds
8 | $author$
9 | https://github.com/jeroenpot/Mirabeau-Sql-Helper
10 | https://raw.githubusercontent.com/jeroenpot/Mirabeau-Sql-Helper/develop/mssql-icon.png
11 | false
12 |
13 | Static helper class for performing MS SQL operations.
14 | Based on the Microsoft .NET Data Access Application Block v2.0.
15 |
16 | Copyright 2015
17 | SqlHelper,Sql Server,DatabaseHelper,SqlServer,SQL,MsSqlHelper
18 |
19 |
--------------------------------------------------------------------------------
/Source/Mirabeau.MsSql.Library/Mirabeau.MsSql.Library.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeroenpot/SqlHelper/a72fed0cc4a3276854fa33b13692806a60140fb4/Source/Mirabeau.MsSql.Library/Mirabeau.MsSql.Library.snk
--------------------------------------------------------------------------------
/Source/Mirabeau.MsSql.Library/ParameterCache.cs:
--------------------------------------------------------------------------------
1 | // ===============================================================================
2 | // Microsoft Data Access Application Block for .NET
3 | // http://msdn.microsoft.com/library/en-us/dnbda/html/daab-rm.asp
4 | //
5 | // SQLHelper.cs
6 | //
7 | // This file contains the implementations of the SqlHelper and SqlHelperParameterCache
8 | // classes.
9 | //
10 | // For more information see the Data Access Application Block Implementation Overview.
11 | // ===============================================================================
12 | // Release history
13 | // VERSION DESCRIPTION
14 | // 2.0 Added support for FillDataSet, UpdateDataSet and "Param" helper methods
15 | //
16 | // ===============================================================================
17 | // Copyright (C) 2000-2001 Microsoft Corporation
18 | // All rights reserved.
19 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
20 | // OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
21 | // LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR
22 | // FITNESS FOR A PARTICULAR PURPOSE.
23 | // ==============================================================================
24 |
25 | using System;
26 | using System.Collections.Concurrent;
27 | using System.Collections.Generic;
28 | using System.Data;
29 | using System.Data.Common;
30 | using System.Data.SqlClient;
31 | using System.Diagnostics.CodeAnalysis;
32 |
33 | using Mirabeau.Sql;
34 |
35 | namespace Mirabeau.MsSql.Library
36 | {
37 | ///
38 | /// SqlHelperParameterCache provides functions to leverage a static cache of procedure parameters, and the
39 | /// ability to discover parameters for stored procedures at run-time.
40 | ///
41 | internal class ParameterCache : IParameterCache
42 | {
43 | #region private methods, variables, and constructors
44 |
45 | private static readonly ConcurrentDictionary> ParamCache = new ConcurrentDictionary>();
46 |
47 | ///
48 | /// Resolve at run time the appropriate set of DbParameters for a stored procedure
49 | ///
50 | /// A valid SqlTransaction object
51 | /// A valid SqlConnection object
52 | /// The name of the stored procedure
53 | /// Whether or not to include their return value parameter
54 | /// The parameter array discovered.
55 | private static IList DiscoverSpParameterSet(DbTransaction transaction, DbConnection connection, string storedProcedureName, bool includeReturnValueParameter)
56 | {
57 | using (SqlCommand cmd = new SqlCommand(storedProcedureName, connection as SqlConnection))
58 | {
59 | if (connection.State != ConnectionState.Open)
60 | {
61 | connection.Open();
62 | }
63 |
64 | cmd.CommandType = CommandType.StoredProcedure;
65 | if (transaction != null)
66 | {
67 | cmd.Transaction = transaction as SqlTransaction;
68 | }
69 |
70 | SqlCommandBuilder.DeriveParameters(cmd);
71 |
72 | if (!includeReturnValueParameter)
73 | {
74 | cmd.Parameters.RemoveAt(0);
75 | }
76 |
77 | SqlParameter[] discoveredParameters = new SqlParameter[cmd.Parameters.Count];
78 |
79 | cmd.Parameters.CopyTo(discoveredParameters, 0);
80 |
81 | return discoveredParameters;
82 | }
83 | }
84 |
85 | ///
86 | /// Deep copy of cached DbParameter array
87 | ///
88 | /// The original parameters.
89 | /// The .
90 | private static IList CloneParameters(IList originalParameters)
91 | {
92 | SqlParameter[] clonedParameters = new SqlParameter[originalParameters.Count];
93 |
94 | for (int i = 0; i < originalParameters.Count; i++)
95 | {
96 | clonedParameters[i] = (SqlParameter)((ICloneable)originalParameters[i]).Clone();
97 | }
98 |
99 | return clonedParameters;
100 | }
101 |
102 | #endregion private methods, variables, and constructors
103 |
104 | #region Parameter Discovery Functions
105 |
106 | ///
107 | /// Retrieves the set of DbParameters appropriate for the stored procedure.
108 | ///
109 | ///
110 | /// This method will query the database for this information, and then store it in a cache for future requests.
111 | ///
112 | /// A valid connection string for a SqlConnection
113 | /// The name of the stored procedure
114 | /// The .
115 | [SuppressMessage("Microsoft.Reliability", "CA2000:DisposeObjectsBeforeLosingScope")]
116 | public IList GetStoredProcedureParameterSet(string connectionString, string storedProcdureName)
117 | {
118 | using (SqlConnection connection = new SqlConnection(connectionString))
119 | {
120 | return GetStoredProcedureParameterSet(null, connection, storedProcdureName, false);
121 | }
122 | }
123 |
124 | ///
125 | /// Retrieves the set of DbParameters appropriate for the stored procedure.
126 | ///
127 | /// A valid SqlTransaction object
128 | /// A valid SqlConnection object
129 | /// The name of the stored procedure
130 | /// The .
131 | public IList GetStoredProcedureParameterSet(DbTransaction connectionString, DbConnection connection, string storedProcedureName)
132 | {
133 | return GetStoredProcedureParameterSet(connectionString, connection, storedProcedureName, false);
134 | }
135 |
136 | ///
137 | /// Retrieves the set of DbParameters appropriate for the stored procedure.
138 | ///
139 | ///
140 | /// This method will query the database for this information, and then store it in a cache for future requests.
141 | ///
142 | /// A valid SqlTransaction object
143 | /// A valid SqlConnection object
144 | /// The name of the stored procedure
145 | /// A boolean value indicating whether the return value parameter should be included in the results
146 | /// The .
147 | public IList GetStoredProcedureParameterSet(DbTransaction connectionString, DbConnection connection, string storedProcedureName, bool includeReturnValueParameter)
148 | {
149 | if (connection == null)
150 | {
151 | throw new ArgumentNullException("connection", String_Resources.CannotbeNull);
152 | }
153 |
154 | if (string.IsNullOrEmpty(storedProcedureName))
155 | {
156 | throw new ArgumentException(String_Resources.CannotbeNullOrEmpty, "storedProcedureName");
157 | }
158 |
159 | string hashKey = connection.ConnectionString + ":" + storedProcedureName +
160 | (includeReturnValueParameter ? ":include ReturnValue Parameter" : "");
161 |
162 | IList cachedParameters = null;
163 | if (ParamCache.ContainsKey(hashKey))
164 | {
165 | cachedParameters = ParamCache[hashKey];
166 | }
167 |
168 | if (cachedParameters == null)
169 | {
170 | var parameterSet = DiscoverSpParameterSet(connectionString, connection, storedProcedureName, includeReturnValueParameter);
171 | cachedParameters = parameterSet;
172 | ParamCache[hashKey] = parameterSet;
173 | }
174 |
175 | return CloneParameters(cachedParameters);
176 | }
177 |
178 | #endregion Parameter Discovery Functions
179 |
180 | }
181 | }
--------------------------------------------------------------------------------
/Source/Mirabeau.MsSql.Library/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection;
3 | using System.Resources;
4 | using System.Runtime.CompilerServices;
5 | using System.Runtime.InteropServices;
6 |
7 | // General Information about an assembly is controlled through the following
8 | // set of attributes. Change these attribute values to modify the information
9 | // associated with an assembly.
10 | [assembly: AssemblyTitle("Mirabeau.MsSql.Library")]
11 | [assembly: AssemblyDescription("")]
12 | [assembly: AssemblyConfiguration("")]
13 | [assembly: AssemblyCompany("Mirabeau")]
14 | [assembly: AssemblyProduct("Mirabeau.MsSql.Library")]
15 | [assembly: AssemblyCopyright("Copyright © Mirabeau BV 2015")]
16 | [assembly: AssemblyTrademark("")]
17 | [assembly: AssemblyCulture("")]
18 |
19 | // Setting ComVisible to false makes the types in this assembly not visible
20 | // to COM components. If you need to access a type in this assembly from
21 | // COM, set the ComVisible attribute to true on that type.
22 | [assembly: ComVisible(false)]
23 |
24 | // The following GUID is for the ID of the typelib if this project is exposed to COM
25 | [assembly: Guid("8fc3e744-ae9d-4c62-92ab-db2e37093597")]
26 |
27 | // Version information for an assembly consists of the following four values:
28 | //
29 | // Major Version
30 | // Minor Version
31 | // Build Number
32 | // Revision
33 | //
34 | // You can specify all the values or you can default the Build and Revision Numbers
35 | // by using the '*' as shown below:
36 | // [assembly: AssemblyVersion("1.0.*")]
37 | [assembly: AssemblyVersion("1.0.0.0")]
38 | [assembly: AssemblyFileVersion("1.0.0.0")]
39 | [assembly: CLSCompliant(true)]
40 | [assembly: NeutralResourcesLanguage("")]
--------------------------------------------------------------------------------
/Source/Mirabeau.MsSql.Library/SqlDebugHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Data;
4 | using System.Data.SqlClient;
5 |
6 | namespace Mirabeau.MsSql.Library
7 | {
8 | ///
9 | /// Helper class to create sql statements with parameter declaration and values.
10 | ///
11 | public static class SqlDebugHelper
12 | {
13 | ///
14 | /// The object that creates the SQL statements. You can override this class and implement your own if you're having issues with the generated SQL.
15 | ///
16 | public static SqlGenerator SqlGenerator = new SqlGenerator();
17 |
18 | ///
19 | /// Creates a SQL-string with the parameter declaration and the sql statement so it can be executed in Sql Server Management studio.
20 | ///
21 | /// The sql-query
22 | /// The SqlParameters used for the sql-statement
23 | ///
24 | public static string CreateExecutableSqlStatement(string sql, params SqlParameter[] parameters)
25 | {
26 | if (sql == null)
27 | {
28 | throw new ArgumentNullException("sql");
29 | }
30 | return CreateExecutableSqlStatement(sql, SqlGenerator.GetCommandType(sql), parameters);
31 | }
32 |
33 | ///
34 | /// Creates a SQL-string with the parameter declaration and the sql statement so it can be executed in Sql Server Management studio.
35 | ///
36 | /// The sql-query
37 | /// The SqlParameters used for the sql-statement
38 | ///
39 | public static string CreateExecutableSqlStatement(string sql, IList parameters)
40 | {
41 | var sqlParameters = SqlGenerator.ConvertToParams(parameters);
42 | return CreateExecutableSqlStatement(sql, sqlParameters);
43 | }
44 |
45 | ///
46 | /// Creates a SQL-string with the parameter declaration and the sql statement so it can be executed in Sql Server Management studio.
47 | ///
48 | /// The sql-query
49 | /// The . Only StoredProcedure and Text are supported.
50 | /// The SqlParameters used for the sql-statement
51 | ///
52 | public static string CreateExecutableSqlStatement(string sql, CommandType commandType, IList parameters)
53 | {
54 | var param = SqlGenerator.ConvertToParams(parameters);
55 | return SqlGenerator.CreateExecutableSqlStatement(sql, commandType, param);
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/Source/Mirabeau.MsSql.Library/SqlParameterFactory.cs:
--------------------------------------------------------------------------------
1 | using System.Data.SqlClient;
2 |
3 | using Mirabeau.Sql;
4 |
5 | namespace Mirabeau.MsSql.Library
6 | {
7 | ///
8 | /// Factory for creating Sql Parameters.
9 | ///
10 | public class SqlParameterFactory : ParameterFactory
11 | {
12 | ///
13 | /// Creates the parameter.
14 | ///
15 | ///
16 | internal override SqlParameter CreateParameter()
17 | {
18 | return new SqlParameter();
19 | }
20 | }
21 | }
--------------------------------------------------------------------------------
/Source/Mirabeau.MsSql.Library/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Source/Mirabeau.MySql.Library.IntegrationTests/DatabaseExecutionTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Data;
4 | using System.Data.Common;
5 | using AutoMapper;
6 | using MySql.Data.MySqlClient;
7 | using NUnit.Framework;
8 |
9 | namespace Mirabeau.MySql.Library.IntegrationTests
10 | {
11 | [TestFixture, Explicit("Requires MYSQL database.")]
12 | public class DatabaseExecutionTests
13 | {
14 | readonly IMySqlHelper _mySqlHelper = new MySqlHelper();
15 | private const string Email = "email@servername.net";
16 |
17 | private const string ConnectionString = "server=x;uid=uid;pwd=pwd;database=db;";
18 |
19 | [TestFixtureSetUp]
20 | public void Setup()
21 | {
22 | _mySqlHelper.ExecuteNonQuery(ConnectionString, CommandType.Text, Properties.Resources.CreateTable);
23 |
24 | Mapper.CreateMap();
25 | }
26 |
27 | [Test]
28 | public void ShouldInsertIntoTable()
29 | {
30 | IList parameters = new List();
31 | parameters.Add("my firstname".CreateMySqlParameter("firstname"));
32 | parameters.Add("my lastname".CreateMySqlParameter("lastname"));
33 | parameters.Add(Email.CreateMySqlParameter("email"));
34 | parameters.Add(DateTime.Now.CreateMySqlParameter("regdate", MySqlDbType.DateTime));
35 |
36 | _mySqlHelper.ExecuteNonQuery(ConnectionString, CommandType.Text, Properties.Resources.InsertIntoTable, parameters);
37 |
38 | using (DbDataReader dataReader = _mySqlHelper.ExecuteReader(ConnectionString, CommandType.Text, "SELECT * FROM tmp_unittest_table"))
39 | {
40 | List rows = Mapper.Map>(dataReader);
41 |
42 | Assert.That(rows, Has.Count.EqualTo(1));
43 | }
44 |
45 | _mySqlHelper.ExecuteNonQuery(ConnectionString, CommandType.Text, Properties.Resources.CreateProcedure);
46 |
47 | MySqlParameter emailParameter = Email.CreateMySqlParameter("emailaddress");
48 |
49 | using (DbDataReader dataReader = _mySqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure, "GetByEmail", emailParameter))
50 | {
51 | List rows = Mapper.Map>(dataReader);
52 | Assert.That(rows, Has.Count.EqualTo(1));
53 | }
54 | }
55 |
56 | [TestFixtureTearDown]
57 | public void TestFixtureTearDown()
58 | {
59 | _mySqlHelper.ExecuteNonQuery(ConnectionString, CommandType.Text, "DROP TABLE tmp_unittest_table");
60 | _mySqlHelper.ExecuteNonQuery(ConnectionString, CommandType.Text, "DROP PROCEDURE GetByEmail");
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/Source/Mirabeau.MySql.Library.IntegrationTests/Mirabeau.MySql.Library.IntegrationTests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {589BA55B-D937-41CF-97D2-1B6CB23E7437}
8 | Library
9 | Properties
10 | Mirabeau.MySql.Library.IntegrationTests
11 | Mirabeau.MySql.Library.IntegrationTests
12 | v4.5
13 | 512
14 | ..\
15 | true
16 |
17 |
18 | true
19 | full
20 | false
21 | bin\Debug\
22 | DEBUG;TRACE
23 | prompt
24 | 4
25 | Mirabeau.MySql.Library.IntegrationTests.ruleset
26 |
27 |
28 | pdbonly
29 | true
30 | bin\Release\
31 | TRACE
32 | prompt
33 | 4
34 | Mirabeau.MySql.Library.IntegrationTests.ruleset
35 |
36 |
37 |
38 | ..\packages\AutoMapper.4.0.4\lib\net45\AutoMapper.dll
39 | True
40 |
41 |
42 | ..\packages\MySql.Data.6.7.8\lib\net45\MySql.Data.dll
43 | True
44 |
45 |
46 | ..\packages\NUnit.2.6.4\lib\nunit.framework.dll
47 | True
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 | True
62 | True
63 | Resources.resx
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 | {aaded218-6603-4ed4-8bba-0f994cc62286}
76 | Mirabeau.MySql.Library
77 |
78 |
79 | {0D304D74-5711-401F-9E23-0485524821E2}
80 | Mirabeau.Sql
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 | ResXFileCodeGenerator
90 | Resources.Designer.cs
91 |
92 |
93 |
94 |
95 |
96 |
97 | This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
98 |
99 |
100 |
101 |
108 |
--------------------------------------------------------------------------------
/Source/Mirabeau.MySql.Library.IntegrationTests/Mirabeau.MySql.Library.IntegrationTests.ruleset:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
--------------------------------------------------------------------------------
/Source/Mirabeau.MySql.Library.IntegrationTests/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("Mirabeau.MySql.Library.IntegrationTests")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Mirabeau")]
12 | [assembly: AssemblyProduct("Mirabeau.MySql.Library.IntegrationTests")]
13 | [assembly: AssemblyCopyright("Copyright © Mirabeau BV 2015")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("2fccf9fd-1328-44ec-9703-e227ccbe29f7")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/Source/Mirabeau.MySql.Library.IntegrationTests/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.34209
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace Mirabeau.MySql.Library.IntegrationTests.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// Returns the cached ResourceManager instance used by this class.
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Mirabeau.MySql.Library.IntegrationTests.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// Overrides the current thread's CurrentUICulture property for all
51 | /// resource lookups using this strongly typed resource class.
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 |
63 | ///
64 | /// Looks up a localized string similar to CREATE PROCEDURE GetByEmail(IN emailaddress VARCHAR(100))
65 | /// BEGIN
66 | /// SELECT *
67 | /// FROM tmp_unittest_table
68 | /// WHERE email = emailaddress;
69 | /// END.
70 | ///
71 | internal static string CreateProcedure {
72 | get {
73 | return ResourceManager.GetString("CreateProcedure", resourceCulture);
74 | }
75 | }
76 |
77 | ///
78 | /// Looks up a localized string similar to CREATE TABLE IF NOT EXISTS tmp_unittest_table (
79 | ///id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
80 | ///firstname VARCHAR(30) NOT NULL,
81 | ///lastname VARCHAR(30) NOT NULL,
82 | ///email VARCHAR(100),
83 | ///registrationdate TIMESTAMP
84 | ///).
85 | ///
86 | internal static string CreateTable {
87 | get {
88 | return ResourceManager.GetString("CreateTable", resourceCulture);
89 | }
90 | }
91 |
92 | ///
93 | /// Looks up a localized string similar to insert into tmp_unittest_table
94 | ///(
95 | /// firstname
96 | ///, lastname
97 | ///, email
98 | ///, registrationdate
99 | ///)
100 | ///values
101 | ///(
102 | /// @firstname
103 | ///, @lastname
104 | ///, @email
105 | ///, @regdate
106 | ///).
107 | ///
108 | internal static string InsertIntoTable {
109 | get {
110 | return ResourceManager.GetString("InsertIntoTable", resourceCulture);
111 | }
112 | }
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/Source/Mirabeau.MySql.Library.IntegrationTests/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
121 |
122 | ..\sqlscripts\createprocedure.sql;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8
123 |
124 |
125 | ..\sqlscripts\createtable.sql;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8
126 |
127 |
128 | ..\sqlscripts\insertintotable.sql;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8
129 |
130 |
--------------------------------------------------------------------------------
/Source/Mirabeau.MySql.Library.IntegrationTests/SqlScripts/CreateProcedure.sql:
--------------------------------------------------------------------------------
1 | CREATE PROCEDURE GetByEmail(IN emailaddress VARCHAR(100))
2 | BEGIN
3 | SELECT *
4 | FROM tmp_unittest_table
5 | WHERE email = emailaddress;
6 | END
--------------------------------------------------------------------------------
/Source/Mirabeau.MySql.Library.IntegrationTests/SqlScripts/CreateTable.sql:
--------------------------------------------------------------------------------
1 | CREATE TABLE IF NOT EXISTS tmp_unittest_table (
2 | id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
3 | firstname VARCHAR(30) NOT NULL,
4 | lastname VARCHAR(30) NOT NULL,
5 | email VARCHAR(100),
6 | registrationdate TIMESTAMP
7 | )
--------------------------------------------------------------------------------
/Source/Mirabeau.MySql.Library.IntegrationTests/SqlScripts/InsertIntoTable.sql:
--------------------------------------------------------------------------------
1 | insert into tmp_unittest_table
2 | (
3 | firstname
4 | , lastname
5 | , email
6 | , registrationdate
7 | )
8 | values
9 | (
10 | @firstname
11 | , @lastname
12 | , @email
13 | , @regdate
14 | )
--------------------------------------------------------------------------------
/Source/Mirabeau.MySql.Library.IntegrationTests/TempTable.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Mirabeau.MySql.Library.IntegrationTests
4 | {
5 | public class TempTable
6 | {
7 | public int Id { get; set; }
8 | public string Firstname { get; set; }
9 | public string Lastname { get; set; }
10 | public string Email { get; set; }
11 | public DateTime RegistrationDate { get; set; }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/Source/Mirabeau.MySql.Library.IntegrationTests/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Source/Mirabeau.MySql.Library.IntegrationTests/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Source/Mirabeau.MySql.Library.UnitTests/Mirabeau.MySql.Library.UnitTests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {67477434-4E6E-46C5-811A-249A321914A2}
8 | Library
9 | Properties
10 | Mirabeau.MySql.Library.UnitTests
11 | Mirabeau.MySql.Library.UnitTests
12 | v4.5
13 | 512
14 | ..\
15 | true
16 |
17 |
18 | true
19 | full
20 | false
21 | bin\Debug\
22 | DEBUG;TRACE
23 | prompt
24 | 4
25 | Mirabeau.MySql.Library.UnitTests.ruleset
26 |
27 |
28 | pdbonly
29 | true
30 | bin\Release\
31 | TRACE
32 | prompt
33 | 4
34 | Mirabeau.MySql.Library.UnitTests.ruleset
35 |
36 |
37 |
38 | ..\packages\MySql.Data.6.7.8\lib\net45\MySql.Data.dll
39 | True
40 |
41 |
42 | ..\packages\NUnit.2.6.4\lib\nunit.framework.dll
43 | True
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 | {AADED218-6603-4ED4-8BBA-0F994CC62286}
66 | Mirabeau.MySql.Library
67 |
68 |
69 | {0D304D74-5711-401F-9E23-0485524821E2}
70 | Mirabeau.Sql
71 |
72 |
73 |
74 |
75 |
76 |
77 | This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
78 |
79 |
80 |
81 |
88 |
--------------------------------------------------------------------------------
/Source/Mirabeau.MySql.Library.UnitTests/Mirabeau.MySql.Library.UnitTests.ruleset:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
--------------------------------------------------------------------------------
/Source/Mirabeau.MySql.Library.UnitTests/MySqlParameterExtensionsTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using MySql.Data.MySqlClient;
3 | using NUnit.Framework;
4 |
5 | namespace Mirabeau.MySql.Library.UnitTests
6 | {
7 | [TestFixture]
8 | public class MySqlParameterExtensionsTests
9 | {
10 | [Test]
11 | public void ShouldCreateMyParameterNotNullabeParameterForString()
12 | {
13 | MySqlParameter mySqlParameter = "aBc".CreateMySqlParameter("param1");
14 |
15 | Assert.That(mySqlParameter.ParameterName, Is.EqualTo("param1"));
16 | Assert.That(mySqlParameter.Value, Is.EqualTo("aBc"));
17 | Assert.That(mySqlParameter.MySqlDbType, Is.EqualTo(MySqlDbType.VarChar));
18 | }
19 |
20 | [Test]
21 | public void ShouldCreateMyParameterNotNullabeParameterForInt()
22 | {
23 | int value = 1;
24 | MySqlParameter mySqlParameter = value.CreateMySqlParameter("param1");
25 |
26 | Assert.That(mySqlParameter.ParameterName, Is.EqualTo("param1"));
27 | Assert.That(mySqlParameter.Value, Is.EqualTo(value));
28 | Assert.That(mySqlParameter.MySqlDbType, Is.EqualTo(MySqlDbType.Int32));
29 | }
30 |
31 | [Test]
32 | public void ShouldCreateMyParameterNotNullabeParameterForLong()
33 | {
34 | long value = 1;
35 | MySqlParameter mySqlParameter = value.CreateMySqlParameter("param1");
36 |
37 | Assert.That(mySqlParameter.ParameterName, Is.EqualTo("param1"));
38 | Assert.That(mySqlParameter.Value, Is.EqualTo(value));
39 | Assert.That(mySqlParameter.MySqlDbType, Is.EqualTo(MySqlDbType.Int64));
40 | }
41 |
42 | [Test]
43 | public void ShouldCreateMyParameterNotNullabeParameterForDecimal()
44 | {
45 | decimal value = 1.2m;
46 | MySqlParameter mySqlParameter = value.CreateMySqlParameter("param1");
47 |
48 | Assert.That(mySqlParameter.ParameterName, Is.EqualTo("param1"));
49 | Assert.That(mySqlParameter.Value, Is.EqualTo(value));
50 | Assert.That(mySqlParameter.MySqlDbType, Is.EqualTo(MySqlDbType.Decimal));
51 | }
52 |
53 | [Test]
54 | public void ShouldCreateMyParameterNotNullabeParameterForBool()
55 | {
56 | bool value = true;
57 | MySqlParameter mySqlParameter = value.CreateMySqlParameter("param1");
58 |
59 | Assert.That(mySqlParameter.ParameterName, Is.EqualTo("param1"));
60 | Assert.That(mySqlParameter.Value, Is.EqualTo(true));
61 | Assert.That(mySqlParameter.MySqlDbType, Is.EqualTo(MySqlDbType.Byte));
62 | }
63 |
64 | [Test]
65 | public void ShouldCreateMyParameterNullabeParamter()
66 | {
67 | long? value = null;
68 | MySqlParameter mySqlParameter = value.CreateMySqlParameter("param1");
69 |
70 | Assert.That(mySqlParameter.ParameterName, Is.EqualTo("param1"));
71 | Assert.That(mySqlParameter.Value, Is.EqualTo(DBNull.Value));
72 | }
73 |
74 | [TestCase(null)]
75 | [TestCase("")]
76 | [TestCase(" ")]
77 | public void ShouldThrowExceptionForInvalidArgument(string parameter)
78 | {
79 | Assert.That(() => 1.CreateMySqlParameter(parameter), Throws.Exception.TypeOf());
80 | }
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/Source/Mirabeau.MySql.Library.UnitTests/MySqlParameterFactoryTests.cs:
--------------------------------------------------------------------------------
1 | using System.Data;
2 | using MySql.Data.MySqlClient;
3 | using NUnit.Framework;
4 |
5 | namespace Mirabeau.MySql.Library.UnitTests
6 | {
7 | [TestFixture]
8 | public class MySqlParameterFactoryTests
9 | {
10 | private readonly MySqlParameterFactory _factory = new MySqlParameterFactory();
11 |
12 | [Test]
13 | public void ShouldCreateParameter()
14 | {
15 | MySqlParameter mySqlParameter = _factory.CreateParameter(12, "param1", ParameterDirection.InputOutput);
16 |
17 | Assert.That(mySqlParameter.ParameterName, Is.EqualTo("param1"));
18 | Assert.That(mySqlParameter.Value, Is.EqualTo(12));
19 | Assert.That(mySqlParameter.MySqlDbType, Is.EqualTo(MySqlDbType.Int32));
20 | Assert.That(mySqlParameter.Direction, Is.EqualTo(ParameterDirection.InputOutput));
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Source/Mirabeau.MySql.Library.UnitTests/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("Mirabeau.MySql.Library.UnitTests")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("HP")]
12 | [assembly: AssemblyProduct("Mirabeau.MySql.Library.UnitTests")]
13 | [assembly: AssemblyCopyright("Copyright © HP 2015")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("3a1ead88-9513-44d8-a71d-3a35b84c6a52")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/Source/Mirabeau.MySql.Library.UnitTests/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Source/Mirabeau.MySql.Library.UnitTests/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Source/Mirabeau.MySql.Library/GlobalSuppressions.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeroenpot/SqlHelper/a72fed0cc4a3276854fa33b13692806a60140fb4/Source/Mirabeau.MySql.Library/GlobalSuppressions.cs
--------------------------------------------------------------------------------
/Source/Mirabeau.MySql.Library/IMySqlHelper.cs:
--------------------------------------------------------------------------------
1 | using Mirabeau.Sql;
2 |
3 | namespace Mirabeau.MySql.Library
4 | {
5 | ///
6 | /// Interface for the MySql helper.
7 | ///
8 | public interface IMySqlHelper : IDatabaseHelper
9 | {
10 | }
11 | }
--------------------------------------------------------------------------------
/Source/Mirabeau.MySql.Library/Mirabeau.MySql.Library.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {AADED218-6603-4ED4-8BBA-0F994CC62286}
8 | Library
9 | Properties
10 | Mirabeau.MySql.Library
11 | Mirabeau.MySql.Library
12 | v4.5
13 | 512
14 | ..\
15 | true
16 |
17 |
18 | true
19 | full
20 | false
21 | bin\Debug\
22 | DEBUG;TRACE
23 | prompt
24 | 4
25 | true
26 | AllRules.ruleset
27 | bin\Debug\Mirabeau.MySql.Library.XML
28 |
29 |
30 | pdbonly
31 | true
32 | bin\Release\
33 | TRACE
34 | prompt
35 | 4
36 |
37 |
38 | true
39 |
40 |
41 | Mirabeau.MySql.Library.snk
42 |
43 |
44 |
45 | ..\packages\MySql.Data.6.7.8\lib\net45\MySql.Data.dll
46 | True
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 | {0D304D74-5711-401F-9E23-0485524821E2}
68 | Mirabeau.Sql
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 | This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
81 |
82 |
83 |
84 |
91 |
--------------------------------------------------------------------------------
/Source/Mirabeau.MySql.Library/Mirabeau.MySql.Library.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | MySqlHelper
5 | $version$
6 | MySqlHelper
7 | Jeroen Pot
8 | Jeroen Pot
9 | https://github.com/jeroenpot/Mirabeau-Sql-Helper
10 | https://raw.githubusercontent.com/jeroenpot/Mirabeau-Sql-Helper/develop/mysql-icon.png
11 | false
12 |
13 | Static helper class for performing MYSQL operations.
14 | Based on the Microsoft .NET Data Access Application Block v2.0, but now support for MySql database actions.
15 |
16 | Copyright 2015
17 | SqlHelper,MySql, DatabaseHelper, SQL, MySqlHelper
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Source/Mirabeau.MySql.Library/Mirabeau.MySql.Library.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeroenpot/SqlHelper/a72fed0cc4a3276854fa33b13692806a60140fb4/Source/Mirabeau.MySql.Library/Mirabeau.MySql.Library.snk
--------------------------------------------------------------------------------
/Source/Mirabeau.MySql.Library/MySqlHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Data.Common;
3 |
4 | using Mirabeau.Sql;
5 |
6 | using MySql.Data.MySqlClient;
7 |
8 | namespace Mirabeau.MySql.Library
9 | {
10 | ///
11 | /// Helper class for MySql commands.
12 | ///
13 | public class MySqlHelper : DatabaseHelperBase, IMySqlHelper
14 | {
15 | ///
16 | /// Creates a new DbConnection.
17 | ///
18 | /// The connection string to the database.
19 | ///
20 | public override DbConnection CreateConnection(string connectionString)
21 | {
22 | return new MySqlConnection(connectionString);
23 | }
24 |
25 | ///
26 | /// Creates a new DbCommand.
27 | ///
28 | ///
29 | public override DbCommand CreateCommand()
30 | {
31 | return new MySqlCommand();
32 | }
33 |
34 | ///
35 | /// Creates a new DbDataAdapter.
36 | ///
37 | /// the .
38 | ///
39 | public override DbDataAdapter CreateDataAdapter(DbCommand command)
40 | {
41 | return new MySqlDataAdapter(command as MySqlCommand);
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/Source/Mirabeau.MySql.Library/MySqlParameterFactory.cs:
--------------------------------------------------------------------------------
1 | using Mirabeau.Sql;
2 |
3 | using MySql.Data.MySqlClient;
4 |
5 | namespace Mirabeau.MySql.Library
6 | {
7 | ///
8 | /// Factory for creating MySqlParameters.
9 | ///
10 | public class MySqlParameterFactory : ParameterFactory
11 | {
12 | internal override MySqlParameter CreateParameter()
13 | {
14 | return new MySqlParameter();
15 | }
16 | }
17 | }
--------------------------------------------------------------------------------
/Source/Mirabeau.MySql.Library/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection;
3 | using System.Resources;
4 | using System.Runtime.CompilerServices;
5 | using System.Runtime.InteropServices;
6 |
7 | // General Information about an assembly is controlled through the following
8 | // set of attributes. Change these attribute values to modify the information
9 | // associated with an assembly.
10 | [assembly: AssemblyTitle("Mirabeau.MySql.Library")]
11 | [assembly: AssemblyDescription("")]
12 | [assembly: AssemblyConfiguration("")]
13 | [assembly: AssemblyCompany("Mirabeau")]
14 | [assembly: AssemblyProduct("Mirabeau.MySql.Library")]
15 | [assembly: AssemblyCopyright("Copyright © Mirabeau BV 2015")]
16 | [assembly: AssemblyTrademark("")]
17 | [assembly: AssemblyCulture("")]
18 |
19 | // Setting ComVisible to false makes the types in this assembly not visible
20 | // to COM components. If you need to access a type in this assembly from
21 | // COM, set the ComVisible attribute to true on that type.
22 | [assembly: ComVisible(false)]
23 |
24 | // The following GUID is for the ID of the typelib if this project is exposed to COM
25 | [assembly: Guid("acfb823b-2345-4189-a1e3-8df2d8851402")]
26 |
27 | // Version information for an assembly consists of the following four values:
28 | //
29 | // Major Version
30 | // Minor Version
31 | // Build Number
32 | // Revision
33 | //
34 | // You can specify all the values or you can default the Build and Revision Numbers
35 | // by using the '*' as shown below:
36 | // [assembly: AssemblyVersion("1.0.*")]
37 | [assembly: AssemblyVersion("1.0.0.0")]
38 | [assembly: AssemblyFileVersion("1.0.0.0")]
39 | [assembly: CLSCompliant(false)]
40 | [assembly: NeutralResourcesLanguage("")]
--------------------------------------------------------------------------------
/Source/Mirabeau.MySql.Library/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Source/Mirabeau.MySql.Library/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Source/Mirabeau.Sql/DbDataReaderHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Mirabeau.Sql
4 | {
5 | ///
6 | /// Helper for the DatabaseDataReader object.
7 | ///
8 | public static class DbDataReaderHelper
9 | {
10 | ///
11 | /// Return a non nullable value of type <T>
12 | ///
13 | /// The value.
14 | /// The type.
15 | public static T GetDbValueOrDefaultForValueType(this object theValue) where T : struct
16 | {
17 | if (theValue is DBNull)
18 | {
19 | return default(T);
20 | }
21 |
22 | return (T)theValue;
23 | }
24 |
25 | ///
26 | /// Return a nullable value of type <T>
27 | ///
28 | /// The value.
29 | /// The type.
30 | public static T? GetDbValueForNullableValueType(this object theValue) where T : struct
31 | {
32 | if (theValue == DBNull.Value)
33 | {
34 | return null;
35 | }
36 |
37 | return (T?)theValue;
38 | }
39 |
40 | ///
41 | /// Return a nullable value of type <T>
42 | ///
43 | /// The value.
44 | /// The type.
45 | public static T GetDbValueOrNullForReferenceType(this object theValue) where T : class
46 | {
47 | if (theValue is DBNull)
48 | {
49 | return null;
50 | }
51 |
52 | return (T)theValue;
53 | }
54 | }
55 | }
--------------------------------------------------------------------------------
/Source/Mirabeau.Sql/GlobalSuppressions.cs:
--------------------------------------------------------------------------------
1 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2100:Review SQL queries for security vulnerabilities", Scope = "member", Target = "Mirabeau.Sql.Library.DatabaseHelperBase.#PrepareCommand(System.Data.Common.DbCommand,System.Data.Common.DbConnection,System.Data.Common.DbTransaction,System.Data.CommandType,System.String,System.Collections.Generic.IEnumerable`1)")]
2 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Scope = "member", Target = "Mirabeau.Sql.Library.DatabaseHelperBase.#ExecuteDataSet(System.Data.Common.DbTransaction,System.Data.CommandType,System.String,System.Collections.Generic.IEnumerable`1)")]
3 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Scope = "member", Target = "Mirabeau.Sql.Library.DatabaseHelperBase.#ExecuteDataSet(System.Data.Common.DbConnection,System.Data.CommandType,System.String,System.Collections.Generic.IEnumerable`1)")]
4 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Scope = "member", Target = "Mirabeau.Sql.Library.DatabaseHelperBase.#ExecuteDataSet`1(System.Data.Common.DbConnection,System.Data.CommandType,System.String,System.Collections.Generic.IEnumerable`1)")]
5 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Scope = "member", Target = "Mirabeau.Sql.Library.DatabaseHelperBase.#ExecuteDataSet`1(System.Data.Common.DbTransaction,System.Data.CommandType,System.String,System.Collections.Generic.IEnumerable`1)")]
6 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Scope = "member", Target = "Mirabeau.Sql.DatabaseHelperBase.#ExecuteDataSet`1(System.Data.Common.DbConnection,System.Data.CommandType,System.String,System.Collections.Generic.IEnumerable`1)")]
7 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Scope = "member", Target = "Mirabeau.Sql.DatabaseHelperBase.#ExecuteDataSet`1(System.Data.Common.DbTransaction,System.Data.CommandType,System.String,System.Collections.Generic.IEnumerable`1)")]
8 |
--------------------------------------------------------------------------------
/Source/Mirabeau.Sql/Mirabeau.Sql.Library.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeroenpot/SqlHelper/a72fed0cc4a3276854fa33b13692806a60140fb4/Source/Mirabeau.Sql/Mirabeau.Sql.Library.snk
--------------------------------------------------------------------------------
/Source/Mirabeau.Sql/Mirabeau.Sql.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 9.0.30729
7 | 2.0
8 | {0D304D74-5711-401F-9E23-0485524821E2}
9 | Library
10 | Properties
11 | Mirabeau.Sql
12 | Mirabeau.Sql
13 | v4.5
14 | 512
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 | true
24 | Mirabeau.Sql.Library.snk
25 |
26 |
27 |
28 |
29 | 3.5
30 | publish\
31 | true
32 | Disk
33 | false
34 | Foreground
35 | 7
36 | Days
37 | false
38 | false
39 | true
40 | 0
41 | 1.0.0.%2a
42 | false
43 | false
44 | true
45 |
46 |
47 |
48 | true
49 | full
50 | false
51 | bin\Debug\
52 | DEBUG;TRACE
53 | prompt
54 | 4
55 | true
56 | bin\Debug\Mirabeau.Sql.xml
57 | AllRules.ruleset
58 | false
59 |
60 |
61 | pdbonly
62 | true
63 | bin\Release\
64 | TRACE
65 | prompt
66 | 4
67 | AllRules.ruleset
68 | bin\Release\Mirabeau.Sql.xml
69 | true
70 | false
71 |
72 |
73 |
74 |
75 |
76 | 3.5
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 | String.Resources.resx
90 | True
91 | True
92 |
93 |
94 |
95 |
96 |
97 |
98 | ResXFileCodeGenerator
99 | String.Resources.Designer.cs
100 | Designer
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 | False
109 | .NET Framework 3.5 SP1 Client Profile
110 | false
111 |
112 |
113 | False
114 | .NET Framework 3.5 SP1
115 | true
116 |
117 |
118 | False
119 | Windows Installer 3.1
120 | true
121 |
122 |
123 |
124 |
131 |
--------------------------------------------------------------------------------
/Source/Mirabeau.Sql/ParameterFactory.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Data;
3 | using System.Data.Common;
4 |
5 | namespace Mirabeau.Sql
6 | {
7 | ///
8 | /// Factory for creating s.
9 | ///
10 | /// The type of .
11 | public abstract class ParameterFactory where T : DbParameter
12 | {
13 | internal abstract T CreateParameter();
14 |
15 | ///
16 | /// Creates the parameter.
17 | ///
18 | /// The value.
19 | /// Name of the parameter.
20 | /// The direction of the parameter.
21 | ///
22 | public T CreateParameter(object theValue, string parameterName, ParameterDirection direction)
23 | {
24 | ValidateParameter(parameterName);
25 |
26 | object valueToUse = theValue;
27 |
28 | if (theValue == null)
29 | {
30 | valueToUse = DBNull.Value;
31 | }
32 |
33 | T parameter = CreateParameter();
34 | parameter.ParameterName = parameterName;
35 | parameter.Value = valueToUse;
36 | parameter.Direction = direction;
37 |
38 | return parameter;
39 | }
40 |
41 | // ReSharper disable once UnusedParameter.Local
42 | private static void ValidateParameter(string parameterName)
43 | {
44 | if (string.IsNullOrWhiteSpace(parameterName))
45 | {
46 | throw new ArgumentException(String_Resources.CannotbeNullOrEmpty, "parameterName");
47 | }
48 | }
49 | }
50 | }
--------------------------------------------------------------------------------
/Source/Mirabeau.Sql/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection;
3 | using System.Resources;
4 | using System.Runtime.CompilerServices;
5 | using System.Runtime.InteropServices;
6 |
7 | // General Information about an assembly is controlled through the following
8 | // set of attributes. Change these attribute values to modify the information
9 | // associated with an assembly.
10 | [assembly: AssemblyTitle("Mirabeau.Sql")]
11 | [assembly: AssemblyDescription("")]
12 | [assembly: AssemblyConfiguration("")]
13 | [assembly: AssemblyCompany("Mirabeau BV")]
14 | [assembly: AssemblyProduct("Mirabeau.Sql")]
15 | [assembly: AssemblyCopyright("Copyright © Mirabeau BV 2015")]
16 | [assembly: AssemblyTrademark("")]
17 | [assembly: AssemblyCulture("")]
18 | [assembly: InternalsVisibleTo("Mirabeau.MsSql.Library, PublicKey=00240000048000009400000006020000002400005253413100040000010001005518300253e09e1480c8150286d1b8998d2fb905ac0f2a97cb482e682d6447ece4a3e6fbfa0eb34b5fb8a5914e61425fbce6ce78ddf610cda22281d48813d247fcef15fb4dbd7b457a5f550c9a7f2213c50093294d9e25e1016ddfcdc505147ab0e0c1fe5a9682b2901a677ecd52ce8c15653f69c82e3a5c83145d32e06bffb7")]
19 | [assembly: InternalsVisibleTo("Mirabeau.MySql.Library, PublicKey=0024000004800000940000000602000000240000525341310004000001000100ed11cadb5fe59c9da8cf0b220755b029dc9af656516a83b46721b68482abfcd99dfc0d4cf4e09b5d712a28d7ab7e656356553533dbacfd358661d6d4a7ed562a8aab399750846065998673835aae2797caddc6c8b8effc11d4556aaff97430b088fee2e73ffbe6da570678f3fa0325522f0f203d48a2e5bbe0be8dd37512a4ab")]
20 |
21 | // Setting ComVisible to false makes the types in this assembly not visible
22 | // to COM components. If you need to access a type in this assembly from
23 | // COM, set the ComVisible attribute to true on that type.
24 | [assembly: ComVisible(false)]
25 |
26 | // The following GUID is for the ID of the typelib if this project is exposed to COM
27 | [assembly: Guid("fcaf4f57-412d-4ba5-9034-3599bce767f6")]
28 |
29 | // Version information for an assembly consists of the following four values:
30 | //
31 | // Major Version
32 | // Minor Version
33 | // Build Number
34 | // Revision
35 | //
36 | // You can specify all the values or you can default the Build and Revision Numbers
37 | // by using the '*' as shown below:
38 | // [assembly: AssemblyVersion("1.0.*")]
39 | [assembly: AssemblyVersion("1.0.0.0")]
40 | [assembly: AssemblyFileVersion("1.0.0.0")]
41 | [assembly: CLSCompliant(true)]
42 | [assembly: NeutralResourcesLanguage("")]
43 |
--------------------------------------------------------------------------------
/Source/Mirabeau.Sql/String.Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.34209
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace Mirabeau.Sql {
12 | using System;
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class String_Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal String_Resources() {
33 | }
34 |
35 | ///
36 | /// Returns the cached ResourceManager instance used by this class.
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Mirabeau.Sql.String.Resources", typeof(String_Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// Overrides the current thread's CurrentUICulture property for all
51 | /// resource lookups using this strongly typed resource class.
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 |
63 | ///
64 | /// Looks up a localized string similar to cannot be null.
65 | ///
66 | internal static string CannotbeNull {
67 | get {
68 | return ResourceManager.GetString("CannotbeNull", resourceCulture);
69 | }
70 | }
71 |
72 | ///
73 | /// Looks up a localized string similar to cannot be null or empty.
74 | ///
75 | internal static string CannotbeNullOrEmpty {
76 | get {
77 | return ResourceManager.GetString("CannotbeNullOrEmpty", resourceCulture);
78 | }
79 | }
80 |
81 | ///
82 | /// Looks up a localized string similar to [Errorcode: {0}] {1}.
83 | ///
84 | internal static string errorCodeFormatString {
85 | get {
86 | return ResourceManager.GetString("errorCodeFormatString", resourceCulture);
87 | }
88 | }
89 |
90 | ///
91 | /// Looks up a localized string similar to No errorcode available for errorcode: {0}..
92 | ///
93 | internal static string NoErrorCodePresent {
94 | get {
95 | return ResourceManager.GetString("NoErrorCodePresent", resourceCulture);
96 | }
97 | }
98 |
99 | ///
100 | /// Looks up a localized string similar to Parameter {0} cannot be null..
101 | ///
102 | internal static string ParameterCannotBeNull {
103 | get {
104 | return ResourceManager.GetString("ParameterCannotBeNull", resourceCulture);
105 | }
106 | }
107 |
108 | ///
109 | /// Looks up a localized string similar to Parameter count does not match Parameter Value count..
110 | ///
111 | internal static string ParameterCountDoesNotMatch {
112 | get {
113 | return ResourceManager.GetString("ParameterCountDoesNotMatch", resourceCulture);
114 | }
115 | }
116 |
117 | ///
118 | /// Looks up a localized string similar to Required version of assembly {0} is {1}. Found verions is {2}..
119 | ///
120 | internal static string RequiredAssemblyNotFound {
121 | get {
122 | return ResourceManager.GetString("RequiredAssemblyNotFound", resourceCulture);
123 | }
124 | }
125 |
126 | ///
127 | /// Looks up a localized string similar to Wrong format: {0}.
128 | ///
129 | internal static string WrongFormat {
130 | get {
131 | return ResourceManager.GetString("WrongFormat", resourceCulture);
132 | }
133 | }
134 | }
135 | }
136 |
--------------------------------------------------------------------------------
/Source/Mirabeau.Sql/String.Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
121 | cannot be null
122 |
123 |
124 | cannot be null or empty
125 |
126 |
127 | [Errorcode: {0}] {1}
128 | The format in which errors (description) are shown
129 |
130 |
131 | No errorcode available for errorcode: {0}.
132 |
133 |
134 | Parameter {0} cannot be null.
135 |
136 |
137 | Parameter count does not match Parameter Value count.
138 |
139 |
140 | Required version of assembly {0} is {1}. Found verions is {2}.
141 |
142 |
143 | Wrong format: {0}
144 |
145 |
--------------------------------------------------------------------------------
/Source/Mirabeau.Sql/StringExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Mirabeau.Sql
4 | {
5 | ///
6 | /// Extentions for string.
7 | ///
8 | public static class StringExtensions
9 | {
10 | ///
11 | /// Replaces a single quote to a double single quote.
12 | ///
13 | ///
14 | ///
15 | public static string ReplaceSingleQuote(this string sql)
16 | {
17 | if (sql == null)
18 | {
19 | throw new ArgumentNullException("sql");
20 | }
21 | return sql.Replace("'", "''");
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Source/Mirabeau.Sql/TaskExtentions.cs:
--------------------------------------------------------------------------------
1 | using System.Threading.Tasks;
2 |
3 | namespace Mirabeau.Sql
4 | {
5 | internal static class TaskExtentions
6 | {
7 | internal static T TaskResult(this Task task)
8 | {
9 | return task.GetAwaiter().GetResult();
10 | }
11 | }
12 | }
--------------------------------------------------------------------------------
/Source/packages/repositories.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/appveyor.yml:
--------------------------------------------------------------------------------
1 | version: 4.0.0.{build}
2 | skip_tags: true
3 | configuration: Release
4 | assembly_info:
5 | patch: true
6 | file: '**\AssemblyInfo.*'
7 | assembly_version: '{version}'
8 | assembly_file_version: '{version}'
9 | assembly_informational_version: '{version}'
10 | build:
11 | publish_nuget: true
12 | publish_nuget_symbols: true
13 | verbosity: minimal
14 | include_nuget_references: true
15 | environment:
16 | COVERALLS_REPO_TOKEN:
17 | secure: JC9AZf9AdKHmaWmaWMq/fnFaGCIkVvdQjIfHOuWGTXycseJYYbBk+Q7HUbxHJryU
18 | after_test:
19 | - Source\packages\OpenCover.4.6.166\tools\OpenCover.Console.exe -mergeoutput -register:user -target:"Source\packages\NUnit.Runners.2.6.4\tools\nunit-console.exe" "-targetargs:""Source\Mirabeau.MsSql.Library.UnitTests\bin\Release\Mirabeau.MsSql.Library.UnitTests.dll"" /noshadow" -output:opencoverCoverage.xml
20 | - Source\packages\OpenCover.4.6.166\tools\OpenCover.Console.exe -mergeoutput -register:user -target:"Source\packages\NUnit.Runners.2.6.4\tools\nunit-console.exe" "-targetargs:""Source\Mirabeau.MySql.Library.UnitTests\bin\Release\Mirabeau.MySql.Library.UnitTests.dll"" /noshadow" -output:opencoverCoverage.xml
21 | - Source\packages\coveralls.net.0.6.0\tools\csmacnz.Coveralls.exe --opencover -i opencoverCoverage.xml --repoToken %COVERALLS_REPO_TOKEN% --commitBranch %APPVEYOR_REPO_BRANCH%
22 | deploy:
23 | - provider: NuGet
24 | api_key:
25 | secure: sgFlZQ6SSawwtiKcN23uO3hdwEGvy8M4hA8ye2iTAPdmz4gByofx2ZljpJHZ+Pm3
26 | on:
27 | branch: master
--------------------------------------------------------------------------------
/mssql-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeroenpot/SqlHelper/a72fed0cc4a3276854fa33b13692806a60140fb4/mssql-icon.png
--------------------------------------------------------------------------------
/mysql-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeroenpot/SqlHelper/a72fed0cc4a3276854fa33b13692806a60140fb4/mysql-icon.png
--------------------------------------------------------------------------------
/releaseversion.txt:
--------------------------------------------------------------------------------
1 | 4.0.0
--------------------------------------------------------------------------------