Skip to content
This repository was archived by the owner on Apr 15, 2025. It is now read-only.

Commit 82d6226

Browse files
committed
Adding MariaDB support. Closes #76
1 parent 64e3d31 commit 82d6226

File tree

18 files changed

+267
-19
lines changed

18 files changed

+267
-19
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{B2D692A1-8751-45DD-BAB0-8155C79E560E}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>DataCore.Database.MySql</RootNamespace>
11+
<AssemblyName>DataCore.Database.MySql</AssemblyName>
12+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<DebugSymbols>true</DebugSymbols>
17+
<DebugType>full</DebugType>
18+
<Optimize>false</Optimize>
19+
<OutputPath>bin\Debug\</OutputPath>
20+
<DefineConstants>DEBUG;TRACE</DefineConstants>
21+
<ErrorReport>prompt</ErrorReport>
22+
<WarningLevel>4</WarningLevel>
23+
</PropertyGroup>
24+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25+
<DebugType>pdbonly</DebugType>
26+
<Optimize>true</Optimize>
27+
<OutputPath>bin\Release\</OutputPath>
28+
<DefineConstants>TRACE</DefineConstants>
29+
<ErrorReport>prompt</ErrorReport>
30+
<WarningLevel>4</WarningLevel>
31+
</PropertyGroup>
32+
<ItemGroup>
33+
<Reference Include="MySql.Data, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
34+
<HintPath>..\packages\MySql.Data.6.9.9\lib\net40\MySql.Data.dll</HintPath>
35+
</Reference>
36+
<Reference Include="System" />
37+
<Reference Include="System.Core" />
38+
<Reference Include="System.Xml.Linq" />
39+
<Reference Include="System.Data.DataSetExtensions" />
40+
<Reference Include="Microsoft.CSharp" />
41+
<Reference Include="System.Data" />
42+
<Reference Include="System.Xml" />
43+
</ItemGroup>
44+
<ItemGroup>
45+
<Compile Include="MySqlDatabase.cs" />
46+
<Compile Include="MySqlTranslator.cs" />
47+
<Compile Include="Properties\AssemblyInfo.cs" />
48+
</ItemGroup>
49+
<ItemGroup>
50+
<ProjectReference Include="..\DataCore.Database\DataCore.Database.csproj">
51+
<Project>{bb807b00-3b7d-4aad-9b56-a73ec1458366}</Project>
52+
<Name>DataCore.Database</Name>
53+
</ProjectReference>
54+
<ProjectReference Include="..\DataCore\DataCore.csproj">
55+
<Project>{deda8ebc-ad0e-492e-85f7-2dbcc1c66c5f}</Project>
56+
<Name>DataCore</Name>
57+
</ProjectReference>
58+
</ItemGroup>
59+
<ItemGroup>
60+
<None Include="app.config" />
61+
<None Include="packages.config" />
62+
</ItemGroup>
63+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
64+
</Project>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.Data;
2+
3+
namespace DataCore.Database.MySql
4+
{
5+
public class MySqlDatabase : Database
6+
{
7+
public MySqlDatabase(IDbConnection connection) : base(connection, new MySqlTranslator())
8+
{
9+
}
10+
}
11+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
using System.Data;
2+
3+
namespace DataCore.Database.MySql
4+
{
5+
public class MySqlTranslator : Translator
6+
{
7+
protected override string GetStringForColumn(FieldDefinition field)
8+
{
9+
var nullable = field.Nullable ? "NULL" : "NOT NULL";
10+
var primaryKey = field.IsPrimaryKey ? " PRIMARY KEY" : null;
11+
12+
var extra = primaryKey ?? nullable;
13+
14+
return string.Format(GetFormatFor(field), field.Name, GetTextFor(field.Type), field.Size, field.Precision, extra,
15+
field.IsIdentity ? "AUTO_INCREMENT" : "");
16+
}
17+
18+
protected override string GetSelectTableName(string tableName)
19+
{
20+
return tableName;
21+
}
22+
23+
public override string GetIsNullFunctionName()
24+
{
25+
return "coalesce";
26+
}
27+
28+
public override string GetLengthFunctionName()
29+
{
30+
return "length";
31+
}
32+
33+
public override string GetAliasFormat()
34+
{
35+
return "\"{0}\"";
36+
}
37+
38+
public override string GetDropIndexIfExistsQuery(string tableName, string indexName)
39+
{
40+
return
41+
string.Concat(
42+
"IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.STATISTICS WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME = '",
43+
tableName,
44+
"' AND INDEX_NAME = '", indexName,
45+
"') THEN ALTER TABLE ", tableName, " DROP INDEX ", indexName, "; END IF;");
46+
}
47+
48+
public override string GetCreateIndexIfNotExistsQuery(string indexName, string tableName, string columns, bool unique)
49+
{
50+
return
51+
string.Concat(
52+
"IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.STATISTICS WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME = '",
53+
tableName,
54+
"' AND INDEX_NAME = '", indexName,
55+
"') THEN CREATE", unique ? " UNIQUE" : "", " INDEX ", indexName, " ON ", tableName, "(", columns,
56+
"); END IF;");
57+
}
58+
59+
public override string GetDropForeignKeyIfExistsQuery(string tableName, string indexName)
60+
{
61+
return string.Concat("ALTER TABLE ", tableName, " DROP FOREIGN KEY ", indexName);
62+
}
63+
64+
protected override string GetTextFor(DbType type, bool isCasting = false)
65+
{
66+
switch (type)
67+
{
68+
case DbType.Boolean:
69+
return "BOOLEAN";
70+
case DbType.Double:
71+
case DbType.Decimal:
72+
case DbType.Single:
73+
case DbType.Currency:
74+
case DbType.VarNumeric:
75+
return "REAL";
76+
case DbType.Guid:
77+
case DbType.AnsiString:
78+
case DbType.AnsiStringFixedLength:
79+
case DbType.String:
80+
case DbType.StringFixedLength:
81+
case DbType.Object:
82+
case DbType.Xml:
83+
return "VARCHAR";
84+
case DbType.Time:
85+
case DbType.Date:
86+
case DbType.DateTime:
87+
case DbType.DateTime2:
88+
case DbType.DateTimeOffset:
89+
return "DATETIME";
90+
default:
91+
return isCasting ? "SIGNED" : "INTEGER";
92+
}
93+
}
94+
}
95+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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("DataCore.Database.MySql")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("DataCore.Database.MySql")]
13+
[assembly: AssemblyCopyright("Copyright © 2017")]
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("b2d692a1-8751-45dd-bab0-8155c79e560e")]
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")]

‎DataCore.Database.MySql/app.config

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<system.data>
4+
<DbProviderFactories>
5+
<remove invariant="MySql.Data.MySqlClient" />
6+
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
7+
</DbProviderFactories>
8+
</system.data>
9+
</configuration>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="MySql.Data" version="6.9.9" targetFramework="net40" />
4+
</packages>

‎DataCore.Database.Oracle/OracleTranslator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ protected override string GetFormatFor(FieldDefinition field)
144144
}
145145
}
146146

147-
protected override string GetTextFor(DbType type)
147+
protected override string GetTextFor(DbType type, bool isCasting = false)
148148
{
149149
switch (type)
150150
{

‎DataCore.Database.Postgres/PostgresTranslator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ protected override string GetFormatFor(FieldDefinition field)
6262
}
6363
}
6464

65-
protected override string GetTextFor(DbType type)
65+
protected override string GetTextFor(DbType type, bool isCasting = false)
6666
{
6767
switch (type)
6868
{

‎DataCore.Database.SqlServer/SqlServerTranslator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ protected override string GetStringForColumn(FieldDefinition field)
7979
return string.Format(GetFormatFor(field), field.Name, GetTextFor(field.Type), field.Size, field.Precision, extra, identity);
8080
}
8181

82-
protected override string GetTextFor(DbType type)
82+
protected override string GetTextFor(DbType type, bool isCasting = false)
8383
{
8484
switch (type)
8585
{

‎DataCore.Test/App.config

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
33
<configSections>
4-
<section name="oracle.manageddataaccess.client"
5-
type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
4+
<section name="oracle.manageddataaccess.client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
65
</configSections>
76
<system.data>
87
<DbProviderFactories>
9-
<remove invariant="Oracle.ManagedDataAccess.Client"/>
10-
<add name="ODP.NET, Managed Driver" invariant="Oracle.ManagedDataAccess.Client" description="Oracle Data Provider for .NET, Managed Driver"
11-
type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
12-
</DbProviderFactories>
8+
<remove invariant="Oracle.ManagedDataAccess.Client" />
9+
<add name="ODP.NET, Managed Driver" invariant="Oracle.ManagedDataAccess.Client" description="Oracle Data Provider for .NET, Managed Driver" type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
10+
<remove invariant="MySql.Data.MySqlClient" /><add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" /></DbProviderFactories>
1311
</system.data>
1412
<runtime>
1513
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
1614
<dependentAssembly>
17-
<publisherPolicy apply="no"/>
18-
<assemblyIdentity name="Oracle.ManagedDataAccess" publicKeyToken="89b483f429c47342" culture="neutral"/>
19-
<bindingRedirect oldVersion="4.121.0.0 - 4.65535.65535.65535" newVersion="4.121.2.0"/>
15+
<publisherPolicy apply="no" />
16+
<assemblyIdentity name="Oracle.ManagedDataAccess" publicKeyToken="89b483f429c47342" culture="neutral" />
17+
<bindingRedirect oldVersion="4.121.0.0 - 4.65535.65535.65535" newVersion="4.121.2.0" />
2018
</dependentAssembly>
2119
</assemblyBinding>
2220
</runtime>
2321
<oracle.manageddataaccess.client>
2422
<version number="*">
2523
<dataSources>
26-
<dataSource alias="SampleDataSource" descriptor="(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORCL))) "/>
24+
<dataSource alias="SampleDataSource" descriptor="(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORCL))) " />
2725
</dataSources>
2826
</version>
2927
</oracle.manageddataaccess.client>

0 commit comments

Comments
 (0)