提交 8fcb8ebb 编写于 作者: M Marc Gravell

r1.31; Issue 148/149: error message on bad column maps borked due to sequential access

上级 3691fe13
......@@ -32,5 +32,5 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.30.0.0")]
[assembly: AssemblyFileVersion("1.30.0.0")]
[assembly: AssemblyVersion("1.31.0.0")]
[assembly: AssemblyFileVersion("1.31.0.0")]
......@@ -3285,7 +3285,7 @@ public static void SetTypeMap(Type type, ITypeMap map)
bool first = true;
var allDone = il.DefineLabel();
int enumDeclareLocal = -1;
int enumDeclareLocal = -1, valueCopyLocal = il.DeclareLocal(typeof(object)).LocalIndex;
foreach (var item in members)
{
if (item != null)
......@@ -3300,6 +3300,8 @@ public static void SetTypeMap(Type type, ITypeMap map)
il.Emit(OpCodes.Dup);// stack is now [target][target][reader][index][index]
il.Emit(OpCodes.Stloc_0);// stack is now [target][target][reader][index]
il.Emit(OpCodes.Callvirt, getItem); // stack is now [target][target][value-as-object]
il.Emit(OpCodes.Dup); // stack is now [target][target][value-as-object][value-as-object]
StoreLocal(il, valueCopyLocal);
Type colType = reader.GetFieldType(index);
Type memberType = item.MemberType;
......@@ -3332,7 +3334,7 @@ public static void SetTypeMap(Type type, ITypeMap map)
StoreLocal(il, enumDeclareLocal); // stack is now [target][target]
il.Emit(OpCodes.Ldtoken, unboxType); // stack is now [target][target][enum-type-token]
il.EmitCall(OpCodes.Call, typeof(Type).GetMethod("GetTypeFromHandle"), null);// stack is now [target][target][enum-type]
il.Emit(OpCodes.Ldloc_2); // stack is now [target][target][enum-type][string]
LoadLocal(il, enumDeclareLocal); // stack is now [target][target][enum-type][string]
il.Emit(OpCodes.Ldc_I4_1); // stack is now [target][target][enum-type][string][true]
il.EmitCall(OpCodes.Call, enumParse, null); // stack is now [target][target][enum-as-object]
il.Emit(OpCodes.Unbox_Any, unboxType); // stack is now [target][target][typed-value]
......@@ -3460,6 +3462,7 @@ public static void SetTypeMap(Type type, ITypeMap map)
il.BeginCatchBlock(typeof(Exception)); // stack is Exception
il.Emit(OpCodes.Ldloc_0); // stack is Exception, index
il.Emit(OpCodes.Ldarg_0); // stack is Exception, index, reader
LoadLocal(il, valueCopyLocal); // stack is Exception, index, reader, value
il.EmitCall(OpCodes.Call, typeof(SqlMapper).GetMethod("ThrowDataException"), null);
il.EndExceptionBlock();
......@@ -3635,36 +3638,33 @@ private static void LoadLocalAddress(ILGenerator il, int index)
/// <summary>
/// Throws a data exception, only used internally
/// </summary>
/// <param name="ex"></param>
/// <param name="index"></param>
/// <param name="reader"></param>
public static void ThrowDataException(Exception ex, int index, IDataReader reader)
[Obsolete("Intended for internal use only")]
public static void ThrowDataException(Exception ex, int index, IDataReader reader, object value)
{
Exception toThrow;
try
{
string name = "(n/a)", value = "(n/a)";
string name = "(n/a)", formattedValue = "(n/a)";
if (reader != null && index >= 0 && index < reader.FieldCount)
{
name = reader.GetName(index);
try
{
object val = reader.GetValue(index); // if there throw an exception, then I got one message, but Which column?
if (val == null || val is DBNull)
if (value == null || value is DBNull)
{
value = "<null>";
formattedValue = "<null>";
}
else
{
value = Convert.ToString(val) + " - " + Type.GetTypeCode(val.GetType());
formattedValue = Convert.ToString(value) + " - " + Type.GetTypeCode(value.GetType());
}
}
catch (Exception valEx)
{
value = valEx.Message;
formattedValue = valEx.Message;
}
}
toThrow = new DataException(string.Format("Error parsing column {0} ({1}={2})", index, name, value), ex);
toThrow = new DataException(string.Format("Error parsing column {0} ({1}={2})", index, name, formattedValue), ex);
}
catch
{ // throw the **original** exception, wrapped as DataException
......
......@@ -31,5 +31,5 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.30.0.0")]
[assembly: AssemblyFileVersion("1.30.0.0")]
[assembly: AssemblyVersion("1.31.0.0")]
[assembly: AssemblyFileVersion("1.31.0.0")]
......@@ -31,5 +31,5 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.30.0.0")]
[assembly: AssemblyFileVersion("1.30.0.0")]
[assembly: AssemblyVersion("1.31.0.0")]
[assembly: AssemblyFileVersion("1.31.0.0")]
......@@ -31,5 +31,5 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.30.0.0")]
[assembly: AssemblyFileVersion("1.30.0.0")]
[assembly: AssemblyVersion("1.31.0.0")]
[assembly: AssemblyFileVersion("1.31.0.0")]
......@@ -31,5 +31,5 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.30.0.0")]
[assembly: AssemblyFileVersion("1.30.0.0")]
[assembly: AssemblyVersion("1.31.0.0")]
[assembly: AssemblyFileVersion("1.31.0.0")]
......@@ -31,5 +31,5 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.30.0.0")]
[assembly: AssemblyFileVersion("1.30.0.0")]
[assembly: AssemblyVersion("1.31.0.0")]
[assembly: AssemblyFileVersion("1.31.0.0")]
......@@ -31,5 +31,5 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.30.0.0")]
[assembly: AssemblyFileVersion("1.30.0.0")]
[assembly: AssemblyVersion("1.31.0.0")]
[assembly: AssemblyFileVersion("1.31.0.0")]
......@@ -3476,6 +3476,23 @@ public void SO25069578_DynamicParams_Procs()
tran.Rollback();
row.X.IsEqualTo("bar");
}
public void Issue149_TypeMismatch_SequentialAccess()
{
string error;
Guid guid = Guid.Parse("cf0ef7ac-b6fe-4e24-aeda-a2b45bb5654e");
try
{
var result = connection.Query<Issue149_Person>(@"select @guid as Id", new { guid }).First();
error = null;
} catch(Exception ex)
{
error = ex.Message;
}
error.IsEqualTo("Error parsing column 0 (Id=cf0ef7ac-b6fe-4e24-aeda-a2b45bb5654e - Object)");
}
public class Issue149_Person { public string Id { get; set; } }
public class HazX
{
public string X { get; set; }
......
......@@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata schemaVersion="2">
<id>Dapper</id>
<version>1.30</version>
<version>1.31</version>
<title>Dapper dot net</title>
<authors>Sam Saffron,Marc Gravell</authors>
<owners>Sam Saffron,Marc Gravell</owners>
......@@ -19,6 +19,7 @@
<frameworkAssembly assemblyName="Microsoft.CSharp" targetFramework=".NETFramework4.0-Client, .NETFramework4.0" />
</frameworkAssemblies>
<releaseNotes>
* 1.31 - Fix issue with error message when there is a column/type mismatch
* 1.30 - Better async cancellation
* 1.29 - Make underscore name matching optional (opt-in) - this can be a breaking change for some people
* 1.28 - Much better numeric type conversion; fix for large oracle strings; map Foo_Bar to FooBar (etc); ExecuteScalar added; stability fixes
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册