Skip to content

Commit

Permalink
A bunch of fixes to make mysql.data.tests suite pass
Browse files Browse the repository at this point in the history
-  Related to connection string builder functionality (default values, etc.)
-  New accounting for semantics difference between Hashtable and Dictionary.
- Other minor issues to make unit tests compile.
- Some unit tests pass in .NET now.
  • Loading branch information
fer-gonzalez-sanchez committed Apr 11, 2013
1 parent 9e6c47a commit c145642
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 54 deletions.
97 changes: 61 additions & 36 deletions Source/MySql.Data/MySqlConnectionStringBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,20 @@ static MySqlConnectionStringBuilder()
options.Add(new MySqlConnectionStringOption("server", "host,data source,datasource,address,addr,network address", typeof(string), "localhost", false));
options.Add(new MySqlConnectionStringOption("database", "initial catalog", typeof(string), null, false));
options.Add(new MySqlConnectionStringOption("protocol", "connection protocol, connectionprotocol", typeof(MySqlConnectionProtocol), MySqlConnectionProtocol.Sockets, false));
options.Add(new MySqlConnectionStringOption("port", null, typeof(uint), 3306, false));
options.Add(new MySqlConnectionStringOption("port", null, typeof(uint), ( uint )3306, false));
options.Add(new MySqlConnectionStringOption("pipe", "pipe name,pipename", typeof(string), "MYSQL", false));
options.Add(new MySqlConnectionStringOption("compress", "use compression,usecompression", typeof(bool), false, false));
options.Add(new MySqlConnectionStringOption("allow batch", "allowbatch", typeof(bool), true, false));
options.Add(new MySqlConnectionStringOption("allowbatch", "allowbatch", typeof(bool), true, false));
options.Add(new MySqlConnectionStringOption("logging", null, typeof(bool), false, false));
options.Add(new MySqlConnectionStringOption("shared memory name", "sharedmemoryname", typeof(string), "MYSQL", false));
options.Add(new MySqlConnectionStringOption("sharedmemoryname", "sharedmemoryname", typeof(string), "MYSQL", false));
options.Add(new MySqlConnectionStringOption("useoldsyntax", "old syntax,oldsyntax,use old syntax", typeof(bool), false, true));
options.Add(new MySqlConnectionStringOption("connectiontimeout", "connection timeout,connect timeout", typeof(uint), 15, false));
options.Add(new MySqlConnectionStringOption("defaultcommandtimeout", "command timeout,default command timeout", typeof(uint), 30, false));
options.Add(new MySqlConnectionStringOption("connectiontimeout", "connection timeout,connect timeout", typeof(uint), ( uint )15, false));
options.Add(new MySqlConnectionStringOption("defaultcommandtimeout", "command timeout,default command timeout", typeof(uint), ( uint )30, false));
options.Add(new MySqlConnectionStringOption("usedefaultcommandtimeoutforef", "use default command timeout for ef", typeof(bool), false, false));

// authentication options
options.Add(new MySqlConnectionStringOption("userid", "uid,username,user name,user,user id", typeof(string), null, false));
options.Add(new MySqlConnectionStringOption("password", "pwd", typeof(string), null, false));
options.Add(new MySqlConnectionStringOption("password", "pwd", typeof(string), "", false));
options.Add(new MySqlConnectionStringOption("persistsecurityinfo", "persist security info", typeof(bool), false, false));
#if !CF
options.Add(new MySqlConnectionStringOption("encrypt", null, typeof(bool), false, true));
Expand All @@ -48,7 +49,7 @@ static MySqlConnectionStringBuilder()
options.Add(new MySqlConnectionStringOption("allowzerodatetime", "allow zero datetime", typeof(bool), false, false));
options.Add(new MySqlConnectionStringOption("convertzerodatetime", "convert zero datetime", typeof(bool), false, false));
options.Add(new MySqlConnectionStringOption("useusageadvisor", "use usage advisor,usage advisor", typeof(bool), false, false));
options.Add(new MySqlConnectionStringOption("procedurecachesize", "procedure cache size,procedure cache,procedurecache", typeof(uint), 25, false));
options.Add(new MySqlConnectionStringOption("procedurecachesize", "procedure cache size,procedure cache,procedurecache", typeof(uint), ( uint )25, false));
options.Add(new MySqlConnectionStringOption("useperformancemonitor", "use performance monitor,useperfmon,perfmon", typeof(bool), false, false));
options.Add(new MySqlConnectionStringOption("ignoreprepare", "ignore prepare", typeof(bool), true, false));
options.Add(new MySqlConnectionStringOption("useprocedurebodies", "use procedure bodies,procedure bodies", typeof(bool), true, true));
Expand All @@ -60,31 +61,31 @@ static MySqlConnectionStringBuilder()
options.Add(new MySqlConnectionStringOption("functionsreturnstring", "functions return string", typeof(bool), false, false));
options.Add(new MySqlConnectionStringOption("useaffectedrows", "use affected rows", typeof(bool), false, false));
options.Add(new MySqlConnectionStringOption("oldguids", "old guids", typeof(bool), false, false));
options.Add(new MySqlConnectionStringOption("keepalive", "keep alive", typeof(uint), 0, false));
options.Add(new MySqlConnectionStringOption("keepalive", "keep alive", typeof(uint), (uint)0, false));
options.Add(new MySqlConnectionStringOption("sqlservermode", "sql server mode", typeof(bool), false, false));
options.Add(new MySqlConnectionStringOption("tablecaching", "table cache,tablecache", typeof(bool), false, false));
options.Add(new MySqlConnectionStringOption("defaulttablecacheage", "default table cache age", typeof(uint), 60, false));
options.Add(new MySqlConnectionStringOption("defaulttablecacheage", "default table cache age", typeof(int), ( int ) 0, false));
options.Add(new MySqlConnectionStringOption("checkparameters", "check parameters", typeof(bool), true, false));
options.Add(new MySqlConnectionStringOption("replication", null, typeof(bool), true, false));
options.Add(new MySqlConnectionStringOption("replication", null, typeof(bool), false, false));
options.Add(new MySqlConnectionStringOption("exceptioninterceptors", "exception interceptors", typeof(string), null, false));
options.Add(new MySqlConnectionStringOption("commandinterceptors", "command interceptors", typeof(string), null, false));
#if !CF
options.Add(new MySqlConnectionStringOption("includesecurityasserts", "include security asserts", typeof(bool), false, false));
#endif

// pooling options
options.Add(new MySqlConnectionStringOption("connectionlifetime", "connection lifetime", typeof(uint), 0, false));
options.Add(new MySqlConnectionStringOption("connectionlifetime", "connection lifetime", typeof(uint), ( uint )0, false));
options.Add(new MySqlConnectionStringOption("pooling", null, typeof(bool), true, false));
options.Add(new MySqlConnectionStringOption("minpoolsize", "min pool size,minimum pool size", typeof(uint), 0, false));
options.Add(new MySqlConnectionStringOption("maxpoolsize", "max pool size,maximum pool size", typeof(uint), 100, false));
options.Add(new MySqlConnectionStringOption("minpoolsize", "min pool size,minimum pool size", typeof(uint), ( uint )0, false));
options.Add(new MySqlConnectionStringOption("maxpoolsize", "max pool size,maximum pool size", typeof(uint), ( uint )100, false));
options.Add(new MySqlConnectionStringOption("connectionreset", "connection reset", typeof(bool), false, false));
options.Add(new MySqlConnectionStringOption("cacheserverproperties", "cache server properties", typeof(bool), false, false));

// language and charset options
options.Add(new MySqlConnectionStringOption("characterset", "character set,charset", typeof(bool), false, false));
options.Add(new MySqlConnectionStringOption("characterset", "character set,charset", typeof(string), "", false));
options.Add(new MySqlConnectionStringOption("treatblobsasutf8", "treat blobs as utf8", typeof(bool), false, false));
options.Add(new MySqlConnectionStringOption("blobasutf8includepattern", null, typeof(string), false, false));
options.Add(new MySqlConnectionStringOption("blobasutf8excludepattern", null, typeof(string), false, false));
options.Add(new MySqlConnectionStringOption("blobasutf8includepattern", null, typeof(string), "", false));
options.Add(new MySqlConnectionStringOption("blobasutf8excludepattern", null, typeof(string), "", false));
#if !CF
options.Add(new MySqlConnectionStringOption("sslmode", "ssl mode", typeof(MySqlSslMode), MySqlSslMode.None, false));
#endif
Expand Down Expand Up @@ -181,8 +182,8 @@ public bool UseCompression
[RefreshProperties(RefreshProperties.All)]
public bool AllowBatch
{
get { return (bool)values["allow batch"]; }
set { SetValue("allow batch", value); }
get { return (bool)values["allowbatch"]; }
set { SetValue("allowbatch", value); }
}

/// <summary>
Expand All @@ -207,8 +208,8 @@ public bool Logging
[RefreshProperties(RefreshProperties.All)]
public string SharedMemoryName
{
get { return (string)values["Shared Memory Name"]; }
set { SetValue("Shared Memory Name", value); }
get { return (string)values["sharedmemoryname"]; }
set { SetValue("sharedmemoryname", value); }
}

/// <summary>
Expand Down Expand Up @@ -277,8 +278,8 @@ public uint ConnectionTimeout
[RefreshProperties(RefreshProperties.All)]
public uint DefaultCommandTimeout
{
get { return (uint)values["Default Command Timeout"]; }
set { SetValue("Default Command Timeout", value); }
get { return (uint)values["defaultcommandtimeout"]; }
set { SetValue("defaultcommandtimeout", value); }
}

#endregion
Expand Down Expand Up @@ -323,8 +324,8 @@ public string Password
[RefreshProperties(RefreshProperties.All)]
public bool PersistSecurityInfo
{
get { return (bool)values["pPersistsecurityinfo"]; }
set { SetValue("pPersistsecurityinfo", value); }
get { return (bool)values["persistsecurityinfo"]; }
set { SetValue("persistsecurityinfo", value); }
}

#if !CF
Expand Down Expand Up @@ -494,8 +495,8 @@ public bool IgnorePrepare
[Obsolete("Use CheckParameters instead")]
public bool UseProcedureBodies
{
get { return (bool)values["Use Procedure Bodies"]; }
set { SetValue("Use Procedure Bodies", value); }
get { return (bool)values["useprocedurebodies"]; }
set { SetValue("useprocedurebodies", value); }
}

[Category("Advanced")]
Expand Down Expand Up @@ -692,8 +693,8 @@ public bool IncludeSecurityAsserts
[RefreshProperties(RefreshProperties.All)]
public uint ConnectionLifeTime
{
get { return (uint)values["connectionlifeTime"]; }
set { SetValue("connectionlifeTime", value); }
get { return (uint)values["connectionlifetime"]; }
set { SetValue("connectionlifetime", value); }
}

/// <summary>
Expand All @@ -720,7 +721,7 @@ public bool Pooling
[RefreshProperties(RefreshProperties.All)]
public uint MinimumPoolSize
{
get { return (uint)values["miunpoolsize"]; }
get { return (uint)values["minpoolsize"]; }
set { SetValue("minpoolsize", value); }
}

Expand Down Expand Up @@ -837,6 +838,18 @@ public MySqlSslMode SslMode

#endregion

#region Backwards compatibility properties
[DisplayName("Use Default Command Timeout For EF")]
[Category("Backwards Compatibility")]
[Description("Enforces the command timeout of EFMySqlCommand to the value provided in 'DefaultCommandTimeout' property")]
[DefaultValue(false)]
public bool UseDefaultCommandTimeoutForEF
{
get { return (bool)values["usedefaultcommandtimeoutforef"]; }
set { SetValue("usedefaultcommandtimeoutforef", value); }
}
#endregion

internal bool HasProcAccess { get; set; }

public override object this[string keyword]
Expand All @@ -863,12 +876,15 @@ public override void Clear()
foreach (var option in options)
if (option.DefaultValue != null)
values[option.Keyword] = option.DefaultValue;
else
values[option.Keyword] = null;
}

private void SetValue(string keyword, object value)
{
MySqlConnectionStringOption option = GetOption(keyword);
option.ValidateValue(value);
if (option.Keyword == "keepalive") { System.Diagnostics.Debugger.Break(); }
option.ValidateValue(ref value);

// remove all related keywords
option.Clean(this);
Expand Down Expand Up @@ -950,28 +966,37 @@ public void Clean(MySqlConnectionStringBuilder builder)
builder.Remove(syn);
}

public void ValidateValue(object value)
public void ValidateValue(ref object value)
{
string typeName = BaseType.Name;
Type valueType = value.GetType();
if (valueType.Name != "String" && BaseType == valueType) return;
if (valueType.Name == "String" && BaseType == valueType) return;

bool b;
if (typeName == "Boolean" && Boolean.TryParse(value.ToString(), out b)) return;
if (typeName == "Boolean" && Boolean.TryParse(value.ToString(), out b)) { value = b; return; }

UInt64 uintVal;
if (typeName.StartsWith("UInt") && UInt64.TryParse(value.ToString(), out uintVal)) return;
if (typeName.StartsWith("UInt64") && UInt64.TryParse(value.ToString(), out uintVal)) { value = uintVal; return; }

UInt32 uintVal32;
if (typeName.StartsWith("UInt32") && UInt32.TryParse(value.ToString(), out uintVal32)) { value = uintVal32; return; }

Int64 intVal;
if (typeName.StartsWith("Int") && Int64.TryParse(value.ToString(), out intVal)) return;
if (typeName.StartsWith("Int64") && Int64.TryParse(value.ToString(), out intVal)) { value = intVal; return; }

Int32 intVal32;
if (typeName.StartsWith("Int32") && Int32.TryParse(value.ToString(), out intVal32)) { value = intVal32; return; }

object objValue;
#if RT
Type baseType = BaseType.GetTypeInfo().BaseType;
#else
Type baseType = BaseType.BaseType;
#endif
if (baseType != null && baseType.Name == "Enum" && ParseEnum(value.ToString(), out objValue)) return;
if (baseType != null && baseType.Name == "Enum" && ParseEnum(value.ToString(), out objValue))
{
value = objValue; return;
}

throw new ArgumentException(String.Format(Resources.ValueNotCorrectType, value));
}
Expand Down
2 changes: 1 addition & 1 deletion Source/MySql.Data/ProcedureCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public ProcedureCacheEntry GetProcedure(MySqlConnection conn, string spName, str

lock (procHash)
{
proc = procHash[hash];
procHash.TryGetValue(hash, out proc);
}
}
if (proc == null)
Expand Down
19 changes: 11 additions & 8 deletions Source/MySql.Data/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Source/MySql.Data/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -529,4 +529,7 @@
<data name="ValueNotCorrectType" xml:space="preserve">
<value>Value '{0}' is not of the correct type.</value>
</data>
<data name="LoadBalancing_NoAvailableServer" xml:space="preserve">
<value>No available server found.</value>
</data>
</root>
2 changes: 1 addition & 1 deletion Source/MySql.Data/ResultSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ private void LoadColumns(int numCols)

values = new IMySqlValue[numCols];
uaFieldsUsed = new bool[numCols];
fieldHashCS = new Dictionary<string, int>();
fieldHashCS = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
fieldHashCI = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);

for (int i = 0; i < fields.Length; i++)
Expand Down
35 changes: 35 additions & 0 deletions Source/MySql.Data/Schema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ public class MySqlSchemaCollection
{
private List<SchemaColumn> columns = new List<SchemaColumn>();
private List<MySqlSchemaRow> rows = new List<MySqlSchemaRow>();
#if !RT
private DataTable _table = null;
#endif

public MySqlSchemaCollection()
{
Expand All @@ -22,6 +25,30 @@ public MySqlSchemaCollection(string name) : this()
Name = name;
}

#if !RT
public MySqlSchemaCollection(DataTable dt)
{
// cache the original datatable to avoid the overhead of creating again whenever possible.
_table = dt;
int i = 0;
foreach (DataColumn dc in dt.Columns)
{
columns.Add(new SchemaColumn() { Name = dc.ColumnName, Type = dc.DataType });
Mapping.Add(dc.ColumnName, i++);
}

foreach (DataRow dr in dt.Rows)
{
MySqlSchemaRow row = new MySqlSchemaRow(this);
for (i = 0; i < columns.Count; i++)
{
row[i] = dr[i];
}
rows.Add(row);
}
}
#endif

internal Dictionary<string, int> Mapping;
public string Name { get; set; }
public IList<SchemaColumn> Columns { get { return columns; } }
Expand Down Expand Up @@ -75,6 +102,7 @@ internal MySqlSchemaRow AddRow()
#if !RT
internal DataTable AsDataTable()
{
if (_table != null) return _table;
DataTable dt = new DataTable(Name);
foreach (SchemaColumn col in Columns)
dt.Columns.Add(col.Name, col.Type);
Expand All @@ -95,6 +123,13 @@ public class MySqlSchemaRow : List<object>
public MySqlSchemaRow(MySqlSchemaCollection c)
{
Collection = c;
InitMetadata();
}

internal void InitMetadata()
{
for( int i = 0; i < Collection.Mapping.Keys.Count; i++ )
this.Add(null);
}

internal MySqlSchemaCollection Collection { get; private set; }
Expand Down
9 changes: 4 additions & 5 deletions Source/MySql.Data/parameter_collection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,11 @@ private void InternalSetParameter(int index, MySqlParameter value)
/// <returns>The zero-based location of the <see cref="MySqlParameter"/> in the collection.</returns>
public override int IndexOf(string parameterName)
{
object o = indexHashCS[parameterName];
if (o == null)
o = indexHashCI[parameterName];
if (o == null)
int i = -1;
if (!indexHashCS.TryGetValue(parameterName, out i) &&
!indexHashCI.TryGetValue(parameterName, out i))
return -1;
return (int)o;
return i;
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Tests/MySql.Data.Tests/StoredProcedure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ public void GetProcedureParametersDoesNotRequireSelectFromMySqlProceduresTable()
ISSchemaProvider isp = new ISSchemaProvider(c);
string[] rest = isp.CleanRestrictions(restrictions);

DataTable parametersTable = isp.GetProcedureParameters(rest, procTable);
MySqlSchemaCollection parametersTable = isp.GetProcedureParameters(rest, new MySqlSchemaCollection( procTable ));

Assert.IsNotNull(parametersTable);
}
Expand Down
Loading

0 comments on commit c145642

Please sign in to comment.