Update Oracle num 8,2 decimal? bug

This commit is contained in:
sunkaixuan 2021-02-04 21:47:14 +08:00
parent 18e37307b3
commit 33330ae31c
3 changed files with 68 additions and 45 deletions

View File

@ -13,6 +13,17 @@ namespace OrmTest
if (Db.DbMaintenance.IsAnyTable("UnitCodeTest1", false))
Db.DbMaintenance.DropTable("UnitCodeTest1");
Db.CodeFirst.InitTables<UnitCodeTest1>();
Db.CodeFirst.InitTables<Unitasdfa1>();
Db.Insertable(new Unitasdfa1() { t1 = 1, t2 = 1 }).ExecuteCommand();
var x = Db.Queryable<Unitasdfa1>().ToList();
}
public class Unitasdfa1
{
[SqlSugar.SugarColumn(ColumnDataType = "number(8,2)")]
public decimal t2 { get; set; }
[SqlSugar.SugarColumn(ColumnDataType ="number(8,2)")]
public decimal? t1 { get; set; }
}
public class UnitCodeTest1
{

View File

@ -37,7 +37,7 @@ namespace SqlSugar
private static readonly MethodInfo getInt32 = typeof(IDataRecord).GetMethod("GetInt32", new Type[] { typeof(int) });
private static readonly MethodInfo getInt64 = typeof(IDataRecord).GetMethod("GetInt64", new Type[] { typeof(int) });
private static readonly MethodInfo getString = typeof(IDataRecord).GetMethod("GetString", new Type[] { typeof(int) });
private static readonly MethodInfo getConvertValueMethod = typeof(IDataRecordExtensions).GetMethod("GetConvertValue");
//private static readonly MethodInfo getConvertValueMethod = typeof(IDataRecordExtensions).GetMethod("GetConvertValue");
private static readonly MethodInfo getdatetimeoffset = typeof(IDataRecordExtensions).GetMethod("Getdatetimeoffset");
private static readonly MethodInfo getdatetimeoffsetDate = typeof(IDataRecordExtensions).GetMethod("GetdatetimeoffsetDate");
private static readonly MethodInfo getStringGuid = typeof(IDataRecordExtensions).GetMethod("GetStringGuid");
@ -223,7 +223,7 @@ namespace SqlSugar
}
else if (bindPropertyType == UtilConstants.StringType&&dbTypeName?.ToLower()== "timestamp")
{
method = getConvertValueMethod.MakeGenericMethod(columnInfo.PropertyInfo.PropertyType); ;
method = isNullableType ? getOtherNull.MakeGenericMethod(bindPropertyType) : getOther.MakeGenericMethod(bindPropertyType);
}
else if (bindPropertyType == UtilConstants.StringType)
{
@ -231,7 +231,7 @@ namespace SqlSugar
}
else
{
method = getConvertValueMethod.MakeGenericMethod(columnInfo.PropertyInfo.PropertyType);
method = isNullableType ? getOtherNull.MakeGenericMethod(bindPropertyType) : getOther.MakeGenericMethod(bindPropertyType);
}
if (method.IsVirtual)
@ -301,11 +301,11 @@ namespace SqlSugar
}
if (bindPropertyType == UtilConstants.DecType)
{
method = getConvertValueMethod.MakeGenericMethod(bindPropertyType);
method = isNullableType ? getOtherNull.MakeGenericMethod(bindPropertyType) : getOther.MakeGenericMethod(bindPropertyType);
}
if (bindPropertyType == UtilConstants.IntType)
{
method = getConvertValueMethod.MakeGenericMethod(bindPropertyType);
method = isNullableType ? getOtherNull.MakeGenericMethod(bindPropertyType) : getOther.MakeGenericMethod(bindPropertyType);
}
break;
case CSharpDataType.Guid:
@ -337,7 +337,7 @@ namespace SqlSugar
case CSharpDataType.Single:
break;
default:
method = getConvertValueMethod.MakeGenericMethod(bindPropertyType);
method = isNullableType ? getOtherNull.MakeGenericMethod(bindPropertyType) : getOther.MakeGenericMethod(bindPropertyType);
break;
}
if (method == null && bindPropertyType == UtilConstants.StringType)
@ -346,7 +346,7 @@ namespace SqlSugar
}
if (bindPropertyType == UtilConstants.ObjType)
{
method = getConvertValueMethod.MakeGenericMethod(bindPropertyType);
method = isNullableType ? getOtherNull.MakeGenericMethod(bindPropertyType) : getOther.MakeGenericMethod(bindPropertyType);
}
if (method == null)
method = isNullableType ? getOtherNull.MakeGenericMethod(bindPropertyType) : getOther.MakeGenericMethod(bindPropertyType);

View File

@ -136,38 +136,22 @@ namespace SqlSugar
var result = dr.GetInt32(i);
return result;
}
public static T GetConvertValue<T>(this IDataRecord dr, int i)
{
try
{
if (dr.IsDBNull(i))
{
return default(T);
}
var result = dr.GetValue(i);
return UtilMethods.To<T>(result);
}
catch (Exception ex)
{
if (dr.GetFieldType(i) == UtilConstants.DateType)
{
return UtilMethods.To<T>(dr.GetConvertDouble(i));
}
if (dr.GetFieldType(i) == UtilConstants.GuidType)
{
var data = dr.GetString(i);
if (data.ToString() == "")
{
return UtilMethods.To<T>(null);
}
else
{
return UtilMethods.To<T>(Guid.Parse(data.ToString()));
}
}
throw new Exception(ex.Message);
}
}
//public static T GetConvertValue<T>(this IDataRecord dr, int i)
//{
// try
// {
// if (dr.IsDBNull(i))
// {
// return default(T);
// }
// var result = dr.GetValue(i);
// return UtilMethods.To<T>(result);
// }
// catch (Exception ex)
// {
// return OtherException<T>(dr, i, ex);
// }
//}
public static long? GetConvetInt64(this IDataRecord dr, int i)
{
@ -264,12 +248,13 @@ namespace SqlSugar
{
return null;
}
var result = dr.GetValue(i);
return UtilMethods.To<T>(result);
return GetOther<T>(dr,i);
}
public static T GetOther<T>(this IDataReader dr, int i)
{
try
{
if (dr.IsDBNull(i))
{
@ -278,6 +263,11 @@ namespace SqlSugar
var result = dr.GetValue(i);
return UtilMethods.To<T>(result);
}
catch (Exception ex)
{
return OtherException<T>(dr, i, ex);
}
}
public static T GetJson<T>(this IDataReader dr, int i)
{
@ -330,6 +320,28 @@ namespace SqlSugar
return null;
}
private static T OtherException<T>(IDataRecord dr, int i, Exception ex)
{
if (dr.GetFieldType(i) == UtilConstants.DateType)
{
return UtilMethods.To<T>(dr.GetConvertDouble(i));
}
if (dr.GetFieldType(i) == UtilConstants.GuidType)
{
var data = dr.GetString(i);
if (data.ToString() == "")
{
return UtilMethods.To<T>(null);
}
else
{
return UtilMethods.To<T>(Guid.Parse(data.ToString()));
}
}
throw new Exception(ex.Message);
}
#endregion
}
}