-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #302 from MediaPortal/MP1-5215-TV_Server_and_Maria…
…DB_-_DBNull_problem MP1-5215: Add MySQL.Interceptor and Read TV Server dependencies in SetupTV
- Loading branch information
Showing
19 changed files
with
334 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
Common-MP-TVE3/External/Gentle.NET/Source/Gentle.Provider.MySQL.Interceptor/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#region Copyright (C) 2024 Team MediaPortal | ||
|
||
// Copyright (C) 2024 Team MediaPortal | ||
// http://www.team-mediaportal.com | ||
// | ||
// MediaPortal is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 2 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// MediaPortal is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with MediaPortal. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
#endregion | ||
|
||
using System.Reflection; | ||
|
||
// This file contains only the assemlbly attributes specific to this assembly. | ||
// The remaining attributes are defined in the shared SolutionInfo.cs file. | ||
|
||
[assembly: AssemblyTitle( "MySQL interceptor for Gentle.NET" )] | ||
[assembly: AssemblyDescription( "This inerceptor uses the MySQL .NET Connector library from MySQL AB." )] |
115 changes: 115 additions & 0 deletions
115
...tle.NET/Source/Gentle.Provider.MySQL.Interceptor/Gentle.Provider.MySQL.Interceptor.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0"> | ||
<PropertyGroup> | ||
<ProjectType>Local</ProjectType> | ||
<ProductVersion>9.0.30729</ProductVersion> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
<ProjectGuid>{D8D01EDD-FE20-4F51-9CE1-B5C50244D6CA}</ProjectGuid> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ApplicationIcon> | ||
</ApplicationIcon> | ||
<AssemblyKeyContainerName> | ||
</AssemblyKeyContainerName> | ||
<AssemblyName>Gentle.Provider.MySQL.Interceptor</AssemblyName> | ||
<AssemblyOriginatorKeyFile>Gentle.snk</AssemblyOriginatorKeyFile> | ||
<DefaultClientScript>JScript</DefaultClientScript> | ||
<DefaultHTMLPageLayout>Grid</DefaultHTMLPageLayout> | ||
<DefaultTargetSchema>IE50</DefaultTargetSchema> | ||
<DelaySign>false</DelaySign> | ||
<OutputType>Library</OutputType> | ||
<RootNamespace>Gentle.Provider.MySQL.Interceptor</RootNamespace> | ||
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent> | ||
<StartupObject> | ||
</StartupObject> | ||
<FileUpgradeFlags> | ||
</FileUpgradeFlags> | ||
<UpgradeBackupLocation> | ||
</UpgradeBackupLocation> | ||
<OldToolsVersion>3.5</OldToolsVersion> | ||
<SignAssembly>true</SignAssembly> | ||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> | ||
<TargetFrameworkProfile /> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<AllowUnsafeBlocks>false</AllowUnsafeBlocks> | ||
<BaseAddress>285212672</BaseAddress> | ||
<CheckForOverflowUnderflow>false</CheckForOverflowUnderflow> | ||
<ConfigurationOverrideFile> | ||
</ConfigurationOverrideFile> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<DocumentationFile> | ||
</DocumentationFile> | ||
<DebugSymbols>true</DebugSymbols> | ||
<FileAlignment>4096</FileAlignment> | ||
<NoStdLib>false</NoStdLib> | ||
<NoWarn>1591;1701;1702</NoWarn> | ||
<Optimize>false</Optimize> | ||
<RegisterForComInterop>false</RegisterForComInterop> | ||
<RemoveIntegerChecks>false</RemoveIntegerChecks> | ||
<TreatWarningsAsErrors>false</TreatWarningsAsErrors> | ||
<WarningLevel>4</WarningLevel> | ||
<DebugType>full</DebugType> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningsAsErrors>;NU1605</WarningsAsErrors> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<AllowUnsafeBlocks>false</AllowUnsafeBlocks> | ||
<BaseAddress>285212672</BaseAddress> | ||
<CheckForOverflowUnderflow>false</CheckForOverflowUnderflow> | ||
<ConfigurationOverrideFile> | ||
</ConfigurationOverrideFile> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<DocumentationFile> | ||
</DocumentationFile> | ||
<DebugSymbols>false</DebugSymbols> | ||
<FileAlignment>4096</FileAlignment> | ||
<NoStdLib>false</NoStdLib> | ||
<NoWarn>1591;1701;1702</NoWarn> | ||
<Optimize>true</Optimize> | ||
<RegisterForComInterop>false</RegisterForComInterop> | ||
<RemoveIntegerChecks>false</RemoveIntegerChecks> | ||
<TreatWarningsAsErrors>false</TreatWarningsAsErrors> | ||
<WarningLevel>4</WarningLevel> | ||
<DebugType>none</DebugType> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningsAsErrors>;NU1605</WarningsAsErrors> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="MySql.Data"> | ||
<HintPath>..\Gentle.Provider.MySQL\lib\MySql.Data.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System"> | ||
<Name>System</Name> | ||
</Reference> | ||
<Reference Include="System.Data"> | ||
<Name>System.Data</Name> | ||
</Reference> | ||
<Reference Include="System.Xml"> | ||
<Name>System.XML</Name> | ||
</Reference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="..\SolutionInfo.cs"> | ||
<Link>SolutionInfo.cs</Link> | ||
<SubType>Code</SubType> | ||
</Compile> | ||
<Compile Include="AssemblyInfo.cs"> | ||
<SubType>Code</SubType> | ||
</Compile> | ||
<Compile Include="Interceptor.cs" /> | ||
<Compile Include="Utf8mb3.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="Gentle.snk" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> | ||
<PropertyGroup> | ||
<PreBuildEvent> | ||
</PreBuildEvent> | ||
<PostBuildEvent> | ||
</PostBuildEvent> | ||
</PropertyGroup> | ||
</Project> |
Binary file added
BIN
+596 Bytes
Common-MP-TVE3/External/Gentle.NET/Source/Gentle.Provider.MySQL.Interceptor/Gentle.snk
Binary file not shown.
47 changes: 47 additions & 0 deletions
47
Common-MP-TVE3/External/Gentle.NET/Source/Gentle.Provider.MySQL.Interceptor/Interceptor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#region Copyright (C) 2024 Team MediaPortal | ||
|
||
// Copyright (C) 2024 Team MediaPortal | ||
// http://www.team-mediaportal.com | ||
// | ||
// MediaPortal is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 2 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// MediaPortal is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with MediaPortal. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
#endregion | ||
|
||
using System; | ||
using System.Data; | ||
using MySql.Data.MySqlClient; | ||
|
||
namespace Gentle.Provider.MySQL.Interceptor | ||
{ | ||
/// <summary> | ||
/// Filters out collations with NULL id (e.g. UCA-14.0.0) from SHOW COLLATION command | ||
/// </summary> | ||
public sealed class Interceptor : BaseCommandInterceptor | ||
{ | ||
public override bool ExecuteReader(string sql, CommandBehavior behavior, ref MySqlDataReader returnValue) | ||
{ | ||
if (!sql.Equals("SHOW COLLATION", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
return false; | ||
} | ||
|
||
MySqlCommand command = ActiveConnection.CreateCommand(); | ||
|
||
command.CommandText = "SHOW COLLATION WHERE id IS NOT NULL"; | ||
returnValue = command.ExecuteReader(behavior); | ||
|
||
return true; | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...-MP-TVE3/External/Gentle.NET/Source/Gentle.Provider.MySQL.Interceptor/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Gentle.Provider.MySQL.Interceptor | ||
|
||
## How it works | ||
|
||
Library modifies `SHOW COLLATION` query using `BaseCommandInterceptor` to prevent fetching collations with NULL Id's. | ||
There is also small piece of code which append `utf8mb3` charset to MySql.Data's internal mapping Dictionary allowing | ||
to read fields with utf8mb3 collations. | ||
|
||
## Usage | ||
|
||
1. Append following line to your connection string | ||
|
||
`;commandinterceptors=Gentle.Provider.MySQL.Interceptor.Interceptor,Gentle.Provider.MySQL.Interceptor` | ||
|
||
2. Call `Utf8mb3.Enable()` before opening first MySql connection. |
64 changes: 64 additions & 0 deletions
64
Common-MP-TVE3/External/Gentle.NET/Source/Gentle.Provider.MySQL.Interceptor/Utf8mb3.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#region Copyright (C) 2024 Team MediaPortal | ||
|
||
// Copyright (C) 2024 Team MediaPortal | ||
// http://www.team-mediaportal.com | ||
// | ||
// MediaPortal is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 2 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// MediaPortal is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with MediaPortal. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
#endregion | ||
|
||
using System; | ||
using System.Collections; | ||
using MySql.Data.MySqlClient; | ||
|
||
namespace Gentle.Provider.MySQL.Interceptor | ||
{ | ||
// ReSharper disable once InconsistentNaming | ||
public static class Utf8mb3 | ||
{ | ||
private static readonly Version NewFieldNamingVersion = new Version(6, 10, 0); | ||
|
||
public static void Enable() | ||
{ | ||
// Add internal mapping of database utf8mb3 charset to .NET framework's UTF-8 encoding | ||
var assembly = System.Reflection.Assembly.GetAssembly(typeof(MySqlConnection)); | ||
var connectorVersion = assembly.GetName().Version; | ||
|
||
var mappingFieldName = connectorVersion >= NewFieldNamingVersion ? "_mapping" : "mapping"; | ||
|
||
var mappingField = assembly | ||
.GetType("MySql.Data.MySqlClient.CharSetMap").GetField(mappingFieldName, | ||
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.GetField | | ||
System.Reflection.BindingFlags.Static); | ||
|
||
if (mappingField != null) | ||
{ | ||
var mappingDictionary = (IDictionary)mappingField.GetValue(null); | ||
var utf8Mapping = mappingDictionary["utf8"]; | ||
|
||
if (utf8Mapping != null) | ||
{ | ||
try | ||
{ | ||
mappingDictionary.Add("utf8mb3", utf8Mapping); | ||
} | ||
catch (ArgumentException) | ||
{ | ||
// Item already exist | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.