Skip to content

Commit

Permalink
Update Peachpie.Library.PDO.MySql to use MySqlConnector
Browse files Browse the repository at this point in the history
  • Loading branch information
iamcarbon committed May 23, 2018
1 parent db752dc commit 762aaec
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 55 deletions.
16 changes: 7 additions & 9 deletions src/PDO/Peachpie.Library.PDO.MySQL/PDOMySQLDriver.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;
using MySql.Data.MySqlClient;

using Pchp.Core;
using System.Data.Common;

namespace Peachpie.Library.PDO.MySQL
{
Expand All @@ -27,9 +23,11 @@ public PDOMySQLDriver() : base("mysql", MySqlClientFactory.Instance)
protected override string BuildConnectionString(string dsn, string user, string password, PhpArray options)
{
//TODO mysql pdo parameters to dotnet connectionstring
var csb = new MySqlConnectionStringBuilder(dsn);
csb.UserID = user;
csb.Password = password;
var csb = new MySqlConnectionStringBuilder(dsn)
{
UserID = user,
Password = password
};
return csb.ConnectionString;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<Import Project="..\..\..\build\Targets\Settings.props" />
<PropertyGroup>
<TargetFrameworks>netstandard1.6;netstandard2.0;net46</TargetFrameworks>
<TargetFrameworks>netstandard1.5;netstandard2.0;net46</TargetFrameworks>
<PreserveCompilationContext>true</PreserveCompilationContext>
<AssemblyName>Peachpie.Library.PDO.MySQL</AssemblyName>
<PackageId>Peachpie.Library.PDO.MySQL</PackageId>
Expand All @@ -14,7 +14,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="MySql.Data" Version="7.0.6-IR31" />
<PackageReference Include="MySqlConnector" Version="0.40.4" />
</ItemGroup>

</Project>
12 changes: 2 additions & 10 deletions src/Peachpie.App/Peachpie.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Import Project="..\..\build\Targets\Settings.props" />
<PropertyGroup>
<Description>Peachpie platform dependencies.</Description>
<TargetFrameworks>netstandard1.5;netstandard1.6;netstandard2.0;net46</TargetFrameworks>
<TargetFrameworks>netstandard1.5;netstandard2.0;net46</TargetFrameworks>
<AssemblyName>Peachpie.App</AssemblyName>
<PackageId>Peachpie.App</PackageId>
<IncludeBuildOutput>false</IncludeBuildOutput>
Expand All @@ -17,19 +17,11 @@
<ProjectReference Include="..\Peachpie.Runtime\Peachpie.Runtime.csproj" />
<ProjectReference Include="..\Peachpie.Library\Peachpie.Library.csproj" />
<ProjectReference Include="..\Peachpie.Library.MsSql\Peachpie.Library.MsSql.csproj" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' != 'netstandard1.5' ">
<ProjectReference Include="..\Peachpie.Library.MySql\Peachpie.Library.MySql.csproj" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net46' ">
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'net46' ">
<ProjectReference Include="..\Peachpie.Library.XmlDom\Peachpie.Library.XmlDom.csproj" />
</ItemGroup>

</Project>
</Project>
37 changes: 10 additions & 27 deletions src/Peachpie.Library.MySql/MySqlResultResource.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
using MySql.Data.MySqlClient;
using MySql.Data.Types;
using Pchp.Core;
using Pchp.Library.Database;
using System;
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;
using Pchp.Core;
using Pchp.Library.Database;
using Pchp.Library.Resources;

namespace Peachpie.Library.MySql
Expand Down Expand Up @@ -69,10 +66,8 @@ internal static MySqlResultResource ValidResult(PhpResource handle)
protected override void FreeManaged()
{
var reader = (MySqlDataReader)this.Reader;
if (reader != null)
{
reader.Close(); // non virtual!!
}

reader?.Dispose();

base.FreeManaged();
}
Expand Down Expand Up @@ -176,8 +171,8 @@ private static object ConvertDbValue(string dataType, object sqlValue)
if (sqlValue.GetType() == typeof(float))
return Pchp.Core.Convert.ToString((float)sqlValue);

if (sqlValue.GetType() == typeof(System.DateTime))
return ConvertDateTime(dataType, (System.DateTime)sqlValue);
if (sqlValue.GetType() == typeof(DateTime))
return ConvertDateTime(dataType, (DateTime)sqlValue);

if (sqlValue.GetType() == typeof(long))
return ((long)sqlValue).ToString();
Expand All @@ -194,24 +189,12 @@ private static object ConvertDbValue(string dataType, object sqlValue)
if (sqlValue.GetType() == typeof(byte[]))
return (byte[])sqlValue;

//MySqlDateTime sql_date_time = sqlValue as MySqlDateTime;
if (sqlValue.GetType() == typeof(MySqlDateTime))
{
MySqlDateTime sql_date_time = (MySqlDateTime)sqlValue;
if (sql_date_time.IsValidDateTime)
return ConvertDateTime(dataType, sql_date_time.GetDateTime());

if (dataType == "DATE" || dataType == "NEWDATE")
return "0000-00-00";
else
return "0000-00-00 00:00:00";
}


Debug.Fail("Unexpected DB field type " + sqlValue.GetType() + ".");
return sqlValue.ToString();
}

private static string ConvertDateTime(string dataType, System.DateTime value)
private static string ConvertDateTime(string dataType, DateTime value)
{
if (dataType == "DATE" || dataType == "NEWDATE")
return value.ToString("yyyy-MM-dd");
Expand Down
10 changes: 3 additions & 7 deletions src/Peachpie.Library.MySql/Peachpie.Library.MySql.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<Import Project="..\..\build\Targets\Settings.props" />
<PropertyGroup>
<TargetFrameworks>netstandard1.6;netstandard2.0;net46</TargetFrameworks>
<TargetFrameworks>netstandard1.5;netstandard2.0;net46</TargetFrameworks>
<AssemblyName>Peachpie.Library.MySql</AssemblyName>
<PackageId>Peachpie.Library.MySql</PackageId>
<PackageTags>peachpie;library;mysql</PackageTags>
Expand All @@ -16,11 +16,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="MySql.Data" Version="7.0.7-M61" />
<PackageReference Include="MySqlConnector" Version="0.40.4" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net46' ">
<Reference Include="System" />
</ItemGroup>


</Project>

0 comments on commit 762aaec

Please sign in to comment.