#At file:///H:/connector_net/6.2/ based on revid:vvaintroub@stripped
806 Vladislav Vaintroub 2009-11-26
Bug #31996 add-on - remove reference to MySqlConnection from Driver, to help GC find unused
connections first time through. Refactor MySqlField - it does not need ref on connection.
modified:
MySql.Data/Provider/Source/Connection.cs
MySql.Data/Provider/Source/Driver.cs
MySql.Data/Provider/Source/Field.cs
MySql.Data/Provider/Source/MySqlPool.cs
MySql.Data/Provider/Source/command.cs
MySql.Data/Tests/Source/ConnectionTests.cs
=== modified file 'MySql.Data/Provider/Source/Connection.cs'
--- a/MySql.Data/Provider/Source/Connection.cs 2009-11-25 20:32:24 +0000
+++ b/MySql.Data/Provider/Source/Connection.cs 2009-11-26 02:37:50 +0000
@@ -113,11 +113,6 @@ namespace MySql.Data.MySqlClient
}
}
- internal bool IsExecutingBuggyQuery
- {
- get { return isExecutingBuggyQuery; }
- set { isExecutingBuggyQuery = value; }
- }
internal bool SoftClosed
{
=== modified file 'MySql.Data/Provider/Source/Driver.cs'
--- a/MySql.Data/Provider/Source/Driver.cs 2009-11-25 20:32:24 +0000
+++ b/MySql.Data/Provider/Source/Driver.cs 2009-11-26 02:37:50 +0000
@@ -42,7 +42,6 @@ namespace MySql.Data.MySqlClient
protected string serverCharSet;
protected int serverCharSetIndex;
protected Hashtable serverProps;
- protected MySqlConnection connection;
protected Hashtable charSets;
protected bool hasWarnings;
protected long maxPacketSize;
@@ -85,12 +84,6 @@ namespace MySql.Data.MySqlClient
#region Properties
- public MySqlConnection Connection
- {
- get { return connection; }
- set { connection = value; }
- }
-
public int ThreadID
{
get { return handler.ThreadId; }
@@ -236,7 +229,6 @@ namespace MySql.Data.MySqlClient
public virtual void Configure(MySqlConnection connection)
{
- this.connection = connection;
bool firstConfigure = false;
// if we have not already configured our server variables
@@ -269,7 +261,7 @@ namespace MySql.Data.MySqlClient
if (serverProps.Contains("max_allowed_packet"))
maxPacketSize = Convert.ToInt64(serverProps["max_allowed_packet"]);
- LoadCharacterSets();
+ LoadCharacterSets(connection);
}
#if AUTHENTICATED
@@ -318,7 +310,7 @@ namespace MySql.Data.MySqlClient
/// Loads all the current character set names and ids for this server
/// into the charSets hashtable
/// </summary>
- private void LoadCharacterSets()
+ private void LoadCharacterSets(MySqlConnection connection)
{
MySqlCommand cmd = new MySqlCommand("SHOW COLLATION", connection);
@@ -342,7 +334,7 @@ namespace MySql.Data.MySqlClient
}
}
- public void ReportWarnings()
+ public void ReportWarnings(MySqlConnection connection)
{
ArrayList errors = new ArrayList();
@@ -416,7 +408,7 @@ namespace MySql.Data.MySqlClient
{
MySqlField[] fields = new MySqlField[count];
for (int i = 0; i < count; i++)
- fields[i] = new MySqlField(connection);
+ fields[i] = new MySqlField(this);
handler.GetColumnsData(fields);
return fields;
@@ -489,6 +481,12 @@ namespace MySql.Data.MySqlClient
GC.SuppressFinalize(this);
}
+ internal bool isExecutingBuggyQuery;
+ internal bool IsExecutingBuggyQuery
+ {
+ get { return isExecutingBuggyQuery; }
+ set { isExecutingBuggyQuery = value; }
+ }
#endregion
}
=== modified file 'MySql.Data/Provider/Source/Field.cs'
--- a/MySql.Data/Provider/Source/Field.cs 2009-11-25 15:14:35 +0000
+++ b/MySql.Data/Provider/Source/Field.cs 2009-11-26 02:37:50 +0000
@@ -70,15 +70,15 @@ namespace MySql.Data.MySqlClient
protected byte scale;
protected MySqlDbType mySqlDbType;
protected DBVersion connVersion;
- protected MySqlConnection connection;
+ protected Driver driver;
protected bool binaryOk;
#endregion
- public MySqlField(MySqlConnection connection)
+ public MySqlField(Driver driver)
{
- this.connection = connection;
- connVersion = connection.driver.Version;
+ this.driver = driver;
+ connVersion = driver.Version;
maxLength = 1;
binaryOk = true;
}
@@ -191,12 +191,12 @@ namespace MySql.Data.MySqlClient
mySqlDbType = type;
if (String.IsNullOrEmpty(TableName) && String.IsNullOrEmpty(RealTableName) &&
- connection.Settings.FunctionsReturnString)
+ driver.Settings.FunctionsReturnString)
{
mySqlDbType = MySqlDbType.VarString;
// we are treating a binary as string so we have to choose some
// charset index. Connection seems logical.
- CharacterSetIndex = connection.driver.ConnectionCharSetIndex;
+ CharacterSetIndex = driver.ConnectionCharSetIndex;
binaryOk = false;
}
@@ -230,11 +230,11 @@ namespace MySql.Data.MySqlClient
{
// handle blob to UTF8 conversion if requested. This is only activated
// on binary blobs
- if (IsBinary && connection.Settings.TreatBlobsAsUTF8)
+ if (IsBinary && driver.Settings.TreatBlobsAsUTF8)
{
bool convertBlob = false;
- Regex includeRegex = connection.Settings.GetBlobAsUTF8IncludeRegex();
- Regex excludeRegex = connection.Settings.GetBlobAsUTF8ExcludeRegex();
+ Regex includeRegex = driver.Settings.GetBlobAsUTF8IncludeRegex();
+ Regex excludeRegex = driver.Settings.GetBlobAsUTF8ExcludeRegex();
if (includeRegex != null && includeRegex.IsMatch(ColumnName))
convertBlob = true;
else if (includeRegex == null && excludeRegex != null &&
@@ -264,15 +264,15 @@ namespace MySql.Data.MySqlClient
}
// now determine if we really should be binary
- if (connection.Settings.RespectBinaryFlags)
+ if (driver.Settings.RespectBinaryFlags)
CheckForExceptions();
- if (Type == MySqlDbType.String && CharacterLength == 36 && !connection.Settings.OldGuids)
+ if (Type == MySqlDbType.String && CharacterLength == 36 && !driver.Settings.OldGuids)
mySqlDbType = MySqlDbType.Guid;
if (!IsBinary) return;
- if (connection.Settings.RespectBinaryFlags)
+ if (driver.Settings.RespectBinaryFlags)
{
if (type == MySqlDbType.String)
mySqlDbType = MySqlDbType.Binary;
@@ -282,9 +282,9 @@ namespace MySql.Data.MySqlClient
}
if (CharacterSetIndex == 63)
- CharacterSetIndex = connection.driver.ConnectionCharSetIndex;
+ CharacterSetIndex = driver.ConnectionCharSetIndex;
- if (Type == MySqlDbType.Binary && ColumnLength == 16 && connection.Settings.OldGuids)
+ if (Type == MySqlDbType.Binary && ColumnLength == 16 && driver.Settings.OldGuids)
mySqlDbType = MySqlDbType.Guid;
}
@@ -295,14 +295,14 @@ namespace MySql.Data.MySqlClient
colName = OriginalColumnName.ToUpper(CultureInfo.InvariantCulture);
if (colName.StartsWith("CHAR("))
binaryOk = false;
- else if (connection.IsExecutingBuggyQuery)
+ else if (driver.IsExecutingBuggyQuery)
binaryOk = false;
}
public IMySqlValue GetValueObject()
{
IMySqlValue v = GetIMySqlValue(Type);
- if (v is MySqlByte && ColumnLength == 1 && connection.Settings.TreatTinyAsBoolean)
+ if (v is MySqlByte && ColumnLength == 1 && driver.Settings.TreatTinyAsBoolean)
{
MySqlByte b = (MySqlByte)v;
b.TreatAsBoolean = true;
@@ -311,7 +311,7 @@ namespace MySql.Data.MySqlClient
else if (v is MySqlGuid)
{
MySqlGuid g = (MySqlGuid)v;
- g.OldGuids = connection.Settings.OldGuids;
+ g.OldGuids = driver.Settings.OldGuids;
v = g;
}
return v;
@@ -384,8 +384,8 @@ namespace MySql.Data.MySqlClient
private void SetFieldEncoding()
{
- Hashtable charSets = connection.driver.CharacterSets;
- DBVersion version = connection.driver.Version;
+ Hashtable charSets = driver.CharacterSets;
+ DBVersion version = driver.Version;
if (charSets == null || CharacterSetIndex == -1) return;
if (charSets[CharacterSetIndex] == null) return;
=== modified file 'MySql.Data/Provider/Source/MySqlPool.cs'
--- a/MySql.Data/Provider/Source/MySqlPool.cs 2009-11-25 20:32:24 +0000
+++ b/MySql.Data/Provider/Source/MySqlPool.cs 2009-11-26 02:37:50 +0000
@@ -47,7 +47,6 @@ namespace MySql.Data.MySqlClient
private void EnqueueIdle(Driver driver)
{
driver.IdleSince = DateTime.Now;
- driver.Connection = null;
idlePool.Enqueue(driver);
}
public MySqlPool(MySqlConnectionStringBuilder settings)
=== modified file 'MySql.Data/Provider/Source/command.cs'
--- a/MySql.Data/Provider/Source/command.cs 2009-11-25 15:14:35 +0000
+++ b/MySql.Data/Provider/Source/command.cs 2009-11-26 02:37:50 +0000
@@ -362,7 +362,7 @@ namespace MySql.Data.MySqlClient
// now we check to see if we are executing a query that is buggy
// in 4.1
- connection.IsExecutingBuggyQuery = false;
+ connection.driver.IsExecutingBuggyQuery = false;
if (!connection.driver.Version.isAtLeast(5, 0, 0) &&
connection.driver.Version.isAtLeast(4, 1, 0))
{
@@ -370,7 +370,7 @@ namespace MySql.Data.MySqlClient
if (snippet.Length > 17)
snippet = sql.Substring(0, 17);
snippet = snippet.ToUpper(CultureInfo.InvariantCulture);
- connection.IsExecutingBuggyQuery =
+ connection.driver.IsExecutingBuggyQuery =
snippet.StartsWith("DESCRIBE") ||
snippet.StartsWith("SHOW TABLE STATUS");
}
=== modified file 'MySql.Data/Tests/Source/ConnectionTests.cs'
--- a/MySql.Data/Tests/Source/ConnectionTests.cs 2009-11-25 20:32:24 +0000
+++ b/MySql.Data/Tests/Source/ConnectionTests.cs 2009-11-26 02:37:50 +0000
@@ -379,15 +379,20 @@ namespace MySql.Data.MySqlClient.Tests
[Test]
public void ConnectionCloseByGC()
{
+ int threadId;
ConnectionClosedCheck check = new ConnectionClosedCheck();
- string connStr = GetConnectionString(true);
+ string connStr = GetConnectionString(true)+";pooling=true";
MySqlConnection c = new MySqlConnection(connStr);
c.StateChange += new StateChangeEventHandler(check.stateChangeHandler);
c.Open();
+ threadId= c.ServerThread;
c = null;
GC.Collect();
GC.WaitForPendingFinalizers();
Assert.IsTrue(check.closed);
+
+ MySqlCommand cmd = new MySqlCommand("KILL " + threadId, conn);
+ cmd.ExecuteNonQuery();
}
/// <summary>
/// Bug #30964 StateChange imperfection
Attachment: [text/bzr-bundle] bzr/vvaintroub@mysql.com-20091126023750-v8c0pc5wr14c8e1p.bundle
| Thread |
|---|
| • bzr commit into connector-net-trunk branch (vvaintroub:806) Bug#31996 | Vladislav Vaintroub | 26 Nov |