mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-22 20:13:41 +08:00
Update Core
This commit is contained in:
@@ -1173,7 +1173,7 @@ namespace SqlSugar
|
||||
}
|
||||
catch
|
||||
{
|
||||
Check.Exception(true, ErrorMessage.GetThrowMessage("Please reduce the number of T. Save Queue Changes queries don't have so many results", "请减少T的数量,SaveQueueChanges 查询没有这么多结果"));
|
||||
// Check.Exception(true, ErrorMessage.GetThrowMessage("Please reduce the number of T. Save Queue Changes queries don't have so many results", "请减少T的数量,SaveQueueChanges 查询没有这么多结果"));
|
||||
}
|
||||
}
|
||||
private void ExecuteProcessingSQL(ref string sql, SugarParameter[] parameters)
|
||||
|
@@ -116,6 +116,8 @@ namespace SqlSugar
|
||||
NoExistLogic(entityInfo);
|
||||
|
||||
this.Context.DbMaintenance.AddRemark(entityInfo);
|
||||
this.Context.DbMaintenance.AddIndex(entityInfo);
|
||||
this.Context.DbMaintenance.AddDefaultValue(entityInfo);
|
||||
}
|
||||
public virtual void NoExistLogic(EntityInfo entityInfo)
|
||||
{
|
||||
|
@@ -169,8 +169,7 @@ namespace SqlSugar
|
||||
}
|
||||
else if (propertyTypes == null || propertyTypes.Count() == 0)
|
||||
{
|
||||
Check.ThrowNotSupportedException(string.Format(" \"{0}\" Type NotSupported, DbBindProvider.GetPropertyTypeName error.", dbTypeName));
|
||||
return null;
|
||||
return "object";
|
||||
}
|
||||
else if (propertyTypes.First().Value == CSharpDataType.byteArray)
|
||||
{
|
||||
|
@@ -26,7 +26,6 @@ namespace SqlSugar
|
||||
private IDataReaderEntityBuilder<T> DynamicBuilder;
|
||||
private IDataRecord DataRecord;
|
||||
private static readonly MethodInfo isDBNullMethod = typeof(IDataRecord).GetMethod("IsDBNull", new Type[] { typeof(int) });
|
||||
private static readonly MethodInfo getValueMethod = typeof(IDataRecord).GetMethod("get_Item", new Type[] { typeof(int) });
|
||||
private static readonly MethodInfo getBoolean = typeof(IDataRecord).GetMethod("GetBoolean", new Type[] { typeof(int) });
|
||||
private static readonly MethodInfo getByte = typeof(IDataRecord).GetMethod("GetByte", new Type[] { typeof(int) });
|
||||
private static readonly MethodInfo getDateTime = typeof(IDataRecord).GetMethod("GetDateTime", new Type[] { typeof(int) });
|
||||
@@ -38,6 +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 getdatetimeoffset = typeof(IDataRecordExtensions).GetMethod("Getdatetimeoffset");
|
||||
private static readonly MethodInfo getdatetimeoffsetDate = typeof(IDataRecordExtensions).GetMethod("GetdatetimeoffsetDate");
|
||||
private static readonly MethodInfo getStringGuid = typeof(IDataRecordExtensions).GetMethod("GetStringGuid");
|
||||
@@ -64,8 +64,6 @@ 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 getSqliteTypeNull = typeof(IDataRecordExtensions).GetMethod("GetSqliteTypeNull");
|
||||
private static readonly MethodInfo getSqliteType = typeof(IDataRecordExtensions).GetMethod("GetSqliteType");
|
||||
private static readonly MethodInfo getEntity = typeof(IDataRecordExtensions).GetMethod("GetEntity", new Type[] { typeof(SqlSugarProvider) });
|
||||
|
||||
private delegate T Load(IDataRecord dataRecord);
|
||||
@@ -205,16 +203,9 @@ namespace SqlSugar
|
||||
{
|
||||
method = getString;
|
||||
}
|
||||
else if (bindPropertyType == UtilConstants.ByteArrayType)
|
||||
{
|
||||
method = getValueMethod;
|
||||
generator.Emit(OpCodes.Call, method);
|
||||
generator.Emit(OpCodes.Unbox_Any, columnInfo.PropertyInfo.PropertyType);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
method = isNullableType ? getSqliteTypeNull.MakeGenericMethod(bindPropertyType) : getSqliteType.MakeGenericMethod(bindPropertyType);
|
||||
method = getConvertValueMethod.MakeGenericMethod(columnInfo.PropertyInfo.PropertyType);
|
||||
}
|
||||
generator.Emit(OpCodes.Call, method);
|
||||
return;
|
||||
@@ -272,6 +263,14 @@ namespace SqlSugar
|
||||
if (dbTypeName.Equals("float",StringComparison.CurrentCultureIgnoreCase) && isNullableType && bindProperyTypeName.Equals("single",StringComparison.CurrentCultureIgnoreCase)) {
|
||||
method = getConvertDoubleToFloat;
|
||||
}
|
||||
if (bindPropertyType == UtilConstants.DecType)
|
||||
{
|
||||
method = getConvertValueMethod.MakeGenericMethod(bindPropertyType);
|
||||
}
|
||||
if (bindPropertyType == UtilConstants.IntType)
|
||||
{
|
||||
method = getConvertValueMethod.MakeGenericMethod(bindPropertyType);
|
||||
}
|
||||
break;
|
||||
case CSharpDataType.Guid:
|
||||
CheckType(bind.GuidThrow, bindProperyTypeName, validPropertyName, propertyName);
|
||||
@@ -300,7 +299,7 @@ namespace SqlSugar
|
||||
method = isNullableType ? getConvertdatetimeoffsetDate : getdatetimeoffsetDate;
|
||||
break;
|
||||
default:
|
||||
method = getValueMethod;
|
||||
method = getConvertValueMethod.MakeGenericMethod(bindPropertyType);
|
||||
break;
|
||||
}
|
||||
if (method == null && bindPropertyType == UtilConstants.StringType)
|
||||
@@ -309,15 +308,12 @@ namespace SqlSugar
|
||||
}
|
||||
if (bindPropertyType == UtilConstants.ObjType)
|
||||
{
|
||||
method = getValueMethod;
|
||||
method = getConvertValueMethod.MakeGenericMethod(bindPropertyType);
|
||||
}
|
||||
if (method == null)
|
||||
method = isNullableType ? getOtherNull.MakeGenericMethod(bindPropertyType) : getOther.MakeGenericMethod(bindPropertyType);
|
||||
|
||||
generator.Emit(OpCodes.Call, method);
|
||||
if (method == getValueMethod)
|
||||
{
|
||||
generator.Emit(OpCodes.Unbox_Any, columnInfo.PropertyInfo.PropertyType);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
|
@@ -136,6 +136,15 @@ namespace SqlSugar
|
||||
var result = dr.GetInt32(i);
|
||||
return result;
|
||||
}
|
||||
public static T GetConvertValue<T>(this IDataRecord dr, int i)
|
||||
{
|
||||
if (dr.IsDBNull(i))
|
||||
{
|
||||
return default(T);
|
||||
}
|
||||
var result = dr.GetValue(i);
|
||||
return UtilMethods.To<T>(result);
|
||||
}
|
||||
|
||||
public static long? GetConvetInt64(this IDataRecord dr, int i)
|
||||
{
|
||||
@@ -216,13 +225,19 @@ namespace SqlSugar
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return (T)Convert.ChangeType(dr.GetValue(i), typeof(T));
|
||||
var result = dr.GetValue(i);
|
||||
return UtilMethods.To<T>(result);
|
||||
|
||||
}
|
||||
|
||||
public static T GetOther<T>(this IDataReader dr, int i)
|
||||
{
|
||||
return (T)Convert.ChangeType(dr.GetValue(i), typeof(T));
|
||||
if (dr.IsDBNull(i))
|
||||
{
|
||||
return default(T);
|
||||
}
|
||||
var result = dr.GetValue(i);
|
||||
return UtilMethods.To<T>(result);
|
||||
}
|
||||
|
||||
public static T GetJson<T>(this IDataReader dr, int i)
|
||||
@@ -269,61 +284,5 @@ namespace SqlSugar
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Sqlite Extensions
|
||||
public static Nullable<T> GetSqliteTypeNull<T>(this IDataReader dr, int i) where T : struct
|
||||
{
|
||||
var type = UtilMethods.GetUnderType(typeof(T));
|
||||
if (dr.IsDBNull(i))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return SqliteTypeConvert<T>(dr, i, type);
|
||||
}
|
||||
|
||||
public static T GetSqliteType<T>(this IDataReader dr, int i) where T : struct
|
||||
{
|
||||
var type = typeof(T);
|
||||
return SqliteTypeConvert<T>(dr, i, type);
|
||||
}
|
||||
|
||||
private static T SqliteTypeConvert<T>(IDataReader dr, int i, Type type) where T : struct
|
||||
{
|
||||
if (type.IsIn(UtilConstants.IntType))
|
||||
{
|
||||
return (T)((object)(dr.GetInt32(i)));
|
||||
}
|
||||
else if (type == UtilConstants.DateType)
|
||||
{
|
||||
return (T)Convert.ChangeType(Convert.ToDateTime(dr.GetString(i)), type);
|
||||
}
|
||||
else if (type == UtilConstants.DecType)
|
||||
{
|
||||
return (T)Convert.ChangeType(dr.GetDecimal(i), type);
|
||||
}
|
||||
else if (type == UtilConstants.DobType)
|
||||
{
|
||||
return (T)Convert.ChangeType(dr.GetDouble(i), type);
|
||||
}
|
||||
else if (type == UtilConstants.BoolType)
|
||||
{
|
||||
return (T)Convert.ChangeType(dr.GetBoolean(i), type);
|
||||
}
|
||||
else if (type == UtilConstants.LongType)
|
||||
{
|
||||
return (T)Convert.ChangeType(dr.GetInt64(i), type);
|
||||
}
|
||||
else if (type == UtilConstants.GuidType)
|
||||
{
|
||||
string guidString = dr.GetString(i);
|
||||
string changeValue = guidString.IsNullOrEmpty() ? Guid.Empty.ToString() : guidString;
|
||||
return (T)Convert.ChangeType(Guid.Parse(changeValue), type);
|
||||
}
|
||||
else
|
||||
{
|
||||
return (T)Convert.ChangeType((dr.GetString(i)), type);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@@ -292,6 +292,27 @@ namespace SqlSugar
|
||||
var dt=this.Context.Ado.GetDataTable(sql);
|
||||
return dt.Rows != null && dt.Rows.Count > 0;
|
||||
}
|
||||
public virtual bool AddDefaultValue(string tableName, string columnName, string defaultValue)
|
||||
{
|
||||
if (defaultValue == "''")
|
||||
{
|
||||
defaultValue = "";
|
||||
}
|
||||
string sql = string.Format(AddDefaultValueSql, tableName, columnName,defaultValue);
|
||||
this.Context.Ado.ExecuteCommand(sql);
|
||||
return true;
|
||||
}
|
||||
public virtual bool CreateIndex(string tableName, string[] columnNames)
|
||||
{
|
||||
string sql = string.Format(CreateIndexSql,tableName,string.Join(",",columnNames), string.Join("_", columnNames));
|
||||
this.Context.Ado.ExecuteCommand(sql);
|
||||
return true;
|
||||
}
|
||||
public virtual bool IsAnyIndex(string indexName)
|
||||
{
|
||||
string sql = string.Format(this.IsAnyIndexSql, indexName);
|
||||
return this.Context.Ado.GetInt(sql)>0;
|
||||
}
|
||||
public virtual bool AddRemark(EntityInfo entity)
|
||||
{
|
||||
var db = this.Context;
|
||||
@@ -330,6 +351,54 @@ namespace SqlSugar
|
||||
return true;
|
||||
}
|
||||
|
||||
public virtual void AddIndex(EntityInfo entityInfo)
|
||||
{
|
||||
var db = this.Context;
|
||||
var columns = entityInfo.Columns.Where(it => it.IsIgnore == false).ToList();
|
||||
var indexColumns = columns.Where(it => it.IndexGroupNameList.HasValue()).ToList();
|
||||
if (indexColumns.HasValue())
|
||||
{
|
||||
var groups = indexColumns.SelectMany(it => it.IndexGroupNameList).GroupBy(it => it).Select(it=>it.Key).ToList();
|
||||
foreach (var item in groups)
|
||||
{
|
||||
var columnNames = indexColumns.Where(it => it.IndexGroupNameList.Any(i => i.Equals(item, StringComparison.CurrentCultureIgnoreCase))).Select(it=>it.DbColumnName).ToArray();
|
||||
var indexName = string.Format("Index_{0}_{1}",entityInfo.DbTableName, string.Join("_", columnNames));
|
||||
if (!IsAnyIndex(indexName))
|
||||
{
|
||||
CreateIndex(entityInfo.DbTableName, columnNames);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual bool IsAnyDefaultValue(string tableName, string columnName,List<DbColumnInfo> columns)
|
||||
{
|
||||
var defaultValue = columns.Where(it => it.DbColumnName.Equals(columnName, StringComparison.CurrentCultureIgnoreCase)).First().DefaultValue;
|
||||
return defaultValue.HasValue();
|
||||
}
|
||||
|
||||
public virtual bool IsAnyDefaultValue(string tableName, string columnName)
|
||||
{
|
||||
return IsAnyDefaultValue(tableName, columnName, this.GetColumnInfosByTableName(tableName, false));
|
||||
}
|
||||
|
||||
public virtual void AddDefaultValue(EntityInfo entityInfo)
|
||||
{
|
||||
var dbColumns=this.GetColumnInfosByTableName(entityInfo.DbTableName, false);
|
||||
var db = this.Context;
|
||||
var columns = entityInfo.Columns.Where(it => it.IsIgnore == false).ToList();
|
||||
foreach (var item in columns)
|
||||
{
|
||||
if (item.DefaultValue.HasValue())
|
||||
{
|
||||
if (!IsAnyDefaultValue(entityInfo.DbTableName,item.DbColumnName,dbColumns))
|
||||
{
|
||||
this.AddDefaultValue(entityInfo.DbTableName, item.DbColumnName, item.DefaultValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool RenameTable(string oldTableName, string newTableName)
|
||||
{
|
||||
string sql = string.Format(this.RenameTableSql, oldTableName,newTableName);
|
||||
|
@@ -32,6 +32,9 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region DDL
|
||||
protected abstract string CreateIndexSql { get; }
|
||||
protected abstract string IsAnyIndexSql { get; }
|
||||
protected abstract string AddDefaultValueSql { get; }
|
||||
protected abstract string CreateDataBaseSql { get; }
|
||||
protected abstract string AddColumnToTableSql { get; }
|
||||
protected abstract string AlterColumnToTableSql { get; }
|
||||
|
@@ -171,6 +171,8 @@ namespace SqlSugar
|
||||
column.SerializeDateTimeFormat = sugarColumn.SerializeDateTimeFormat;
|
||||
column.IsJson = sugarColumn.IsJson;
|
||||
column.NoSerialize = sugarColumn.NoSerialize;
|
||||
column.DefaultValue = sugarColumn.DefaultValue;
|
||||
column.IndexGroupNameList = sugarColumn.IndexGroupNameList;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -14,7 +14,15 @@ namespace SqlSugar
|
||||
{
|
||||
if (_Filters == null)
|
||||
_Filters = new List<SqlFilterItem>();
|
||||
_Filters.Add(filter);
|
||||
if (this.Context.CurrentConnectionConfig.IsShardSameThread)
|
||||
{
|
||||
if (!_Filters.Select(it => it.FilterValue(this.Context).Sql).Contains(filter.FilterValue(this.Context).Sql))
|
||||
_Filters.Add(filter);
|
||||
}
|
||||
else
|
||||
{
|
||||
_Filters.Add(filter);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@@ -154,9 +154,10 @@ namespace SqlSugar
|
||||
LambdaExpression lambda = setValueExpression as LambdaExpression;
|
||||
var expression = lambda.Body;
|
||||
Check.Exception(!(expression is BinaryExpression), "Expression format error");
|
||||
Check.Exception( (expression as BinaryExpression).NodeType!=ExpressionType.Equal, "Expression format error");
|
||||
var leftExpression = (expression as BinaryExpression).Left;
|
||||
Check.Exception(!(leftExpression is MemberExpression), "Expression format error");
|
||||
var leftResultString = UpdateBuilder.GetExpressionValue(leftExpression, ResolveExpressType.WhereSingle).GetString();
|
||||
var leftResultString = UpdateBuilder.GetExpressionValue(leftExpression, ResolveExpressType.FieldSingle).GetString();
|
||||
UpdateBuilder.SetValues.Add(new KeyValuePair<string, string>(leftResultString, resultString));
|
||||
return this;
|
||||
}
|
||||
@@ -620,21 +621,21 @@ namespace SqlSugar
|
||||
Check.Exception(dbVersion == null, "UpdateVersionValidation database column {0} is not null", versionColumn.DbColumnName);
|
||||
if (versionColumn.PropertyInfo.PropertyType.IsIn(UtilConstants.IntType, UtilConstants.LongType))
|
||||
{
|
||||
if (Convert.ToInt64(dbVersion) > Convert.ToInt64(currentVersion))
|
||||
if (Convert.ToInt64(dbVersion) != Convert.ToInt64(currentVersion))
|
||||
{
|
||||
throw new VersionExceptions(string.Format("UpdateVersionValidation {0} Not the latest version ", versionColumn.PropertyName));
|
||||
}
|
||||
}
|
||||
else if (versionColumn.PropertyInfo.PropertyType.IsIn(UtilConstants.DateType))
|
||||
{
|
||||
if (dbVersion.ObjToDate() > currentVersion.ObjToDate())
|
||||
if (dbVersion.ObjToDate() != currentVersion.ObjToDate())
|
||||
{
|
||||
throw new VersionExceptions(string.Format("UpdateVersionValidation {0} Not the latest version ", versionColumn.PropertyName));
|
||||
}
|
||||
}
|
||||
else if (versionColumn.PropertyInfo.PropertyType.IsIn(UtilConstants.ByteArrayType))
|
||||
{
|
||||
if (UtilMethods.GetLong((byte[])dbVersion) > UtilMethods.GetLong((byte[])currentVersion))
|
||||
if (UtilMethods.GetLong((byte[])dbVersion) != UtilMethods.GetLong((byte[])currentVersion))
|
||||
{
|
||||
throw new VersionExceptions(string.Format("UpdateVersionValidation {0} Not the latest version ", versionColumn.PropertyName));
|
||||
}
|
||||
|
@@ -31,5 +31,6 @@ namespace SqlSugar
|
||||
public string SerializeDateTimeFormat { get; set; }
|
||||
public bool IsJson { get; set; }
|
||||
public bool NoSerialize { get; set; }
|
||||
public string[] IndexGroupNameList { get; set; }
|
||||
}
|
||||
}
|
||||
|
@@ -148,6 +148,22 @@ namespace SqlSugar
|
||||
get { return _IsJson; }
|
||||
set { _IsJson = value; }
|
||||
}
|
||||
|
||||
|
||||
private string _DefaultValue;
|
||||
public string DefaultValue
|
||||
{
|
||||
get { return _DefaultValue; }
|
||||
set { _DefaultValue = value; }
|
||||
}
|
||||
|
||||
private string[] _IndexGroupNameList;
|
||||
public string[] IndexGroupNameList
|
||||
{
|
||||
get { return _IndexGroupNameList; }
|
||||
set { _IndexGroupNameList = value; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -17,5 +17,6 @@ namespace SqlSugar
|
||||
public bool IsMember { get; set; }
|
||||
public object MemberName { get; set; }
|
||||
public object MemberValue { get; set; }
|
||||
public Type Type { get; set; }
|
||||
}
|
||||
}
|
||||
|
@@ -264,6 +264,12 @@ namespace SqlSugar
|
||||
return string.Format("COUNT({0})", parameter.MemberName);
|
||||
}
|
||||
|
||||
public virtual string AggregateDistinctCount(MethodCallExpressionModel model)
|
||||
{
|
||||
var parameter = model.Args[0];
|
||||
return string.Format("COUNT(DISTINCT{0})", parameter.MemberName);
|
||||
}
|
||||
|
||||
public virtual string MappingColumn(MethodCallExpressionModel model)
|
||||
{
|
||||
var parameter = model.Args[0];
|
||||
|
@@ -48,6 +48,7 @@ namespace SqlSugar
|
||||
string AggregateMin(MethodCallExpressionModel model);
|
||||
string AggregateMax(MethodCallExpressionModel model);
|
||||
string AggregateCount(MethodCallExpressionModel model);
|
||||
string AggregateDistinctCount(MethodCallExpressionModel model);
|
||||
string MappingColumn(MethodCallExpressionModel model);
|
||||
string IsNull(MethodCallExpressionModel model);
|
||||
string GetSelfAndAutoFill(string shortName,bool isSingle);
|
||||
|
@@ -101,6 +101,7 @@ namespace SqlSugar
|
||||
public static TResult AggregateMin<TResult>(TResult thisValue) { throw new NotSupportedException("Can only be used in expressions"); }
|
||||
public static TResult AggregateMax<TResult>(TResult thisValue) { throw new NotSupportedException("Can only be used in expressions"); }
|
||||
public static int AggregateCount<TResult>(TResult thisValue) { throw new NotSupportedException("Can only be used in expressions"); }
|
||||
public static int AggregateDistinctCount<TResult>(TResult thisValue) { throw new NotSupportedException("Can only be used in expressions"); }
|
||||
public static TResult MappingColumn<TResult>(TResult oldColumnName,string newColumnName) { throw new NotSupportedException("Can only be used in expressions"); }
|
||||
/// <summary>
|
||||
///Example: new NewT(){name=SqlFunc.GetSelfAndAutoFill(it)} Generated SQL it.*
|
||||
|
@@ -253,6 +253,19 @@ namespace SqlSugar
|
||||
this.Context.Result.Replace(ExpressionConst.FormatSymbol, "NOT");
|
||||
}
|
||||
}
|
||||
protected void AppendNegate(object Value)
|
||||
{
|
||||
var isAppend = !this.Context.Result.Contains(ExpressionConst.FormatSymbol);
|
||||
var lastCharIsSpace = this.Context.Result.LastCharIsSpace;
|
||||
if (isAppend)
|
||||
{
|
||||
this.Context.Result.Append(lastCharIsSpace ? "-" : " -");
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Context.Result.Replace(ExpressionConst.FormatSymbol, "-");
|
||||
}
|
||||
}
|
||||
|
||||
protected MethodCallExpressionArgs GetMethodCallArgs(ExpressionParameter parameter, Expression item)
|
||||
{
|
||||
@@ -478,6 +491,24 @@ namespace SqlSugar
|
||||
Check.ThrowNotSupportedException(item.GetType().Name);
|
||||
}
|
||||
}
|
||||
protected static bool IsNotMember(Expression item)
|
||||
{
|
||||
return item is UnaryExpression &&
|
||||
item.Type == UtilConstants.BoolType &&
|
||||
(item as UnaryExpression).NodeType == ExpressionType.Not &&
|
||||
(item as UnaryExpression).Operand is MemberExpression &&
|
||||
((item as UnaryExpression).Operand as MemberExpression).Expression != null &&
|
||||
((item as UnaryExpression).Operand as MemberExpression).Expression.NodeType == ExpressionType.Parameter;
|
||||
}
|
||||
protected static bool IsNotParameter(Expression item)
|
||||
{
|
||||
return item is UnaryExpression &&
|
||||
item.Type == UtilConstants.BoolType &&
|
||||
(item as UnaryExpression).NodeType == ExpressionType.Not &&
|
||||
(item as UnaryExpression).Operand is MemberExpression &&
|
||||
((item as UnaryExpression).Operand as MemberExpression).Expression != null &&
|
||||
((item as UnaryExpression).Operand as MemberExpression).Expression.NodeType == ExpressionType.MemberAccess;
|
||||
}
|
||||
|
||||
protected bool IsSubMethod(MethodCallExpression express)
|
||||
{
|
||||
|
@@ -32,15 +32,15 @@ namespace SqlSugar
|
||||
{
|
||||
base.Context.Result.Replace(ExpressionConst.FormatSymbol, ExpressionConst.LeftParenthesis + ExpressionConst.FormatSymbol);
|
||||
}
|
||||
if (leftExpression is UnaryExpression && (leftExpression as UnaryExpression).Operand is UnaryExpression&& (leftExpression as UnaryExpression).NodeType != ExpressionType.Not)
|
||||
if (leftExpression is UnaryExpression && (leftExpression as UnaryExpression).Operand is UnaryExpression&& (leftExpression as UnaryExpression).NodeType == ExpressionType.Convert)
|
||||
{
|
||||
leftExpression = (leftExpression as UnaryExpression).Operand;
|
||||
}
|
||||
if (leftExpression is UnaryExpression && (leftExpression as UnaryExpression).Operand.Type == UtilConstants.BoolType && (leftExpression as UnaryExpression).NodeType != ExpressionType.Not&&rightExpression.Type==UtilConstants.BoolTypeNull)
|
||||
if (leftExpression is UnaryExpression && (leftExpression as UnaryExpression).Operand.Type == UtilConstants.BoolType && (leftExpression as UnaryExpression).NodeType == ExpressionType.Convert&&rightExpression.Type==UtilConstants.BoolTypeNull)
|
||||
{
|
||||
leftExpression = (leftExpression as UnaryExpression).Operand;
|
||||
}
|
||||
if (rightExpression is UnaryExpression&& (rightExpression as UnaryExpression).Operand.Type==UtilConstants.BoolType&& (rightExpression as UnaryExpression).NodeType != ExpressionType.Not)
|
||||
if (rightExpression is UnaryExpression&& (rightExpression as UnaryExpression).Operand.Type==UtilConstants.BoolType&& (rightExpression as UnaryExpression).NodeType == ExpressionType.Convert)
|
||||
{
|
||||
rightExpression = (rightExpression as UnaryExpression).Operand;
|
||||
}
|
||||
|
@@ -336,6 +336,10 @@ namespace SqlSugar
|
||||
this.Expression = expression.Expression;
|
||||
this.Start();
|
||||
var methodParamter = new MethodCallExpressionArgs() { IsMember = true, MemberName = parameter.CommonTempData, MemberValue = null };
|
||||
if (expression.Expression?.Type != null)
|
||||
{
|
||||
methodParamter.Type =UtilMethods.GetUnderType(expression.Expression?.Type);
|
||||
}
|
||||
var result = this.Context.DbMehtods.HasValue(new MethodCallExpressionModel()
|
||||
{
|
||||
Args = new List<MethodCallExpressionArgs>() {
|
||||
|
@@ -48,7 +48,7 @@ namespace SqlSugar
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
MemberAssignment memberAssignment = (MemberAssignment)binding;
|
||||
var type =expression.Type;
|
||||
var type = expression.Type;
|
||||
var memberName = this.Context.GetDbColumnName(type.Name, memberAssignment.Member.Name);
|
||||
var item = memberAssignment.Expression;
|
||||
if ((item is MemberExpression) && ((MemberExpression)item).Expression == null)
|
||||
@@ -57,12 +57,46 @@ namespace SqlSugar
|
||||
string parameterName = AppendParameter(paramterValue);
|
||||
this.Context.Result.Append(base.Context.GetEqString(memberName, parameterName));
|
||||
}
|
||||
else if (IsNotMember(item))
|
||||
{
|
||||
if (base.Context.Result.IsLockCurrentParameter == false)
|
||||
{
|
||||
base.Context.Result.CurrentParameter = parameter;
|
||||
base.Context.Result.IsLockCurrentParameter = true;
|
||||
parameter.IsAppendTempDate();
|
||||
base.Expression = item;
|
||||
base.Expression = (item as UnaryExpression).Operand;
|
||||
base.Start();
|
||||
parameter.IsAppendResult();
|
||||
var result = this.Context.DbMehtods.IIF(new MethodCallExpressionModel()
|
||||
{
|
||||
Args = new List<MethodCallExpressionArgs>() {
|
||||
new MethodCallExpressionArgs(){ IsMember=true, MemberName=parameter.CommonTempData.ObjToString()+"=1" },
|
||||
new MethodCallExpressionArgs(){ IsMember=true,MemberName=AppendParameter(0) },
|
||||
new MethodCallExpressionArgs(){ IsMember=true, MemberName=AppendParameter(1) }
|
||||
}
|
||||
});
|
||||
parameter.Context.Result.Append(base.Context.GetEqString(memberName, result));
|
||||
base.Context.Result.CurrentParameter = null;
|
||||
}
|
||||
}
|
||||
else if (IsNotParameter(item))
|
||||
{
|
||||
try
|
||||
{
|
||||
parameter.Context.Result.Append(base.Context.GetEqString(memberName,AppendParameter(ExpressionTool.DynamicInvoke(item).ObjToBool())));
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw new NotSupportedException(item.ToString());
|
||||
}
|
||||
}
|
||||
else if (IsMethod(item))
|
||||
{
|
||||
if (item is UnaryExpression)
|
||||
item = (item as UnaryExpression).Operand;
|
||||
var callMethod = item as MethodCallExpression;
|
||||
if (MethodTimeMapping.Any(it => it.Key == callMethod.Method.Name) || MethodMapping.Any(it=>it.Key==callMethod.Method.Name)||IsExtMethod(callMethod.Method.Name)||IsSubMethod(callMethod)|| callMethod.Method.DeclaringType.FullName.StartsWith(UtilConstants.AssemblyName+UtilConstants.Dot))
|
||||
if (MethodTimeMapping.Any(it => it.Key == callMethod.Method.Name) || MethodMapping.Any(it => it.Key == callMethod.Method.Name) || IsExtMethod(callMethod.Method.Name) || IsSubMethod(callMethod) || callMethod.Method.DeclaringType.FullName.StartsWith(UtilConstants.AssemblyName + UtilConstants.Dot))
|
||||
{
|
||||
MethodCall(parameter, memberName, item);
|
||||
}
|
||||
@@ -105,7 +139,7 @@ namespace SqlSugar
|
||||
{
|
||||
try
|
||||
{
|
||||
var value =ExpressionTool.DynamicInvoke(item);
|
||||
var value = ExpressionTool.DynamicInvoke(item);
|
||||
var parameterName = AppendParameter(value);
|
||||
parameter.Context.Result.Append(base.Context.GetEqString(memberName, parameterName));
|
||||
}
|
||||
|
@@ -413,6 +413,10 @@ namespace SqlSugar
|
||||
{
|
||||
parameter.CommonTempData = DateTime.Now.Date;
|
||||
}
|
||||
else if (IsDateDate(item))
|
||||
{
|
||||
parameter.CommonTempData = GetNewExpressionValue(item);
|
||||
}
|
||||
else if (model.Name == "ToString" && item is ConstantExpression && (item as ConstantExpression).Type.IsEnum())
|
||||
{
|
||||
parameter.CommonTempData = item.ToString();
|
||||
@@ -439,6 +443,10 @@ namespace SqlSugar
|
||||
methodCallExpressionArgs.IsMember = false;
|
||||
}
|
||||
}
|
||||
if (IsDateDate(item))
|
||||
{
|
||||
methodCallExpressionArgs.IsMember = true;
|
||||
}
|
||||
if (methodCallExpressionArgs.IsMember == false && (item is MethodCallExpression && item.ToString() == "GetDate()") || (item is UnaryExpression && ((UnaryExpression)item).Operand.ToString() == "GetDate()"))
|
||||
{
|
||||
var parameterName = this.Context.SqlParameterKeyWord + ExpressionConst.MethodConst + this.Context.ParameterIndex;
|
||||
@@ -458,6 +466,11 @@ namespace SqlSugar
|
||||
parameter.ChildExpression = null;
|
||||
}
|
||||
|
||||
private static bool IsDateDate(Expression item)
|
||||
{
|
||||
return item.Type == UtilConstants.DateType && item is MemberExpression && (item as MemberExpression).Member.Name == "Date"&&item.ToString()!= "DateTime.Now.Date";
|
||||
}
|
||||
|
||||
private object GetMethodValue(string name, MethodCallExpressionModel model)
|
||||
{
|
||||
if (IsExtMethod(name))
|
||||
@@ -578,6 +591,8 @@ namespace SqlSugar
|
||||
return this.Context.DbMehtods.AggregateMax(model);
|
||||
case "AggregateCount":
|
||||
return this.Context.DbMehtods.AggregateCount(model);
|
||||
case "AggregateDistinctCount":
|
||||
return this.Context.DbMehtods.AggregateDistinctCount(model);
|
||||
case "MappingColumn":
|
||||
var mappingColumnResult = this.Context.DbMehtods.MappingColumn(model);
|
||||
var isValid = model.Args[0].IsMember && model.Args[1].IsMember == false;
|
||||
|
@@ -9,6 +9,7 @@ namespace SqlSugar
|
||||
{
|
||||
public UnaryExpressionResolve(ExpressionParameter parameter) : base(parameter)
|
||||
{
|
||||
var oldExpression = base.Expression;
|
||||
var expression = base.Expression as UnaryExpression;
|
||||
var baseParameter = parameter.BaseParameter;
|
||||
switch (this.Context.ResolveType)
|
||||
@@ -36,6 +37,14 @@ namespace SqlSugar
|
||||
{
|
||||
Result(parameter, nodeType);
|
||||
}
|
||||
else if (baseParameter.OperatorValue == "=" &&IsNotMember(oldExpression))
|
||||
{
|
||||
AppendNotMember(parameter,nodeType);
|
||||
}
|
||||
else if (baseParameter.OperatorValue == "=" && IsNotParameter(oldExpression))
|
||||
{
|
||||
AppendNotParameter(parameter, nodeType);
|
||||
}
|
||||
else if (base.Expression is BinaryExpression || parameter.BaseExpression is BinaryExpression || baseParameter.CommonTempData.ObjToString() == CommonTempDataType.Append.ToString())
|
||||
{
|
||||
Append(parameter, nodeType);
|
||||
@@ -123,10 +132,53 @@ namespace SqlSugar
|
||||
parameter.CommonTempData = CommonTempDataType.Append;
|
||||
if (nodeType == ExpressionType.Not)
|
||||
AppendNot(parameter.CommonTempData);
|
||||
if (nodeType == ExpressionType.Negate)
|
||||
AppendNegate(parameter.CommonTempData);
|
||||
base.Start();
|
||||
parameter.BaseParameter.CommonTempData = parameter.CommonTempData;
|
||||
parameter.BaseParameter.ChildExpression = base.Expression;
|
||||
parameter.CommonTempData = null;
|
||||
}
|
||||
|
||||
|
||||
private void AppendNotMember(ExpressionParameter parameter, ExpressionType nodeType)
|
||||
{
|
||||
BaseParameter.ChildExpression = base.Expression;
|
||||
this.IsLeft = parameter.IsLeft;
|
||||
parameter.CommonTempData = CommonTempDataType.Result;
|
||||
base.Start();
|
||||
var result= this.Context.DbMehtods.IIF(new MethodCallExpressionModel()
|
||||
{
|
||||
Args = new List<MethodCallExpressionArgs>() {
|
||||
new MethodCallExpressionArgs(){ IsMember=true, MemberName=parameter.CommonTempData.ObjToString()+"=1" },
|
||||
new MethodCallExpressionArgs(){ IsMember=true,MemberName=AppendParameter(0) },
|
||||
new MethodCallExpressionArgs(){ IsMember=true, MemberName=AppendParameter(1) }
|
||||
}
|
||||
});
|
||||
this.Context.Result.Append(result);
|
||||
parameter.BaseParameter.ChildExpression = base.Expression;
|
||||
parameter.CommonTempData = null;
|
||||
}
|
||||
|
||||
|
||||
private void AppendNotParameter(ExpressionParameter parameter, ExpressionType nodeType)
|
||||
{
|
||||
BaseParameter.ChildExpression = base.Expression;
|
||||
this.IsLeft = parameter.IsLeft;
|
||||
parameter.CommonTempData = CommonTempDataType.Result;
|
||||
base.Start();
|
||||
var result = this.Context.DbMehtods.IIF(new MethodCallExpressionModel()
|
||||
{
|
||||
Args = new List<MethodCallExpressionArgs>() {
|
||||
new MethodCallExpressionArgs(){ IsMember=true, MemberName=AppendParameter(parameter.CommonTempData)+"=1" },
|
||||
new MethodCallExpressionArgs(){ IsMember=true,MemberName=AppendParameter(0) },
|
||||
new MethodCallExpressionArgs(){ IsMember=true, MemberName=AppendParameter(1) }
|
||||
}
|
||||
});
|
||||
this.Context.Result.Append(result);
|
||||
parameter.BaseParameter.ChildExpression = base.Expression;
|
||||
parameter.CommonTempData = null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -9,6 +9,7 @@ namespace SqlSugar
|
||||
SqlSugarProvider Context { get; set; }
|
||||
|
||||
#region DML
|
||||
List<string> GetDataBaseList(SqlSugarClient db);
|
||||
List<DbTableInfo> GetViewInfoList(bool isCache=true);
|
||||
List<DbTableInfo> GetTableInfoList(bool isCache=true);
|
||||
List<DbColumnInfo> GetColumnInfosByTableName(string tableName,bool isCache=true);
|
||||
@@ -26,6 +27,8 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region DDL
|
||||
bool AddDefaultValue(string tableName,string columnName,string defaultValue);
|
||||
bool CreateIndex(string tableName, string [] columnNames);
|
||||
bool DropTable(string tableName);
|
||||
bool TruncateTable(string tableName);
|
||||
bool TruncateTable<T>();
|
||||
@@ -40,6 +43,10 @@ namespace SqlSugar
|
||||
bool DropColumn(string tableName,string columnName);
|
||||
bool RenameColumn(string tableName, string oldColumnName, string newColumnName);
|
||||
bool AddRemark(EntityInfo entity);
|
||||
void AddIndex(EntityInfo entityInfo);
|
||||
void AddDefaultValue(EntityInfo entityInfo);
|
||||
bool IsAnyDefaultValue(string tableName, string columnName);
|
||||
bool IsAnyIndex(string indexName);
|
||||
bool AddColumnRemark(string columnName,string tableName,string description);
|
||||
bool DeleteColumnRemark(string columnName, string tableName);
|
||||
bool IsAnyColumnRemark(string columnName, string tableName);
|
||||
@@ -60,7 +67,6 @@ namespace SqlSugar
|
||||
/// <param name="databaseDirectory"></param>
|
||||
/// <returns></returns>
|
||||
bool CreateDatabase(string databaseName,string databaseDirectory = null);
|
||||
List<string> GetDataBaseList(SqlSugarClient db);
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@@ -245,6 +245,29 @@ namespace SqlSugar
|
||||
return "alter table {0} rename {1}";
|
||||
}
|
||||
}
|
||||
|
||||
protected override string CreateIndexSql
|
||||
{
|
||||
get
|
||||
{
|
||||
return "CREATE INDEX Index_{0}_{2} ON {0} ({1})";
|
||||
}
|
||||
}
|
||||
|
||||
protected override string AddDefaultValueSql
|
||||
{
|
||||
get
|
||||
{
|
||||
return "ALTER TABLE {0} ALTER COLUMN {1} SET DEFAULT '{2}'";
|
||||
}
|
||||
}
|
||||
protected override string IsAnyIndexSql
|
||||
{
|
||||
get
|
||||
{
|
||||
return "SELECT count(*) FROM information_schema.statistics WHERE index_name = '{0}'";
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
@@ -397,7 +420,25 @@ namespace SqlSugar
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool AddDefaultValue(string tableName, string columnName, string defaultValue)
|
||||
{
|
||||
if (defaultValue == "''")
|
||||
{
|
||||
defaultValue = "";
|
||||
}
|
||||
if (defaultValue.ToLower().IsIn("now()", "current_timestamp"))
|
||||
{
|
||||
string template = "ALTER table {0} CHANGE COLUMN {1} {1} {3} default {2}";
|
||||
var dbColumnInfo=this.Context.DbMaintenance.GetColumnInfosByTableName(tableName).First(it => it.DbColumnName.Equals(columnName, StringComparison.CurrentCultureIgnoreCase));
|
||||
string sql = string.Format(template, tableName, columnName, defaultValue, dbColumnInfo.DataType);
|
||||
this.Context.Ado.ExecuteCommand(sql);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return base.AddDefaultValue(tableName,columnName,defaultValue);
|
||||
}
|
||||
}
|
||||
public override bool IsAnyConstraint(string constraintName)
|
||||
{
|
||||
throw new NotSupportedException("MySql IsAnyConstraint NotSupportedException");
|
||||
|
@@ -51,6 +51,27 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region DDL
|
||||
protected override string IsAnyIndexSql
|
||||
{
|
||||
get
|
||||
{
|
||||
return "select count(1) from user_ind_columns where index_name=('{0}')";
|
||||
}
|
||||
}
|
||||
protected override string CreateIndexSql
|
||||
{
|
||||
get
|
||||
{
|
||||
return "CREATE INDEX Index_{0}_{2} ON {0}({1})";
|
||||
}
|
||||
}
|
||||
protected override string AddDefaultValueSql
|
||||
{
|
||||
get
|
||||
{
|
||||
return "ALTER TABLE {0} MODIFY({1} DEFAULT '{2}')";
|
||||
}
|
||||
}
|
||||
protected override string CreateDataBaseSql
|
||||
{
|
||||
get
|
||||
@@ -142,48 +163,6 @@ namespace SqlSugar
|
||||
return "ALTER TABLE {0} rename column {1} to {2}";
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Check
|
||||
protected override string CheckSystemTablePermissionsSql
|
||||
{
|
||||
get
|
||||
{
|
||||
return "select t.table_name from user_tables t where rownum=1";
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Scattered
|
||||
protected override string CreateTableNull
|
||||
{
|
||||
get
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
protected override string CreateTableNotNull
|
||||
{
|
||||
get
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
protected override string CreateTablePirmaryKey
|
||||
{
|
||||
get
|
||||
{
|
||||
return "PRIMARY KEY";
|
||||
}
|
||||
}
|
||||
protected override string CreateTableIdentity
|
||||
{
|
||||
get
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
protected override string AddColumnRemarkSql
|
||||
{
|
||||
get
|
||||
@@ -232,7 +211,8 @@ namespace SqlSugar
|
||||
}
|
||||
}
|
||||
|
||||
protected override string RenameTableSql {
|
||||
protected override string RenameTableSql
|
||||
{
|
||||
get
|
||||
{
|
||||
return "alter table {0} rename to {1}";
|
||||
@@ -240,7 +220,81 @@ namespace SqlSugar
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Check
|
||||
protected override string CheckSystemTablePermissionsSql
|
||||
{
|
||||
get
|
||||
{
|
||||
return "select t.table_name from user_tables t where rownum=1";
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Scattered
|
||||
protected override string CreateTableNull
|
||||
{
|
||||
get
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
protected override string CreateTableNotNull
|
||||
{
|
||||
get
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
protected override string CreateTablePirmaryKey
|
||||
{
|
||||
get
|
||||
{
|
||||
return "PRIMARY KEY";
|
||||
}
|
||||
}
|
||||
protected override string CreateTableIdentity
|
||||
{
|
||||
get
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
public override bool AddColumn(string tableName, DbColumnInfo columnInfo)
|
||||
{
|
||||
if (columnInfo.DataType == "varchar"&& columnInfo.Length ==0)
|
||||
{
|
||||
columnInfo.DataType = "varchar2";
|
||||
columnInfo.Length = 50;
|
||||
}
|
||||
return base.AddColumn(tableName,columnInfo);
|
||||
}
|
||||
public override bool CreateIndex(string tableName, string[] columnNames)
|
||||
{
|
||||
string sql = string.Format(CreateIndexSql, tableName, string.Join(",", columnNames), string.Join("_", columnNames.Select(it=>(it+"abc").Substring(0,3))));
|
||||
this.Context.Ado.ExecuteCommand(sql);
|
||||
return true;
|
||||
}
|
||||
public override bool AddDefaultValue(string tableName, string columnName, string defaultValue)
|
||||
{
|
||||
if (defaultValue == "''")
|
||||
{
|
||||
defaultValue = "";
|
||||
}
|
||||
if (defaultValue.ToLower().IsIn("sysdate"))
|
||||
{
|
||||
var template = AddDefaultValueSql.Replace("'", "");
|
||||
string sql = string.Format(template,tableName,columnName,defaultValue);
|
||||
this.Context.Ado.ExecuteCommand(sql);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return base.AddDefaultValue(tableName, columnName, defaultValue);
|
||||
}
|
||||
}
|
||||
public override bool CreateDatabase(string databaseDirectory = null)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
|
@@ -160,6 +160,42 @@ namespace SqlSugar
|
||||
return "ALTER TABLE {0} RENAME {1} TO {2}";
|
||||
}
|
||||
}
|
||||
protected override string AddColumnRemarkSql => "comment on column {1}.{0} is '{2}'";
|
||||
|
||||
protected override string DeleteColumnRemarkSql => "comment on column {1}.{0} is ''";
|
||||
|
||||
protected override string IsAnyColumnRemarkSql => throw new NotSupportedException();
|
||||
|
||||
protected override string AddTableRemarkSql => "comment on table {0} is '{1}'";
|
||||
|
||||
protected override string DeleteTableRemarkSql => "comment on table {0} is ''";
|
||||
|
||||
protected override string IsAnyTableRemarkSql => throw new NotSupportedException();
|
||||
|
||||
protected override string RenameTableSql => "alter table 表名 {0} to {1}";
|
||||
|
||||
protected override string CreateIndexSql
|
||||
{
|
||||
get
|
||||
{
|
||||
return "CREATE INDEX Index_{0}_{2} ON {0} ({1})";
|
||||
}
|
||||
}
|
||||
protected override string AddDefaultValueSql
|
||||
{
|
||||
get
|
||||
{
|
||||
return "ALTER TABLE {0} ALTER COLUMN {1} SET DEFAULT {2}";
|
||||
}
|
||||
}
|
||||
protected override string IsAnyIndexSql
|
||||
{
|
||||
get
|
||||
{
|
||||
return " Select count(1) from (SELECT to_regclass('Index_UnitCodeTest1_Id_CreateDate') as c ) t where t.c is not null";
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Check
|
||||
@@ -201,22 +237,7 @@ namespace SqlSugar
|
||||
return "serial";
|
||||
}
|
||||
}
|
||||
|
||||
protected override string AddColumnRemarkSql => "comment on column {1}.{0} is '{2}'";
|
||||
|
||||
protected override string DeleteColumnRemarkSql => "comment on column {1}.{0} is ''";
|
||||
|
||||
protected override string IsAnyColumnRemarkSql => throw new NotSupportedException();
|
||||
|
||||
protected override string AddTableRemarkSql => "comment on table {0} is '{1}'";
|
||||
|
||||
protected override string DeleteTableRemarkSql => "comment on table {0} is ''";
|
||||
|
||||
protected override string IsAnyTableRemarkSql => throw new NotSupportedException();
|
||||
|
||||
protected override string RenameTableSql => "alter table 表名 {0} to {1}";
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
/// <summary>
|
||||
|
@@ -173,48 +173,6 @@ namespace SqlSugar
|
||||
return "exec sp_rename '{0}.{1}','{2}','column';";
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Check
|
||||
protected override string CheckSystemTablePermissionsSql
|
||||
{
|
||||
get
|
||||
{
|
||||
return "select top 1 id from sysobjects";
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Scattered
|
||||
protected override string CreateTableNull
|
||||
{
|
||||
get
|
||||
{
|
||||
return "NULL";
|
||||
}
|
||||
}
|
||||
protected override string CreateTableNotNull
|
||||
{
|
||||
get
|
||||
{
|
||||
return "NOT NULL";
|
||||
}
|
||||
}
|
||||
protected override string CreateTablePirmaryKey
|
||||
{
|
||||
get
|
||||
{
|
||||
return "PRIMARY KEY";
|
||||
}
|
||||
}
|
||||
protected override string CreateTableIdentity
|
||||
{
|
||||
get
|
||||
{
|
||||
return "IDENTITY(1,1)";
|
||||
}
|
||||
}
|
||||
|
||||
protected override string AddColumnRemarkSql
|
||||
{
|
||||
get
|
||||
@@ -287,7 +245,73 @@ namespace SqlSugar
|
||||
}
|
||||
}
|
||||
|
||||
protected override string CreateIndexSql
|
||||
{
|
||||
get
|
||||
{
|
||||
return "CREATE NONCLUSTERED INDEX Index_{0}_{2} ON {0}({1})";
|
||||
}
|
||||
}
|
||||
protected override string AddDefaultValueSql
|
||||
{
|
||||
get
|
||||
{
|
||||
return "alter table {0} ADD DEFAULT '{2}' FOR {1}";
|
||||
}
|
||||
}
|
||||
protected override string IsAnyIndexSql
|
||||
{
|
||||
get
|
||||
{
|
||||
return "select count(*) from sys.indexes where name='{0}'";
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Check
|
||||
protected override string CheckSystemTablePermissionsSql
|
||||
{
|
||||
get
|
||||
{
|
||||
return "select top 1 id from sysobjects";
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Scattered
|
||||
protected override string CreateTableNull
|
||||
{
|
||||
get
|
||||
{
|
||||
return "NULL";
|
||||
}
|
||||
}
|
||||
protected override string CreateTableNotNull
|
||||
{
|
||||
get
|
||||
{
|
||||
return "NOT NULL";
|
||||
}
|
||||
}
|
||||
protected override string CreateTablePirmaryKey
|
||||
{
|
||||
get
|
||||
{
|
||||
return "PRIMARY KEY";
|
||||
}
|
||||
}
|
||||
protected override string CreateTableIdentity
|
||||
{
|
||||
get
|
||||
{
|
||||
return "IDENTITY(1,1)";
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
///by current connection string
|
||||
/// </summary>
|
||||
@@ -305,7 +329,8 @@ namespace SqlSugar
|
||||
var oldDatabaseName = this.Context.Ado.Connection.Database;
|
||||
var connection = this.Context.CurrentConnectionConfig.ConnectionString;
|
||||
connection = connection.Replace(oldDatabaseName, "master");
|
||||
var newDb = new SqlSugarClient(new ConnectionConfig() {
|
||||
var newDb = new SqlSugarClient(new ConnectionConfig()
|
||||
{
|
||||
DbType = this.Context.CurrentConnectionConfig.DbType,
|
||||
IsAutoCloseConnection = true,
|
||||
ConnectionString = connection
|
||||
@@ -330,7 +355,7 @@ namespace SqlSugar
|
||||
maxsize = 100mb,
|
||||
filegrowth = 10 %
|
||||
)
|
||||
log on --逻辑文件
|
||||
log on
|
||||
(
|
||||
name = N'{0}_log',
|
||||
filename = N'{1}\{0}.ldf',
|
||||
@@ -353,7 +378,7 @@ namespace SqlSugar
|
||||
var pkColumns = columns.Where(it => it.IsPrimarykey).ToList();
|
||||
if (pkColumns.Count > 1)
|
||||
{
|
||||
this.Context.DbMaintenance.AddPrimaryKeys(tableName, pkColumns.Select(it=>it.DbColumnName).ToArray());
|
||||
this.Context.DbMaintenance.AddPrimaryKeys(tableName, pkColumns.Select(it => it.DbColumnName).ToArray());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -365,7 +390,6 @@ namespace SqlSugar
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool RenameColumn(string tableName, string oldColumnName, string newColumnName)
|
||||
{
|
||||
tableName = this.SqlBuilder.GetTranslationTableName(tableName);
|
||||
@@ -374,6 +398,7 @@ namespace SqlSugar
|
||||
string sql = string.Format(this.RenameColumnSql, tableName, oldColumnName, newColumnName);
|
||||
this.Context.Ado.ExecuteCommand(sql);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@@ -20,6 +20,18 @@ namespace SqlSugar
|
||||
}
|
||||
public partial class SqlServerMethod : DefaultDbMethod, IDbMethods
|
||||
{
|
||||
|
||||
public override string HasValue(MethodCallExpressionModel model)
|
||||
{
|
||||
if (model.Args[0].Type == UtilConstants.GuidType)
|
||||
{
|
||||
var parameter = model.Args[0];
|
||||
return string.Format("( {0} IS NOT NULL )", parameter.MemberName);
|
||||
}
|
||||
else
|
||||
{
|
||||
var parameter = model.Args[0];
|
||||
return string.Format("( {0}<>'' AND {0} IS NOT NULL )", parameter.MemberName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -232,6 +232,12 @@ namespace SqlSugar
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
protected override string CreateIndexSql => throw new NotSupportedException();
|
||||
|
||||
protected override string IsAnyIndexSql => throw new NotSupportedException();
|
||||
|
||||
protected override string AddDefaultValueSql => throw new NotSupportedException();
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<Version>5.0.0.2</Version>
|
||||
<Version>5.0.0.3</Version>
|
||||
<Copyright>sun_kai_xuan</Copyright>
|
||||
<PackageProjectUrl>https://github.com/sunkaixuan/SqlSugar</PackageProjectUrl>
|
||||
<PackageLicenseUrl></PackageLicenseUrl>
|
||||
|
@@ -2,7 +2,7 @@
|
||||
<package >
|
||||
<metadata>
|
||||
<id>sqlSugarCore</id>
|
||||
<version>5.0.0.2</version>
|
||||
<version>5.0.0.3</version>
|
||||
<authors>sunkaixuan</authors>
|
||||
<owners>Landa</owners>
|
||||
<licenseUrl>http://www.apache.org/licenses/LICENSE-2.0.html</licenseUrl>
|
||||
|
@@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Security.Cryptography;
|
||||
@@ -12,6 +14,39 @@ namespace SqlSugar
|
||||
{
|
||||
public class UtilMethods
|
||||
{
|
||||
|
||||
internal static object To(object value, Type destinationType)
|
||||
{
|
||||
return To(value, destinationType, CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
internal static object To(object value, Type destinationType, CultureInfo culture)
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
var sourceType = value.GetType();
|
||||
|
||||
var destinationConverter = TypeDescriptor.GetConverter(destinationType);
|
||||
if (destinationConverter != null && destinationConverter.CanConvertFrom(value.GetType()))
|
||||
return destinationConverter.ConvertFrom(null, culture, value);
|
||||
|
||||
var sourceConverter = TypeDescriptor.GetConverter(sourceType);
|
||||
if (sourceConverter != null && sourceConverter.CanConvertTo(destinationType))
|
||||
return sourceConverter.ConvertTo(null, culture, value, destinationType);
|
||||
|
||||
if (destinationType.IsEnum && value is int)
|
||||
return Enum.ToObject(destinationType, (int)value);
|
||||
|
||||
if (!destinationType.IsInstanceOfType(value))
|
||||
return Convert.ChangeType(value, destinationType, culture);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
internal static T To<T>(object value)
|
||||
{
|
||||
return (T)To(value, typeof(T));
|
||||
}
|
||||
internal static Type GetUnderType(Type oldType)
|
||||
{
|
||||
Type type = Nullable.GetUnderlyingType(oldType);
|
||||
|
Reference in New Issue
Block a user