Skip to content

Commit d46795f

Browse files
committed
Dep/MySQL: Update MySql connector to 6.9.6
.NET 4.5.1 is now required
1 parent d587336 commit d46795f

39 files changed

+1901
-440
lines changed

MySql.Data/BulkLoader.cs

+24-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
1+
// Copyright (c) 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc. 2014, Oracle and/or its affiliates. All rights reserved.
22
//
33
// MySQL Connector/NET is licensed under the terms of the GPLv2
44
// <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
@@ -30,6 +30,7 @@
3030
using MySql.Data.Common;
3131
#if NET_40_OR_GREATER
3232
using System.Threading.Tasks;
33+
using System.Threading;
3334
#endif
3435

3536
namespace MySql.Data.MySqlClient
@@ -290,10 +291,29 @@ public int Load()
290291
/// <returns>The number of rows inserted.</returns>
291292
public Task<int> LoadAsync()
292293
{
293-
return Task.Factory.StartNew(() =>
294+
return LoadAsync(CancellationToken.None);
295+
}
296+
297+
public Task<int> LoadAsync(CancellationToken cancellationToken)
298+
{
299+
var result = new TaskCompletionSource<int>();
300+
if (cancellationToken == CancellationToken.None || !cancellationToken.IsCancellationRequested)
294301
{
295-
return Load();
296-
});
302+
try
303+
{
304+
int loadResult = Load();
305+
result.SetResult(loadResult);
306+
}
307+
catch (Exception ex)
308+
{
309+
result.SetException(ex);
310+
}
311+
}
312+
else
313+
{
314+
result.SetCanceled();
315+
}
316+
return result.Task;
297317
}
298318
#endregion
299319
#endif

MySql.Data/CharSetMap.cs

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © 2004, 2013, Oracle and/or its affiliates. All rights reserved.
1+
// Copyright © 2004, 2014, Oracle and/or its affiliates. All rights reserved.
22
//
33
// MySQL Connector/NET is licensed under the terms of the GPLv2
44
// <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
@@ -49,9 +49,12 @@ static CharSetMap()
4949

5050
public static CharacterSet GetCharacterSet(DBVersion version, string CharSetName)
5151
{
52-
CharacterSet cs = (CharacterSet)mapping[CharSetName];
52+
CharacterSet cs = null;
53+
if(mapping.ContainsKey(CharSetName))
54+
cs = (CharacterSet)mapping[CharSetName];
55+
5356
if (cs == null)
54-
throw new MySqlException("Character set '" + CharSetName + "' is not supported");
57+
throw new MySqlException("Character set '" + CharSetName + "' is not supported by .Net Framework.");
5558
return cs;
5659
}
5760

@@ -143,6 +146,7 @@ private static void LoadCharsetMap()
143146
mapping.Add("dos", new CharacterSet("ibm437", 1));
144147
mapping.Add("utf8mb4", new CharacterSet("utf-8", 4));
145148
mapping.Add("utf16", new CharacterSet("utf-16BE", 2));
149+
mapping.Add("utf16le", new CharacterSet("utf-16", 2));
146150
mapping.Add("utf32", new CharacterSet("utf-32BE", 4));
147151
}
148152

MySql.Data/Connection.cs

+175-32
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © 2004, 2013, Oracle and/or its affiliates. All rights reserved.
1+
// Copyright © 2004, 2014, Oracle and/or its affiliates. All rights reserved.
22
//
33
// MySQL Connector/NET is licensed under the terms of the GPLv2
44
// <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
@@ -43,6 +43,7 @@
4343
#endif
4444
#if NET_40_OR_GREATER
4545
using System.Threading.Tasks;
46+
using System.Threading;
4647
#endif
4748

4849
namespace MySql.Data.MySqlClient
@@ -88,6 +89,17 @@ public MySqlConnection(string connectionString)
8889
ConnectionString = connectionString;
8990
}
9091

92+
#region Destructor
93+
~MySqlConnection()
94+
{
95+
#if !RT
96+
Dispose(false);
97+
#else
98+
Dispose();
99+
#endif
100+
}
101+
#endregion
102+
91103
#region Interal Methods & Properties
92104

93105
#if !CF
@@ -478,7 +490,6 @@ public override void Open()
478490
if (driver == null)
479491
{
480492
ReplicationManager.GetNewConnection(Settings.Server, false, this);
481-
return;
482493
}
483494
else
484495
currentSettings = driver.Settings;
@@ -802,11 +813,21 @@ internal void Throw(Exception ex)
802813
#endif
803814
}
804815

816+
#if !RT
817+
public void Dispose()
818+
{
819+
Dispose(true);
820+
GC.SuppressFinalize(this);
821+
}
822+
#else
805823
public void Dispose()
806824
{
807825
if (State == ConnectionState.Open)
808826
Close();
827+
828+
GC.SuppressFinalize(this);
809829
}
830+
#endif
810831

811832
#if NET_40_OR_GREATER
812833
#region Async
@@ -816,76 +837,179 @@ public void Dispose()
816837
/// <returns>An object representing the new transaction.</returns>
817838
public Task<MySqlTransaction> BeginTransactionAsync()
818839
{
819-
return BeginTransactionAsync(IsolationLevel.RepeatableRead);
840+
return BeginTransactionAsync(IsolationLevel.RepeatableRead, CancellationToken.None);
841+
}
842+
843+
public Task<MySqlTransaction> BeginTransactionAsync(CancellationToken cancellationToken)
844+
{
845+
return BeginTransactionAsync(IsolationLevel.RepeatableRead, cancellationToken);
820846
}
847+
821848
/// <summary>
822849
/// Async version of BeginTransaction
823850
/// </summary>
824851
/// <param name="iso">The isolation level under which the transaction should run. </param>
825852
/// <returns>An object representing the new transaction.</returns>
826853
public Task<MySqlTransaction> BeginTransactionAsync(IsolationLevel iso)
827854
{
828-
return Task.Factory.StartNew(() =>
855+
return BeginTransactionAsync(iso, CancellationToken.None);
856+
}
857+
858+
public Task<MySqlTransaction> BeginTransactionAsync(IsolationLevel iso, CancellationToken cancellationToken)
859+
{
860+
var result = new TaskCompletionSource<MySqlTransaction>();
861+
if (cancellationToken == CancellationToken.None || !cancellationToken.IsCancellationRequested)
829862
{
830-
return BeginTransaction(iso);
831-
});
863+
try
864+
{
865+
MySqlTransaction tranResult = BeginTransaction(iso);
866+
result.SetResult(tranResult);
867+
}
868+
catch (Exception ex)
869+
{
870+
result.SetException(ex);
871+
}
872+
}
873+
else
874+
{
875+
result.SetCanceled();
876+
}
877+
878+
return result.Task;
832879
}
833-
/// <summary>
834-
/// Async version of ChangeDataBase
835-
/// </summary>
836-
/// <param name="databaseName">The name of the database to use.</param>
837-
/// <returns></returns>
880+
838881
public Task ChangeDataBaseAsync(string databaseName)
839882
{
840-
return Task.Factory.StartNew(() =>
841-
{
842-
ChangeDatabase(databaseName);
843-
});
883+
return ChangeDataBaseAsync(databaseName, CancellationToken.None);
844884
}
885+
845886
/// <summary>
846-
/// Async version of Open
887+
/// Async version of ChangeDataBase
847888
/// </summary>
889+
/// <param name="databaseName">The name of the database to use.</param>
848890
/// <returns></returns>
849-
public Task OpenAsync()
891+
public Task ChangeDataBaseAsync(string databaseName, CancellationToken cancellationToken)
850892
{
851-
return Task.Factory.StartNew(() =>
893+
var result = new TaskCompletionSource<bool>();
894+
if (cancellationToken == CancellationToken.None || !cancellationToken.IsCancellationRequested)
852895
{
853-
Open();
854-
});
896+
try
897+
{
898+
ChangeDatabase(databaseName);
899+
result.SetResult(true);
900+
}
901+
catch (Exception ex)
902+
{
903+
result.SetException(ex);
904+
}
905+
}
906+
return result.Task;
855907
}
908+
909+
///// <summary>
910+
///// Async version of Open
911+
///// </summary>
912+
///// <returns></returns>
913+
//public Task OpenAsync()
914+
//{
915+
// return Task.Run(() =>
916+
// {
917+
// Open();
918+
// });
919+
//}
920+
856921
/// <summary>
857922
/// Async version of Close
858923
/// </summary>
859924
/// <returns></returns>
860925
public Task CloseAsync()
861926
{
862-
return Task.Factory.StartNew(() =>
927+
return CloseAsync(CancellationToken.None);
928+
}
929+
930+
public Task CloseAsync(CancellationToken cancellationToken)
931+
{
932+
var result = new TaskCompletionSource<bool>();
933+
if (cancellationToken == CancellationToken.None || !cancellationToken.IsCancellationRequested)
863934
{
864-
Close();
865-
});
935+
try
936+
{
937+
Close();
938+
result.SetResult(true);
939+
}
940+
catch (Exception ex)
941+
{
942+
result.SetException(ex);
943+
}
944+
}
945+
else
946+
{
947+
result.SetCanceled();
948+
}
949+
return result.Task;
866950
}
951+
867952
/// <summary>
868953
/// Async version of ClearPool
869954
/// </summary>
870955
/// <param name="connection">The connection associated with the pool to be cleared.</param>
871956
/// <returns></returns>
872957
public Task ClearPoolAsync(MySqlConnection connection)
873958
{
874-
return Task.Factory.StartNew(() =>
959+
return ClearPoolAsync(connection, CancellationToken.None);
960+
}
961+
962+
public Task ClearPoolAsync(MySqlConnection connection, CancellationToken cancellationToken)
963+
{
964+
var result = new TaskCompletionSource<bool>();
965+
if (cancellationToken == CancellationToken.None || !cancellationToken.IsCancellationRequested)
875966
{
876-
ClearPool(connection);
877-
});
967+
try
968+
{
969+
ClearPool(connection);
970+
result.SetResult(true);
971+
}
972+
catch (Exception ex)
973+
{
974+
result.SetException(ex);
975+
}
976+
}
977+
else
978+
{
979+
result.SetCanceled();
980+
}
981+
return result.Task;
878982
}
983+
879984
/// <summary>
880985
/// Async version of ClearAllPools
881986
/// </summary>
882987
/// <returns></returns>
883988
public Task ClearAllPoolsAsync()
884989
{
885-
return Task.Factory.StartNew(() =>
990+
return ClearAllPoolsAsync(CancellationToken.None);
991+
}
992+
993+
public Task ClearAllPoolsAsync(CancellationToken cancellationToken)
994+
{
995+
var result = new TaskCompletionSource<bool>();
996+
if (cancellationToken == CancellationToken.None || !cancellationToken.IsCancellationRequested)
997+
{
998+
try
999+
{
1000+
ClearAllPools();
1001+
result.SetResult(true);
1002+
}
1003+
catch (Exception ex)
1004+
{
1005+
result.SetException(ex);
1006+
}
1007+
}
1008+
else
8861009
{
887-
ClearAllPools();
888-
});
1010+
result.SetCanceled();
1011+
}
1012+
return result.Task;
8891013
}
8901014
/// <summary>
8911015
/// Async version of GetSchemaCollection
@@ -895,10 +1019,29 @@ public Task ClearAllPoolsAsync()
8951019
/// <returns>A schema collection</returns>
8961020
public Task<MySqlSchemaCollection> GetSchemaCollectionAsync(string collectionName, string[] restrictionValues)
8971021
{
898-
return Task.Factory.StartNew(() =>
1022+
return GetSchemaCollectionAsync(collectionName, restrictionValues, CancellationToken.None);
1023+
}
1024+
1025+
public Task<MySqlSchemaCollection> GetSchemaCollectionAsync(string collectionName, string[] restrictionValues, CancellationToken cancellationToken)
1026+
{
1027+
var result = new TaskCompletionSource<MySqlSchemaCollection>();
1028+
if (cancellationToken == CancellationToken.None || !cancellationToken.IsCancellationRequested)
8991029
{
900-
return GetSchemaCollection(collectionName, restrictionValues);
901-
});
1030+
try
1031+
{
1032+
var schema = GetSchemaCollection(collectionName, restrictionValues);
1033+
result.SetResult(schema);
1034+
}
1035+
catch (Exception ex)
1036+
{
1037+
result.SetException(ex);
1038+
}
1039+
}
1040+
else
1041+
{
1042+
result.SetCanceled();
1043+
}
1044+
return result.Task;
9021045
}
9031046
#endregion
9041047
#endif

MySql.Data/Crypt.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// Copyright (c) 2004-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.,
2-
// 2013 Oracle and/or its affiliates. All rights reserved.
1+
// Copyright (c) 2004-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc., 2013, 2014 Oracle and/or its affiliates. All rights reserved.
32
//
43
// MySQL Connector/NET is licensed under the terms of the GPLv2
54
// <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most

0 commit comments

Comments
 (0)