mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-06-28 13:34:32 +08:00
Update Core
This commit is contained in:
parent
185e5349fc
commit
c7a04e43cb
@ -322,6 +322,10 @@ namespace SqlSugar
|
||||
properyTypeName = this.Context.Ado.DbBind.GetDbTypeName(propertyType.Name);
|
||||
}
|
||||
var dataType = dc.DataType;
|
||||
if (properyTypeName == "boolean" && dataType == "bool")
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return properyTypeName != dataType;
|
||||
}
|
||||
#endregion
|
||||
|
@ -64,6 +64,7 @@ namespace SqlSugar
|
||||
private static readonly MethodInfo getOtherNull = typeof(IDataRecordExtensions).GetMethod("GetOtherNull");
|
||||
private static readonly MethodInfo getOther = typeof(IDataRecordExtensions).GetMethod("GetOther");
|
||||
private static readonly MethodInfo getJson = typeof(IDataRecordExtensions).GetMethod("GetJson");
|
||||
private static readonly MethodInfo getArray = typeof(IDataRecordExtensions).GetMethod("GetArray");
|
||||
private static readonly MethodInfo getEntity = typeof(IDataRecordExtensions).GetMethod("GetEntity", new Type[] { typeof(SqlSugarProvider) });
|
||||
|
||||
private delegate T Load(IDataRecord dataRecord);
|
||||
@ -153,6 +154,22 @@ namespace SqlSugar
|
||||
generator.Emit(OpCodes.Callvirt, columnInfo.PropertyInfo.GetSetMethod(true));
|
||||
generator.MarkLabel(endIfLabel);
|
||||
}
|
||||
if (columnInfo.IsArray)
|
||||
{
|
||||
MethodInfo arrayMehtod = getArray.MakeGenericMethod(columnInfo.PropertyInfo.PropertyType);
|
||||
int i = DataRecord.GetOrdinal(fieldName);
|
||||
Label endIfLabel = generator.DefineLabel();
|
||||
generator.Emit(OpCodes.Ldarg_0);
|
||||
generator.Emit(OpCodes.Ldc_I4, i);
|
||||
generator.Emit(OpCodes.Callvirt, isDBNullMethod);
|
||||
generator.Emit(OpCodes.Brtrue, endIfLabel);
|
||||
generator.Emit(OpCodes.Ldloc, result);
|
||||
generator.Emit(OpCodes.Ldarg_0);
|
||||
generator.Emit(OpCodes.Ldc_I4, i);
|
||||
generator.Emit(OpCodes.Call, arrayMehtod);
|
||||
generator.Emit(OpCodes.Callvirt, columnInfo.PropertyInfo.GetSetMethod(true));
|
||||
generator.MarkLabel(endIfLabel);
|
||||
}
|
||||
}
|
||||
private void BindField(ILGenerator generator, LocalBuilder result, EntityColumnInfo columnInfo, string fieldName)
|
||||
{
|
||||
|
@ -248,6 +248,14 @@ namespace SqlSugar
|
||||
var value = obj.ObjToString();
|
||||
return new SerializeService().DeserializeObject<T>(value);
|
||||
}
|
||||
public static T GetArray<T>(this IDataReader dr, int i)
|
||||
{
|
||||
//pgsql
|
||||
var obj = dr.GetValue(i);
|
||||
if (obj == null)
|
||||
return default(T);
|
||||
return (T)obj;
|
||||
}
|
||||
|
||||
public static Nullable<T> GetConvertEnum_Null<T>(this IDataReader dr, int i) where T : struct
|
||||
{
|
||||
|
@ -194,6 +194,7 @@ namespace SqlSugar
|
||||
column.DefaultValue = sugarColumn.DefaultValue;
|
||||
column.IndexGroupNameList = sugarColumn.IndexGroupNameList;
|
||||
column.IsOnlyIgnoreUpdate = sugarColumn.IsOnlyIgnoreUpdate;
|
||||
column.IsArray = sugarColumn.IsArray;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -343,6 +343,10 @@ namespace SqlSugar
|
||||
{
|
||||
paramters.IsJson = true;
|
||||
}
|
||||
if (item.IsArray)
|
||||
{
|
||||
paramters.IsArray = true;
|
||||
}
|
||||
this.InsertBuilder.Parameters.Add(paramters);
|
||||
}
|
||||
}
|
||||
@ -407,6 +411,10 @@ namespace SqlSugar
|
||||
{
|
||||
columnInfo.IsJson = true;
|
||||
}
|
||||
if (column.IsArray)
|
||||
{
|
||||
columnInfo.IsArray = true;
|
||||
}
|
||||
if (columnInfo.PropertyType.IsEnum())
|
||||
{
|
||||
columnInfo.Value = Convert.ToInt64(columnInfo.Value);
|
||||
|
@ -1470,7 +1470,7 @@ namespace SqlSugar
|
||||
{
|
||||
new ConditionalModel()
|
||||
{
|
||||
FieldName=whereCol.DbColumnName,
|
||||
FieldName=this.SqlBuilder.GetTranslationColumnName(whereCol.DbColumnName),
|
||||
ConditionalType= ConditionalType.In,
|
||||
FieldValue=string.Join(",",inValues.Distinct())
|
||||
}
|
||||
|
@ -131,6 +131,14 @@ namespace SqlSugar
|
||||
{
|
||||
parameterName = parameterName.Replace(".", "_");
|
||||
}
|
||||
if (parameterName.Contains("["))
|
||||
{
|
||||
parameterName = parameterName.Replace("[", "_");
|
||||
}
|
||||
if (parameterName.Contains("]"))
|
||||
{
|
||||
parameterName = parameterName.Replace("]", "_");
|
||||
}
|
||||
switch (item.ConditionalType)
|
||||
{
|
||||
case ConditionalType.Equal:
|
||||
|
@ -950,7 +950,8 @@ namespace SqlSugar
|
||||
{
|
||||
try
|
||||
{
|
||||
if (this.CurrentConnectionConfig.DbType == DbType.Oracle) {
|
||||
if (this.CurrentConnectionConfig.DbType == DbType.Oracle)
|
||||
{
|
||||
throw new Exception("Oracle no support SaveQueues");
|
||||
}
|
||||
if (this.Queues == null || this.Queues.Count == 0) return default(T);
|
||||
|
@ -448,6 +448,10 @@ namespace SqlSugar
|
||||
{
|
||||
Check.Exception(true, ErrorMessage.GetThrowMessage("UpdateColumns no support IsJson", "SetColumns方式更新不支持IsJson,你可以使用db.Updateable(实体)的方式更新"));
|
||||
}
|
||||
if (this.EntityInfo.Columns.Any(it => it.IsArray))
|
||||
{
|
||||
Check.Exception(true, ErrorMessage.GetThrowMessage("UpdateColumns no support IsArray", "SetColumns方式更新不支持IsArray,你可以使用db.Updateable(实体)的方式更新"));
|
||||
}
|
||||
}
|
||||
private void SetUpdateItemByDic(int i, T item, List<DbColumnInfo> updateItem)
|
||||
{
|
||||
@ -488,8 +492,13 @@ namespace SqlSugar
|
||||
}
|
||||
if (column.IsJson)
|
||||
{
|
||||
columnInfo.IsJson = true;
|
||||
columnInfo.Value = this.Context.Utilities.SerializeObject(columnInfo.Value);
|
||||
}
|
||||
if (column.IsArray)
|
||||
{
|
||||
columnInfo.IsArray = true;
|
||||
}
|
||||
var tranColumn = EntityInfo.Columns.FirstOrDefault(it => it.IsTranscoding && it.DbColumnName.Equals(column.DbColumnName, StringComparison.CurrentCultureIgnoreCase));
|
||||
if (tranColumn != null && columnInfo.Value.HasValue())
|
||||
{
|
||||
@ -530,7 +539,16 @@ namespace SqlSugar
|
||||
{
|
||||
continue;
|
||||
}
|
||||
this.UpdateBuilder.Parameters.Add(new SugarParameter(this.SqlBuilder.SqlParameterKeyWord + item.DbColumnName, item.Value, item.PropertyType));
|
||||
var parameter = new SugarParameter(this.SqlBuilder.SqlParameterKeyWord + item.DbColumnName, item.Value, item.PropertyType);
|
||||
if (item.IsJson)
|
||||
{
|
||||
parameter.IsJson = true;
|
||||
}
|
||||
if (item.IsArray)
|
||||
{
|
||||
parameter.IsArray = true;
|
||||
}
|
||||
this.UpdateBuilder.Parameters.Add(parameter);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@ namespace SqlSugar
|
||||
public object Value { get; set; }
|
||||
public int DecimalDigits { get; set; }
|
||||
public int Scale { get; set; }
|
||||
public bool IsArray { get; set; }
|
||||
internal bool IsJson { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -33,5 +33,6 @@ namespace SqlSugar
|
||||
public bool IsJson { get; set; }
|
||||
public bool NoSerialize { get; set; }
|
||||
public string[] IndexGroupNameList { get; set; }
|
||||
public bool IsArray { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -171,6 +171,13 @@ namespace SqlSugar
|
||||
set { _IndexGroupNameList = value; }
|
||||
}
|
||||
|
||||
private bool _IsArray;
|
||||
public bool IsArray
|
||||
{
|
||||
get { return _IsArray; }
|
||||
set { _IsArray = value; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -234,5 +234,6 @@ namespace SqlSugar
|
||||
|
||||
public string TypeName { get; set; }
|
||||
public bool IsJson { get; set; }
|
||||
public bool IsArray { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ using System.Dynamic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
namespace SqlSugar
|
||||
{
|
||||
@ -276,9 +277,21 @@ namespace SqlSugar
|
||||
var name = item.Name;
|
||||
var typeName = tType.Name;
|
||||
if (item.PropertyType.IsClass())
|
||||
{
|
||||
if (readerValues != null &&
|
||||
readerValues.Count == 1 &&
|
||||
readerValues.First().Key == name &&
|
||||
readerValues.First().Value!=null&&
|
||||
readerValues.First().Value.GetType()==UtilConstants.StringType&&
|
||||
Regex.IsMatch(readerValues.First().Value.ObjToString(), @"^\{.+\}$"))
|
||||
{
|
||||
result.Add(name, DeserializeObject<Dictionary<string,object>>(readerValues.First().Value.ObjToString()));
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Add(name, DataReaderToDynamicList_Part(readerValues, item, reval));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (readerValues.Any(it => it.Key.Equals(name, StringComparison.CurrentCultureIgnoreCase)))
|
||||
|
@ -99,6 +99,19 @@ namespace SqlSugar
|
||||
{
|
||||
sqlParameter.NpgsqlDbType = NpgsqlDbType.Json;
|
||||
}
|
||||
if (parameter.IsArray)
|
||||
{
|
||||
// sqlParameter.Value = this.Context.Utilities.SerializeObject(sqlParameter.Value);
|
||||
var type = sqlParameter.Value.GetType();
|
||||
if (ArrayMapping.ContainsKey(type))
|
||||
{
|
||||
sqlParameter.NpgsqlDbType = ArrayMapping[type] | NpgsqlDbType.Array;
|
||||
}
|
||||
else
|
||||
{
|
||||
Check.Exception(true, sqlParameter.Value.GetType().Name + " No Support");
|
||||
}
|
||||
}
|
||||
if (sqlParameter.Direction == 0)
|
||||
{
|
||||
sqlParameter.Direction = ParameterDirection.Input;
|
||||
@ -114,5 +127,31 @@ namespace SqlSugar
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
static readonly Dictionary<Type, NpgsqlDbType> ArrayMapping = new Dictionary<Type, NpgsqlDbType>()
|
||||
{
|
||||
{ typeof(int[]),NpgsqlDbType.Integer},
|
||||
{ typeof(short[]),NpgsqlDbType.Smallint},
|
||||
{ typeof(long[]),NpgsqlDbType.Bigint},
|
||||
{ typeof(decimal[]),NpgsqlDbType.Numeric},
|
||||
{ typeof(char[]),NpgsqlDbType.Text},
|
||||
{ typeof(byte[]),NpgsqlDbType.Bytea},
|
||||
{ typeof(bool[]),NpgsqlDbType.Boolean},
|
||||
{typeof(DateTime[]),NpgsqlDbType.Date},
|
||||
|
||||
|
||||
{ typeof(int?[]),NpgsqlDbType.Integer},
|
||||
{ typeof(short?[]),NpgsqlDbType.Smallint},
|
||||
{ typeof(long?[]),NpgsqlDbType.Bigint},
|
||||
{ typeof(decimal?[]),NpgsqlDbType.Numeric},
|
||||
{ typeof(char?[]),NpgsqlDbType.Text},
|
||||
{ typeof(byte?[]),NpgsqlDbType.Bytea},
|
||||
{ typeof(bool?[]),NpgsqlDbType.Boolean},
|
||||
{typeof(DateTime?[]),NpgsqlDbType.Date},
|
||||
|
||||
|
||||
{ typeof(string[]), NpgsqlDbType.Text},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -253,5 +253,10 @@ namespace SqlSugar
|
||||
{
|
||||
return "RANDOM()";
|
||||
}
|
||||
|
||||
public override string EqualTrue(string fieldName)
|
||||
{
|
||||
return "( " + fieldName + "=true )";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ namespace SqlSugar
|
||||
}
|
||||
else if (type == UtilConstants.ByteArrayType)
|
||||
{
|
||||
string bytesString = "0x" + BitConverter.ToString((byte[])value);
|
||||
string bytesString = "0x" + BitConverter.ToString((byte[])value).Replace("-", "");
|
||||
return bytesString;
|
||||
}
|
||||
else if (type == UtilConstants.BoolType)
|
||||
|
@ -56,7 +56,7 @@ namespace SqlSugar
|
||||
}
|
||||
else if (type == UtilConstants.ByteArrayType)
|
||||
{
|
||||
string bytesString = "0x" + BitConverter.ToString((byte[])value);
|
||||
string bytesString = "0x" + BitConverter.ToString((byte[])value).Replace("-", "");
|
||||
return bytesString;
|
||||
}
|
||||
else if (type == UtilConstants.BoolType)
|
||||
|
Loading…
Reference in New Issue
Block a user