Skip to content

Commit 9444227

Browse files
committed
Fix Bug #27277013 - DATAREADER CREATED WITH COMMANDBEHAVIOR.CLOSECONNECTION NOT CLOSING CONNECTION
Applying Dispose Pattern to MySqlDataReader, MySqlCommand and MySqlConnection classes (Other related classes have the pattern implemented correctly, i.e. Transaction).
1 parent b25685d commit 9444227

File tree

4 files changed

+32
-23
lines changed

4 files changed

+32
-23
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- Fix for unexpected ColumnSize for CHAR(63) and BLOB columns in GetSchemaTable (MySQL Bug #87868, Oracle Bug #26876582)
44
- Fix to correct unexpected ColummSize and IsLong values returned by MySqlDataReader.GetSchemaTable when using LongText and LongBlob data types. (MySQL Bug #87876, Oracle Bug #26876592)
55
- Fix to correct the wrong NumericPrecision value returned by MySqlDataReader.GetSchemaTable when NumericScale is 0 for Decimal data types. (MySQL Bug #88058, Oracle Bug #26954812)
6+
- Fix to close connection when MySqlDataReader is created with CommandBehavior.CloseConnection. (Oracle Bug #27277013)
67

78

89
6.9.10

Source/MySql.Data/command.cs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © 2004, 2015, Oracle and/or its affiliates. All rights reserved.
1+
// Copyright © 2004, 2018 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
@@ -328,7 +328,7 @@ public override int ExecuteNonQuery()
328328

329329
#if !RT
330330
// give our interceptors a shot at it first
331-
if ( connection != null &&
331+
if (connection != null &&
332332
connection.commandInterceptor != null &&
333333
connection.commandInterceptor.ExecuteNonQuery(CommandText, ref records))
334334
return records;
@@ -402,12 +402,12 @@ internal void ResetSqlSelectLimit()
402402
#if !RT
403403
// give our interceptors a shot at it first
404404
MySqlDataReader interceptedReader = null;
405-
if ( connection != null &&
406-
connection.commandInterceptor != null &&
405+
if (connection != null &&
406+
connection.commandInterceptor != null &&
407407
connection.commandInterceptor.ExecuteReader(CommandText, behavior, ref interceptedReader))
408408
return interceptedReader;
409409
#endif
410-
410+
411411
// interceptors didn't handle this so we fall through
412412
bool success = false;
413413
CheckState();
@@ -864,7 +864,7 @@ private bool AddCallStatement(string query)
864864

865865
string keyword = query.ToUpper();
866866
int indexChar = keyword.IndexOfAny(new char[] { '(', '"', '@', '\'', '`' });
867-
if(indexChar > 0)
867+
if (indexChar > 0)
868868
keyword = keyword.Substring(0, indexChar);
869869

870870
if (keywords == null)
@@ -999,15 +999,13 @@ protected override void Dispose(bool disposing)
999999
if (disposed)
10001000
return;
10011001

1002-
if (!disposing)
1003-
return;
1004-
1005-
if (statement != null && statement.IsPrepared)
1006-
statement.CloseStatement();
1002+
if (disposing)
1003+
if (statement != null && statement.IsPrepared)
1004+
statement.CloseStatement();
10071005

10081006
base.Dispose(disposing);
1009-
10101007
disposed = true;
1008+
10111009
}
10121010
#else
10131011
public void Dispose()

Source/MySql.Data/datareader.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © 2004, 2014 Oracle and/or its affiliates. All rights reserved.
1+
// Copyright © 2004, 2018 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
@@ -48,6 +48,7 @@ public sealed partial class MySqlDataReader : IDisposable
4848
internal Driver driver;
4949
private PreparableStatement statement;
5050
private ResultSet resultSet;
51+
private bool disposed = false;
5152

5253
// Used in special circumstances with stored procs to avoid exceptions from DbDataAdapter
5354
// If set, AffectedRows returns -1 instead of 0.
@@ -75,7 +76,7 @@ internal MySqlDataReader(MySqlCommand cmd, PreparableStatement statement, Comman
7576
this.statement = statement;
7677

7778
#if !RT
78-
if (cmd.CommandType == CommandType.StoredProcedure
79+
if (cmd.CommandType == CommandType.StoredProcedure
7980
&& cmd.UpdatedRowSource == UpdateRowSource.FirstReturnedRecord
8081
)
8182
{
@@ -1036,12 +1037,15 @@ private void Throw(Exception ex)
10361037
GC.SuppressFinalize(this);
10371038
}
10381039

1039-
internal new void Dispose(bool disposing)
1040+
protected override void Dispose(bool disposing)
10401041
{
1041-
if (disposing)
1042-
{
1043-
Close();
1044-
}
1042+
if (disposed)
1043+
return;
1044+
1045+
Close();
1046+
1047+
base.Dispose(disposing);
1048+
disposed = true;
10451049
}
10461050

10471051
#region Destructor

Source/MySql.Data/extensions/NonRT/MySqlConnection.cs

Lines changed: 10 additions & 4 deletions
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, 2018 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
@@ -36,6 +36,8 @@ namespace MySql.Data.MySqlClient
3636
[ToolboxItem(true)]
3737
public sealed partial class MySqlConnection : DbConnection, ICloneable
3838
{
39+
private bool disposed = false;
40+
3941
/// <summary>
4042
/// Returns schema information for the data source of this <see cref="DbConnection"/>.
4143
/// </summary>
@@ -99,19 +101,23 @@ partial void AssertPermissions()
99101
PermissionSet set = new PermissionSet(PermissionState.None);
100102
set.AddPermission(new MySqlClientPermission(ConnectionString));
101103
set.Demand();
102-
MySqlSecurityPermission.CreatePermissionSet(true).Assert();
104+
MySqlSecurityPermission.CreatePermissionSet(true).Assert();
103105
}
104106
}
105107

106108
#region IDisposeable
107-
108109
protected override void Dispose(bool disposing)
109110
{
111+
if (disposed)
112+
return;
113+
110114
if (State == ConnectionState.Open)
111115
Close();
116+
117+
disposed = true;
112118
base.Dispose(disposing);
113-
}
114119

120+
}
115121
#endregion
116122
}
117123
}

0 commit comments

Comments
 (0)