Modified:
trunk/CHANGES
trunk/MySql.Data.2005.csproj
trunk/mysqlclient/Connection.cs
trunk/mysqlclient/ConnectionString.cs
trunk/mysqlclient/common/DBConnectionString.cs
Log:
Removed use of hashes in DBConnectionString and MySqlConnectionString. This improves the speed of these classes
and improves their type specificity and clarity. Now the classes simply parse the values and store them in member fields.
Modified: trunk/CHANGES
===================================================================
--- trunk/CHANGES 2006-04-11 17:24:07 UTC (rev 214)
+++ trunk/CHANGES 2006-04-12 20:08:10 UTC (rev 215)
@@ -1,4 +1,4 @@
-- Version 1.1.0
+- Version 5.0
Bug #6214 CommandText: Question mark in comment line is being parsed as a parameter [fixed]
Implemented intial usage advisor
Merged cursor support in
@@ -7,6 +7,8 @@
Reimplemented PacketReader/PacketWriter support into MySqlStream* classes
Embedded server is now working (libmysqld.dll)
Added internal implemention of SHA1 so we don't have to distribute the OpenNetCF on mobile devices
+ Added usage advisor warnings for requesting column values by the wrong type
+ Reworked connection string classes to be simpler and faster
8-24-05 - Version 1.0.5
Modified: trunk/MySql.Data.2005.csproj
===================================================================
--- trunk/MySql.Data.2005.csproj 2006-04-11 17:24:07 UTC (rev 214)
+++ trunk/MySql.Data.2005.csproj 2006-04-12 20:08:10 UTC (rev 215)
@@ -134,6 +134,7 @@
<Compile Include="MySqlClient\common\Platform.cs">
<SubType>Code</SubType>
</Compile>
+ <Compile Include="MySqlClient\common\ProcedureCache.cs" />
<Compile Include="MySqlClient\common\Resources.cs" />
<Compile Include="MySqlClient\common\SHA1.cs" />
<Compile Include="MySqlClient\common\SocketStream.cs" />
@@ -205,6 +206,7 @@
<Compile Include="MySqlClient\NativeDriver.cs">
<SubType>Code</SubType>
</Compile>
+ <Compile Include="MySqlClient\NonISSchemaProvider.cs" />
<Compile Include="MySqlClient\parameter.cs">
<SubType>Code</SubType>
</Compile>
@@ -214,6 +216,7 @@
<Compile Include="MySqlClient\PreparedStatement.cs">
<SubType>Code</SubType>
</Compile>
+ <Compile Include="MySqlClient\ISSchemaProvider.cs" />
<Compile Include="MySqlClient\SchemaProvider.cs" />
<Compile Include="MySqlClient\SharedMemoryStream.cs">
<SubType>Code</SubType>
Modified: trunk/mysqlclient/Connection.cs
===================================================================
--- trunk/mysqlclient/Connection.cs 2006-04-11 17:24:07 UTC (rev 214)
+++ trunk/mysqlclient/Connection.cs 2006-04-12 20:08:10 UTC (rev 215)
@@ -43,6 +43,8 @@
private MySqlConnectionString settings;
private UsageAdvisor advisor;
private bool hasBeenOpen;
+ private SchemaProvider schemaProvider;
+ private ProcedureCache procedureCache;
/// <include file='docs/MySqlConnection.xml' path='docs/InfoMessage/*'/>
public event MySqlInfoMessageEventHandler InfoMessage;
@@ -53,7 +55,6 @@
{
//TODO: add event data to StateChange docs
settings = new MySqlConnectionString();
- settings.LoadDefaultValues();
advisor = new UsageAdvisor( this );
}
@@ -65,6 +66,11 @@
#region Interal Methods & Properties
+ internal ProcedureCache ProcedureCache
+ {
+ get { return procedureCache; }
+ }
+
internal MySqlConnectionString Settings
{
get { return settings; }
@@ -202,9 +208,17 @@
if (this.State != ConnectionState.Closed)
throw new MySqlException("Not allowed to change the 'ConnectionString' property while the connection (state=" + State + ").");
- settings.SetConnectionString(value);
- if ( driver != null)
- driver.Settings = settings;
+ try
+ {
+ MySqlConnectionString newSettings = new MySqlConnectionString(value);
+ settings = newSettings;
+ if (driver != null)
+ driver.Settings = newSettings;
+ }
+ catch (Exception)
+ {
+ throw;
+ }
}
}
@@ -294,22 +308,25 @@
throw new InvalidOperationException(
Resources.GetString("ConnectionAlreadyOpen"));
- SetState( ConnectionState.Connecting );
+ SetState(ConnectionState.Connecting);
try
{
if (settings.Pooling)
{
- driver = MySqlPoolManager.GetConnection( settings );
+ MySqlPool pool = MySqlPoolManager.GetPool(settings);
+ driver = pool.GetConnection();
+ procedureCache = pool.ProcedureCache;
}
else
{
- driver = Driver.Create( settings );
+ driver = Driver.Create(settings);
+ procedureCache = new ProcedureCache(settings.ProcedureCacheSize);
}
}
- catch (Exception ex)
+ catch (Exception)
{
- SetState( ConnectionState.Closed );
+ SetState(ConnectionState.Closed);
throw;
}
@@ -317,10 +334,10 @@
if ( driver.Settings.UseOldSyntax)
Logger.LogWarning("You are using old syntax that will be removed in future versions");
- SetState( ConnectionState.Open );
- driver.Configure( this );
+ SetState(ConnectionState.Open);
+ driver.Configure(this);
if (settings.Database != null && settings.Database != String.Empty)
- ChangeDatabase( settings.Database );
+ ChangeDatabase(settings.Database);
hasBeenOpen = true;
}
@@ -399,14 +416,12 @@
public override DataTable GetSchema(string collectionName)
{
- SchemaProvider sp = new SchemaProvider(this);
- return sp.GetSchema(collectionName, null);
+ return schemaProvider.GetSchema(collectionName, null);
}
public override DataTable GetSchema(string collectionName, string[] restrictionValues)
{
- SchemaProvider sp = new SchemaProvider(this);
- return sp.GetSchema(collectionName, restrictionValues);
+ return schemaProvider.GetSchema(collectionName, restrictionValues);
}
#endregion
Modified: trunk/mysqlclient/ConnectionString.cs
===================================================================
--- trunk/mysqlclient/ConnectionString.cs 2006-04-11 17:24:07 UTC (rev 214)
+++ trunk/mysqlclient/ConnectionString.cs 2006-04-12 20:08:10 UTC (rev 215)
@@ -49,56 +49,54 @@
/// </summary>
internal sealed class MySqlConnectionString : DBConnectionString
{
- private Hashtable defaults;
+ private bool useUsageAdvisor;
+ private int procedureCacheSize;
+ private string charSet;
+ private ConnectionProtocol protocol;
+ private bool compress;
+ private string pipeName;
+ private bool allowBatch;
+ private bool logging;
+ private string sharedMemoryName;
+ private bool supportOldSyntax;
+ private string optionFile;
+ private bool useSSL;
+ private DriverType driverType;
+ private bool allowZeroDateTime;
+ private bool convertZeroDateTime;
public MySqlConnectionString() : base()
{
+ useUsageAdvisor = false;
+ procedureCacheSize = 25;
+ protocol = ConnectionProtocol.Sockets;
+ compress = false;
+ allowBatch = true;
+ pipeName = "MYSQL";
+ logging = false;
+ sharedMemoryName = "MYSQL";
+ supportOldSyntax = false;
+ useSSL = false;
+ driverType = DriverType.Native;
+ allowZeroDateTime = true;
+ convertZeroDateTime = true;
}
- public MySqlConnectionString(string connectString) : this()
+ public MySqlConnectionString(string connectString) : base(connectString)
{
- SetConnectionString( connectString );
+ Parse();
}
#region Server Properties
-/* public string Name
- {
- get { return connectionName; }
- set { connectionName = value; }
- }
-*/
-
#if DESIGN
[Category("Connection")]
- [Description("The name or IP address of the server to use")]
-#endif
- public string Server
- {
- get { return GetString("host"); }
-// set { keyValues["host"] = value; }
- }
-
-#if DESIGN
- [Category("Connection")]
- [Description("Port to use when connecting with sockets")]
- [DefaultValue(3306)]
-#endif
- public uint Port
- {
- get { return (uint)GetInt("port"); }
-// set { keyValues["port"] = value; }
- }
-
-#if DESIGN
- [Category("Connection")]
[Description("Protocol to use for connection to MySQL")]
[DefaultValue(ConnectionProtocol.Sockets)]
#endif
public ConnectionProtocol Protocol
{
- get { return (ConnectionProtocol)keyValues["protocol"]; }
-// set { keyValues["protocol"] = value; }
+ get { return protocol; }
}
#if DESIGN
@@ -107,8 +105,7 @@
#endif
public string PipeName
{
- get { return GetString("pipeName"); }
-// set { keyValues["pipeName"] = value; }
+ get { return pipeName; }
}
#if DESIGN
@@ -118,31 +115,10 @@
#endif
public bool UseCompression
{
- get { return GetBool("compress"); }
-// set { keyValues["compress"] = value; }
+ get { return compress; }
}
-#if DESIGN
- [Category("Connection")]
- [Description("Database to use initially")]
- [Editor("MySql.Data.MySqlClient.Design.DatabaseTypeEditor,MySqlClient.Design", typeof(System.Drawing.Design.UITypeEditor))]
-#endif
- public string Database
- {
- get { return GetString("database"); }
- set { keyValues["database"] = value; }
- }
-#if DESIGN
- [Category("Connection")]
- [Description("Number of seconds to wait for the connection to succeed")]
- [DefaultValue(15)]
-#endif
- public int ConnectionTimeout
- {
- get { return GetInt("connect timeout"); }
-// set { keyValues["connect timeout"] = value; }
- }
#if DESIGN
[Category("Connection")]
@@ -151,8 +127,7 @@
#endif
public bool AllowBatch
{
- get { return GetBool("allow batch"); }
-// set { keyValues["allow batch"] = value; }
+ get { return allowBatch; }
}
#if DESIGN
@@ -162,8 +137,7 @@
#endif
public bool Logging
{
- get { return GetBool("logging"); }
-// set { keyValues["logging"] = value; }
+ get { return logging; }
}
#if DESIGN
@@ -173,8 +147,7 @@
#endif
public string SharedMemoryName
{
- get { return GetString("memname"); }
-// set { keyValues["memname"] = value; }
+ get { return sharedMemoryName; }
}
#if DESIGN
@@ -184,8 +157,7 @@
#endif
public bool UseOldSyntax
{
- get { return GetBool("oldsyntax"); }
-// set { keyValues["oldsyntax"] = value; }
+ get { return supportOldSyntax; }
}
#if DESIGN
@@ -195,14 +167,12 @@
#endif
public DriverType DriverType
{
- get { return (DriverType)keyValues["driver"]; }
-// set { keyValues["driver"] = value; }
+ get { return driverType; }
}
public string OptionFile
{
- get { return keyValues["option_file"] as string; }
-// set { keyValues["option_file"] = value; }
+ get { return optionFile; }
}
#endregion
@@ -211,95 +181,16 @@
#if DESIGN
[Category("Authentication")]
- [Description("The username to connect as")]
-#endif
- public string UserId
- {
- get { return GetString("user id"); }
-// set { keyValues["user id"] = value; }
- }
-
-#if DESIGN
- [Category("Authentication")]
- [Description("The password to use for authentication")]
-#endif
- public string Password
- {
- get { return GetString("password"); }
-// set { keyValues["password"] = value; }
- }
-
-#if DESIGN
- [Category("Authentication")]
[Description("Should the connection use SSL. This currently has no effect.")]
[DefaultValue(false)]
#endif
public bool UseSSL
{
- get { return GetBool("useSSL"); }
-// set { keyValues["useSSL"] = value; }
+ get { return useSSL; }
}
-#if DESIGN
- [Category("Authentication")]
- [Description("Show user password in connection string")]
- [DefaultValue(false)]
-#endif
- public bool PersistSecurityInfo
- {
- get { return GetBool("persist security info"); }
-// set { keyValues["persist security info"] = value; }
- }
#endregion
- #region Pooling Properties
-
-#if DESIGN
- [Category("Pooling")]
- [Description("Should the connection support pooling")]
- [DefaultValue(true)]
-#endif
- public bool Pooling
- {
- get { return GetBool("pooling"); }
-// set { keyValues["pooling"] = value; }
- }
-
-#if DESIGN
- [Category("Pooling")]
- [Description("Minimum number of connections to have in this pool")]
- [DefaultValue(0)]
-#endif
- public int MinPoolSize
- {
- get { return GetInt("min pool size"); }
-// set { keyValues["min pool size"] = value; }
- }
-
-#if DESIGN
- [Category("Pooling")]
- [Description("Maximum number of connections to have in this pool")]
- [DefaultValue(100)]
-#endif
- public int MaxPoolSize
- {
- get { return GetInt("max pool size"); }
-// set { keyValues["max pool size"] = value; }
- }
-
-#if DESIGN
- [Category("Pooling")]
- [Description("Maximum number of seconds a connection should live. This is checked when a connection is returned to the pool.")]
- [DefaultValue(0)]
-#endif
- public int ConnectionLifetime
- {
- get { return GetInt("connect lifetime"); }
-// set { keyValues["connect lifetime"] = value; }
- }
-
- #endregion
-
#region Other Properties
#if DESIGN
@@ -309,8 +200,7 @@
#endif
public bool AllowZeroDateTime
{
- get { return GetBool("allowzerodatetime"); }
-// set { keyValues["alllowzerodatetime"] = value; }
+ get { return allowZeroDateTime; }
}
#if DESIGN
@@ -320,8 +210,7 @@
#endif
public bool ConvertZeroDateTime
{
- get { return GetBool("convertzerodatetime"); }
-// set { keyValues["convertzerodatetime"] = value; }
+ get { return convertZeroDateTime; }
}
#if DESIGN
@@ -331,8 +220,7 @@
#endif
public string CharacterSet
{
- get { return GetString("charset"); }
-// set { keyValues["charset"] = value; }
+ get { return charSet; }
}
#if DESIGN
@@ -342,10 +230,19 @@
#endif
public bool UseUsageAdvisor
{
- get { return GetBool("usageAdvisor"); }
-// set { keyValues["usageAdvisor"] = value; }
+ get { return useUsageAdvisor; }
}
+#if DESIGN
+ [Category("Other")]
+ [Description("Number of stored procedures to cache. 0 to disable.")]
+ [DefaultValue(25)]
+#endif
+ public int ProcedureCacheSize
+ {
+ get { return procedureCacheSize; }
+ }
+
#endregion
/// <summary>
@@ -369,74 +266,8 @@
return RemoveKeys(connStr, new string[2] { "password", "pwd" });
}
- /// <summary>
- /// Uses the values in the keyValues hash to create a
- /// connection string
- /// </summary>
- /// <returns></returns>
-/* public string CreateConnectionString()
+ protected override bool ConnectionParameterParsed(string key, string value)
{
- string cStr = String.Empty;
-
- Hashtable values = (Hashtable)keyValues.Clone();
- Hashtable defaultValues = GetDefaultValues();
-
- if (!PersistSecurityInfo && values.Contains("password") )
- values.Remove( "password" );
-
- // we always return the server key. It's not needed but
- // seems weird for it not to be there.
- cStr = "server=" + values["host"] + ";";
- values.Remove("server");
-
- foreach (string key in values.Keys)
- {
- if (values[key] != null && defaultValues[key] != null &&
- !values[key].Equals( defaultValues[key]))
- cStr += key + "=" + values[key] + ";";
- }
-
- return cStr;
- }
-*/
- protected override Hashtable GetDefaultValues()
- {
- defaults = base.GetDefaultValues();
- if (defaults == null)
- {
- defaults = new Hashtable(new CaseInsensitiveHashCodeProvider(),
- new CaseInsensitiveComparer());
- defaults["host"] = String.Empty;
- defaults["connect lifetime"] = 0;
- defaults["user id"] = String.Empty;
- defaults["password"] = String.Empty;
- defaults["database"] = null;
- defaults["charset"] = null;
- defaults["pooling"] = true;
- defaults["min pool size"] = 0;
- defaults["protocol"] = ConnectionProtocol.Sockets;
- defaults["max pool size"] = 100;
- defaults["connect timeout"] = 15;
- defaults["port"] = 3306;
- defaults["useSSL"] = false;
- defaults["compress"] = false;
- defaults["persist security info"] = false;
- defaults["allow batch"] = true;
- defaults["logging"] = false;
- defaults["oldsyntax"] = false;
- defaults["pipeName"] = "MySQL";
- defaults["memname"] = "MYSQL";
- defaults["allowzerodatetime"] = false;
- defaults["usageAdvisor"] = false;
- defaults["driver"] = DriverType.Native;
- defaults["option_file"] = null;
- defaults["convertzerodatetime"] = false;
- }
- return (Hashtable)defaults.Clone();
- }
-
- protected override bool ConnectionParameterParsed(Hashtable hash, string key, string value)
- {
string lowerCaseKey = key.ToLower();
string lowerCaseValue = value.Trim().ToLower();
bool boolVal = lowerCaseValue == "yes" || lowerCaseValue == "true";
@@ -444,81 +275,88 @@
switch (lowerCaseKey)
{
case "option file":
- hash["option_file"] = value;
+ optionFile = value;
return true;
case "driver":
string d = value.ToLower();
if (d == "native")
- hash["driver"] = DriverType.Native;
+ driverType = DriverType.Native;
else if (d == "client")
- hash["driver"] = DriverType.Client;
+ driverType = DriverType.Client;
else if (d == "embedded")
- hash["driver"] = DriverType.Emebedded;
+ driverType = DriverType.Emebedded;
else
throw new ArgumentException("Unknown driver type: " + value);
return true;
case "usage advisor":
case "useusageadvisor":
- hash["usageAdvisor"] = boolVal;
+ useUsageAdvisor = boolVal;
return true;
case "character set":
case "charset":
- hash["charset"] = value;
+ charSet = value;
return true;
case "use compression":
case "compress":
- hash["compress"] = boolVal;
+ compress = boolVal;
return true;
case "protocol":
if (value == "socket" || value == "tcp")
- hash["protocol"] = ConnectionProtocol.Sockets;
+ protocol = ConnectionProtocol.Sockets;
else if (value == "pipe")
- hash["protocol"] = ConnectionProtocol.NamedPipe;
+ protocol = ConnectionProtocol.NamedPipe;
else if (value == "unix")
- hash["protocol"] = ConnectionProtocol.UnixSocket;
+ protocol = ConnectionProtocol.UnixSocket;
else if (value == "memory")
- hash["protocol"] = ConnectionProtocol.SharedMemory;
+ protocol = ConnectionProtocol.SharedMemory;
return true;
case "pipe name":
case "pipe":
- hash["pipeName"] = value;
+ pipeName = value;
return true;
case "allow batch":
- hash["allow batch"] = boolVal;
+ allowBatch = boolVal;
return true;
case "logging":
- hash["logging"] = boolVal;
+ logging = boolVal;
return true;
case "shared memory name":
- hash["memname"] = value;
+ sharedMemoryName = value;
return true;
case "old syntax":
case "oldsyntax":
- hash["oldsyntax"] = boolVal;
+ supportOldSyntax = boolVal;
return true;
case "convert zero datetime":
case "convertzerodatetime":
- hash["convertzerodatetime"] = boolVal;
+ convertZeroDateTime = boolVal;
return true;
case "allow zero datetime":
case "allowzerodatetime":
- hash["allowzerodatetime"] = boolVal;
+ allowZeroDateTime = boolVal;
return true;
+
+ case "procedure cache size":
+ case "procedurecachesize":
+ case "procedure cache":
+ case "procedurecache":
+ procedureCacheSize = Int32.Parse(value);
+ return true;
}
- if (! base.ConnectionParameterParsed(hash, key, value))
+ if (! base.ConnectionParameterParsed(key, value))
throw new ArgumentException("Keyword not supported: '" + key + "'");
return true;
}
Modified: trunk/mysqlclient/common/DBConnectionString.cs
===================================================================
--- trunk/mysqlclient/common/DBConnectionString.cs 2006-04-11 17:24:07 UTC (rev 214)
+++ trunk/mysqlclient/common/DBConnectionString.cs 2006-04-12 20:08:10 UTC (rev 215)
@@ -19,8 +19,6 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
using System;
-using System.Collections;
-using System.Text;
namespace MySql.Data.Common
{
@@ -29,48 +27,151 @@
/// </summary>
internal abstract class DBConnectionString
{
- protected Hashtable keyValues;
- protected string connectionName = String.Empty;
- protected string connectString;
+ protected string connectString;
+ protected bool persistSecurityInfo;
+ protected string userId;
+ protected string password;
+ protected string host;
+ protected string database;
+ protected int connectionTimeout;
+ protected uint port;
+ protected bool pooling;
+ protected int minPoolSize;
+ protected int maxPoolSize;
+ protected int poolLifeTime;
public DBConnectionString()
{
- keyValues = new Hashtable(new CaseInsensitiveHashCodeProvider(),
- new CaseInsensitiveComparer());
- }
+ persistSecurityInfo = false;
+ connectionTimeout = 15;
+ pooling = true;
+ minPoolSize = 0;
+ maxPoolSize = 100;
+ port = 3306;
+ }
+
+ public DBConnectionString(string connectString) : this()
+ {
+ this.connectString = connectString;
+ }
+
+ #region Base Connection Properties
+
+#if DESIGN
+ [Category("Connection")]
+ [Description("The name or IP address of the server to use")]
+#endif
+ public string Server
+ {
+ get { return host; }
+ }
+
+#if DESIGN
+ [Category("Connection")]
+ [Description("Port to use when connecting with sockets")]
+ [DefaultValue(3306)]
+#endif
+ public uint Port
+ {
+ get { return port; }
+ }
+
+#if DESIGN
+ [Category("Connection")]
+ [Description("Database to use initially")]
+ [Editor("MySql.Data.MySqlClient.Design.DatabaseTypeEditor,MySqlClient.Design", typeof(System.Drawing.Design.UITypeEditor))]
+#endif
+ public string Database
+ {
+ get { return database; }
+ set { database = value; }
+ }
+
+#if DESIGN
+ [Category("Connection")]
+ [Description("Number of seconds to wait for the connection to succeed")]
+ [DefaultValue(15)]
+#endif
+ public int ConnectionTimeout
+ {
+ get { return connectionTimeout; }
+ }
+
+#if DESIGN
+ [Category("Authentication")]
+ [Description("Show user password in connection string")]
+ [DefaultValue(false)]
+#endif
+ public bool PersistSecurityInfo
+ {
+ get { return persistSecurityInfo; }
+ }
+
+#if DESIGN
+ [Category("Authentication")]
+ [Description("The username to connect as")]
+#endif
+ public string UserId
+ {
+ get { return userId; }
+ }
+
+#if DESIGN
+ [Category("Authentication")]
+ [Description("The password to use for authentication")]
+#endif
+ public string Password
+ {
+ get { return password; }
+ }
+
+
+#endregion
+
+ #region Pooling Properties
+
+#if DESIGN
+ [Category("Pooling")]
+ [Description("Should the connection support pooling")]
+ [DefaultValue(true)]
+#endif
+ public bool Pooling
+ {
+ get { return pooling; }
+ }
+
+#if DESIGN
+ [Category("Pooling")]
+ [Description("Minimum number of connections to have in this pool")]
+ [DefaultValue(0)]
+#endif
+ public int MinPoolSize
+ {
+ get { return minPoolSize; }
+ }
+
+#if DESIGN
+ [Category("Pooling")]
+ [Description("Maximum number of connections to have in this pool")]
+ [DefaultValue(100)]
+#endif
+ public int MaxPoolSize
+ {
+ get { return maxPoolSize; }
+ }
+
+#if DESIGN
+ [Category("Pooling")]
+ [Description("Maximum number of seconds a connection should live. This is checked when a connection is returned to the pool.")]
+ [DefaultValue(0)]
+#endif
+ public int ConnectionLifetime
+ {
+ get { return poolLifeTime; }
+ }
+
+ #endregion
- public void LoadDefaultValues()
- {
- keyValues = GetDefaultValues();
- }
-
- public void SetConnectionString(string value)
- {
- Hashtable ht = Parse(value);
- connectString = value;
- keyValues = ht;
- }
-
- protected string GetString(string name)
- {
- if (! keyValues.ContainsKey(name)) return String.Empty;
- if (keyValues[name] == null) return String.Empty;
- return (keyValues[name] as string);
- }
-
- protected int GetInt( string name )
- {
- return Convert.ToInt32(keyValues[name], System.Globalization.NumberFormatInfo.InvariantInfo);
- }
-
- protected bool GetBool( string name )
- {
- object val = keyValues[name];
- if (val.Equals(true) || val.Equals("true") || val.Equals("yes") || val.Equals(1))
- return true;
- return false;
- }
-
protected string RemoveKeys(string value, string[] keys)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
@@ -87,27 +188,27 @@
return sb.ToString();
}
- protected virtual bool ConnectionParameterParsed(Hashtable hash, string key, string value)
+ protected virtual bool ConnectionParameterParsed(string key, string value)
{
string lowerKey = key.ToLower(System.Globalization.CultureInfo.InvariantCulture);
switch (lowerKey)
{
- case "persist security info":
- hash["persist security info"] = value;
+ case "persist security info":
+ persistSecurityInfo = value.ToLower() == "yes" || value.ToLower() == "true";
return true;
case "uid":
case "username":
case "user id":
case "user name":
- case "userid":
- hash["user id"] = value;
+ case "userid":
+ userId = value;
return true;
case "password":
- case "pwd":
- hash["password"] = value;
+ case "pwd":
+ password = value;
return true;
case "host":
@@ -116,104 +217,89 @@
case "datasource":
case "address":
case "addr":
- case "network address":
- hash["host"] = value;
+ case "network address":
+ host = value;
return true;
case "initial catalog":
- case "database":
- hash["database"] = value;
+ case "database":
+ database = value;
return true;
case "connection timeout":
case "connect timeout":
- hash["connect timeout"] = Int32.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
+ connectionTimeout = Int32.Parse(value,
+ System.Globalization.NumberFormatInfo.InvariantInfo);
return true;
case "port":
- hash["port"] = Int32.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
+ port = UInt32.Parse(value,
+ System.Globalization.NumberFormatInfo.InvariantInfo);
return true;
case "pooling":
- hash["pooling"] =
- value.ToLower() == "yes" || value.ToLower() == "true";
+ pooling = value.ToLower() == "yes" || value.ToLower() == "true";
return true;
case "min pool size":
- hash["min pool size"] = Int32.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
+ minPoolSize = Int32.Parse(value,
+ System.Globalization.NumberFormatInfo.InvariantInfo);
return true;
case "max pool size":
- hash["max pool size"] = Int32.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
+ maxPoolSize = Int32.Parse(value,
+ System.Globalization.NumberFormatInfo.InvariantInfo);
return true;
case "connection lifetime":
- hash["connect lifetime"] = Int32.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
+ poolLifeTime = Int32.Parse(value,
+ System.Globalization.NumberFormatInfo.InvariantInfo);
return true;
}
return false;
}
- protected virtual Hashtable GetDefaultValues()
- {
- return null;
- }
+ protected virtual void Parse()
+ {
+ String[] keyvalues = connectString.Split(';');
+ String[] newkeyvalues = new String[keyvalues.Length];
+ int x = 0;
+
+ // first run through the array and check for any keys that
+ // have ; in their value
+ foreach (String keyvalue in keyvalues)
+ {
+ // check for trailing ; at the end of the connection string
+ if (keyvalue.Length == 0) continue;
+
+ // this value has an '=' sign so we are ok
+ if (keyvalue.IndexOf('=') >= 0)
+ {
+ newkeyvalues[x++] = keyvalue;
+ }
+ else
+ {
+ newkeyvalues[x - 1] += ";";
+ newkeyvalues[x - 1] += keyvalue;
+ }
+ }
+
+ // now we run through our normalized key-values, splitting on equals
+ for (int y = 0; y < x; y++)
+ {
+ String[] parts = newkeyvalues[y].Split('=');
+
+ // first trim off any space and lowercase the key
+ parts[0] = parts[0].Trim().ToLower();
+ parts[1] = parts[1].Trim();
+
+ // we also want to clear off any quotes
+ parts[0] = parts[0].Trim('\'', '"');
+ parts[1] = parts[1].Trim('\'', '"');
+
+ ConnectionParameterParsed(parts[0], parts[1]);
+ }
+ }
- protected static Hashtable ParseKeyValuePairs(string src)
- {
- String[] keyvalues = src.Split(';');
- String[] newkeyvalues = new String[keyvalues.Length];
- int x = 0;
-
- // first run through the array and check for any keys that
- // have ; in their value
- foreach (String keyvalue in keyvalues)
- {
- // check for trailing ; at the end of the connection string
- if (keyvalue.Length == 0) continue;
-
- // this value has an '=' sign so we are ok
- if (keyvalue.IndexOf('=') >= 0)
- {
- newkeyvalues[x++] = keyvalue;
- }
- else
- {
- newkeyvalues[x-1] += ";";
- newkeyvalues[x-1] += keyvalue;
- }
- }
-
- Hashtable hash = new Hashtable();
-
- // now we run through our normalized key-values, splitting on equals
- for (int y=0; y < x; y++)
- {
- String[] parts = newkeyvalues[y].Split('=');
-
- // first trim off any space and lowercase the key
- parts[0] = parts[0].Trim().ToLower();
- parts[1] = parts[1].Trim();
-
- // we also want to clear off any quotes
- parts[0] = parts[0].Trim('\'', '"');
- parts[1] = parts[1].Trim('\'', '"');
-
- hash[parts[0]] = parts[1];
- }
- return hash;
- }
-
- protected virtual Hashtable Parse(string newConnectString)
- {
- Hashtable hash = ParseKeyValuePairs( newConnectString );
- Hashtable newHash = GetDefaultValues();
-
- foreach (object key in hash.Keys)
- ConnectionParameterParsed( newHash, (string)key, (string)hash[key] );
- return newHash;
- }
-
-
}
}
| Thread |
|---|
| • Connector/NET commit: r215 - in trunk: . mysqlclient mysqlclient/common | rburnett | 12 Apr |