Skip to content

Commit d3c7672

Browse files
authored
Merge pull request #2 from dennis-gr/master
MySqlConnector Driver
2 parents 8e3897a + 7826b5a commit d3c7672

8 files changed

+599
-1
lines changed

LICENSE.txt

Lines changed: 460 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using NHibernate.Cfg.Loquacious;
2+
using NHibernate.Driver.MySqlConnector;
3+
4+
namespace NHibernate.Cfg
5+
{
6+
public static class ConnectionConfigurationExtensionMySqlConnector
7+
{
8+
public static void MySqlConnectorDriver(this IDbIntegrationConfigurationProperties cfg) => cfg.Driver<MySqlConnectorDriver>();
9+
}
10+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
using System.Data.Common;
3+
4+
using MySql.Data.MySqlClient;
5+
6+
using NHibernate.AdoNet;
7+
using NHibernate.Engine;
8+
9+
namespace NHibernate.Driver.MySqlConnector
10+
{
11+
/// <summary>
12+
/// Provides a database driver for MySQL using <a href="https://mysqlconnector.net/">MySqlConnector</a>.
13+
/// </summary>
14+
/// <remarks>
15+
/// Uses <see cref="GenericBatchingBatcherFactory"/> for batching.
16+
/// </remarks>
17+
public class MySqlConnectorDriver : DriverBase, IEmbeddedBatcherFactoryProvider
18+
{
19+
public override bool UseNamedPrefixInSql => true;
20+
21+
public override bool UseNamedPrefixInParameter => true;
22+
23+
public override string NamedPrefix => "@";
24+
25+
public override bool SupportsMultipleQueries => true;
26+
27+
public override bool SupportsMultipleOpenReaders => false;
28+
29+
/// <summary>
30+
/// MySqlConnector prepares commands if <b>IgnorePrepare</b> is set to false in the connection string (default is true),
31+
/// otherwise calling <see cref="MySqlCommand.Prepare"/> is a no-op.
32+
/// </summary>
33+
protected override bool SupportsPreparingCommands => true;
34+
35+
public override DbConnection CreateConnection() => new MySqlConnection();
36+
37+
public override DbCommand CreateCommand() => new MySqlCommand();
38+
39+
public override IResultSetsCommand GetResultSetsCommand(ISessionImplementor session) => new BasicResultSetsCommand(session);
40+
41+
// As of v5.7, lower dates may "work" but without guarantees.
42+
// https://dev.mysql.com/doc/refman/5.7/en/datetime.html
43+
/// <inheritdoc />
44+
public override DateTime MinDate => new DateTime(1000, 1, 1);
45+
46+
public System.Type BatcherFactoryClass => typeof(GenericBatchingBatcherFactory);
47+
}
48+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>net461;netstandard2.0</TargetFrameworks>
5+
<SignAssembly>true</SignAssembly>
6+
<AssemblyOriginatorKeyFile>NHibernate.MySqlConnector.snk</AssemblyOriginatorKeyFile>
7+
<Authors>NHibernate community</Authors>
8+
<Company>NHibernate.info</Company>
9+
<Copyright>Licensed under LGPL.</Copyright>
10+
<PackageLicenseExpression>LGPL-2.1-only</PackageLicenseExpression>
11+
<PackageProjectUrl>http://nhibernate.info</PackageProjectUrl>
12+
<PackageTags>nhibernate; mysqlconnector; mysql; mariadb;</PackageTags>
13+
<Description>NHibernate driver for MySQL/MariaDB using MySqlConnector.</Description>
14+
<RepositoryUrl>https://github.com/nhibernate/NHibernate.MySqlConnector</RepositoryUrl>
15+
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
16+
<Product>NHibernate.Driver.MySqlConnector</Product>
17+
<PackageId>NHibernate.Driver.MySqlConnector</PackageId>
18+
</PropertyGroup>
19+
20+
<ItemGroup>
21+
<PackageReference Include="MySqlConnector" Version="0.63.0" />
22+
<PackageReference Include="NHibernate" Version="5.1.0" />
23+
</ItemGroup>
24+
25+
</Project>
596 Bytes
Binary file not shown.

NHibernate.MySqlConnector.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.29905.134
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NHibernate.Driver.MySqlConnector", "NHibernate.Driver.MySqlConnector\NHibernate.Driver.MySqlConnector.csproj", "{32339143-AF38-4521-BF81-03E46771DE2E}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{32339143-AF38-4521-BF81-03E46771DE2E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{32339143-AF38-4521-BF81-03E46771DE2E}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{32339143-AF38-4521-BF81-03E46771DE2E}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{32339143-AF38-4521-BF81-03E46771DE2E}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {4A791EBC-7772-4C3B-AA3F-B9C8A3E8DA2F}
24+
EndGlobalSection
25+
EndGlobal

README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,27 @@
1-
# NHibernate.MySqlConnector
1+
# NHibernate.MySqlConnector
2+
3+
# Description
4+
5+
This package provides an alternative MySQL/MariaDB driver for NHibernate
6+
in addition to `NHibernate.Driver.MySqlDataDriver` provided by `nhibernate-core`.
7+
8+
It uses the [MySqlConnector](https://github.com/mysql-net/MySqlConnector) library
9+
which is an alternative to [MySql.Data](https://www.nuget.org/packages/MySql.Data/)
10+
that may be more performant in both async and sync workloads and fixes dozens of outstanding
11+
bugs in MySql.Data.
12+
13+
## Usage
14+
15+
Set `connection.driver_class` in your NHibernate session factory config to:
16+
17+
- `connection.driver_class`: `NHibernate.Driver.MySqlConnectorDriver, NHibernate.Driver.MySqlConnector`
18+
19+
or use the Configure-by-code helper:
20+
21+
- `new Configuration().DataBaseIntegration(c => c.MySqlConnectorDriver());`
22+
23+
Values of the other parameters should stay the same as when using `MySql.Data`:
24+
25+
- `connection.provider`: `NHibernate.Connection.DriverConnectionProvider`
26+
27+
- `dialect`: One of the available MySQL dialects e.g. `NHibernate.Dialect.MySQL5Dialect`

appveyor.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
version: 1.0.0.{build}
2+
image: Visual Studio 2019
3+
before_build:
4+
- nuget restore NHibernate.MySqlConnector.sln

0 commit comments

Comments
 (0)