mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-20 10:38:09 +08:00
Update Core
This commit is contained in:
@@ -447,7 +447,7 @@ namespace SqlSugar
|
|||||||
var sqlObj = this.ToSql();
|
var sqlObj = this.ToSql();
|
||||||
var result = sqlObj.Key;
|
var result = sqlObj.Key;
|
||||||
if (result == null) return null;
|
if (result == null) return null;
|
||||||
result = UtilMethods.GetSqlString(this.Context.CurrentConnectionConfig, sqlObj, result);
|
result = UtilMethods.GetSqlString(this.Context.CurrentConnectionConfig, sqlObj);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
public KeyValuePair<string, List<SugarParameter>> ToSql()
|
public KeyValuePair<string, List<SugarParameter>> ToSql()
|
||||||
|
@@ -58,7 +58,7 @@ namespace SqlSugar
|
|||||||
var sqlObj = this.ToSql();
|
var sqlObj = this.ToSql();
|
||||||
var result = sqlObj.Key;
|
var result = sqlObj.Key;
|
||||||
if (result == null) return null;
|
if (result == null) return null;
|
||||||
result = UtilMethods.GetSqlString(this.Context.CurrentConnectionConfig, sqlObj, result);
|
result = UtilMethods.GetSqlString(this.Context.CurrentConnectionConfig, sqlObj);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
public virtual KeyValuePair<string, List<SugarParameter>> ToSql()
|
public virtual KeyValuePair<string, List<SugarParameter>> ToSql()
|
||||||
|
@@ -1937,7 +1937,7 @@ namespace SqlSugar
|
|||||||
var sqlObj = this.Clone().ToSql();
|
var sqlObj = this.Clone().ToSql();
|
||||||
var result = sqlObj.Key;
|
var result = sqlObj.Key;
|
||||||
if (result == null) return null;
|
if (result == null) return null;
|
||||||
result = UtilMethods.GetSqlString(this.Context.CurrentConnectionConfig,sqlObj, result);
|
result = UtilMethods.GetSqlString(this.Context.CurrentConnectionConfig,sqlObj);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -43,7 +43,7 @@ namespace SqlSugar
|
|||||||
var sqlObj = this.ToSql();
|
var sqlObj = this.ToSql();
|
||||||
var result = sqlObj.Key;
|
var result = sqlObj.Key;
|
||||||
if (result == null) return null;
|
if (result == null) return null;
|
||||||
result = UtilMethods.GetSqlString(this.Context.CurrentConnectionConfig, sqlObj, result);
|
result = UtilMethods.GetSqlString(this.Context.CurrentConnectionConfig, sqlObj);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -10,6 +10,8 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
public SqlSugarProvider Context { get; set; }
|
public SqlSugarProvider Context { get; set; }
|
||||||
public void SetTable<T>(Expression<Func<T, object>> keyExpression, Expression<Func<T, object>> valueTextExpression, string uniqueCode = null, Expression<Func<T, object>> whereExpression=null)
|
public void SetTable<T>(Expression<Func<T, object>> keyExpression, Expression<Func<T, object>> valueTextExpression, string uniqueCode = null, Expression<Func<T, object>> whereExpression=null)
|
||||||
|
{
|
||||||
|
lock (SqlFuncExtendsion.TableInfos)
|
||||||
{
|
{
|
||||||
var entity = this.Context.EntityMaintenance.GetEntityInfo<T>();
|
var entity = this.Context.EntityMaintenance.GetEntityInfo<T>();
|
||||||
ExpressionContext context = new ExpressionContext();
|
ExpressionContext context = new ExpressionContext();
|
||||||
@@ -40,6 +42,7 @@ namespace SqlSugar
|
|||||||
Check.Exception(true, "SetKeyValue error , entity & uniqueCode already exist");
|
Check.Exception(true, "SetKeyValue error , entity & uniqueCode already exist");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public void SetTable<T>(Expression<Func<T, object>> key, Expression<Func<T, object>> value)
|
public void SetTable<T>(Expression<Func<T, object>> key, Expression<Func<T, object>> value)
|
||||||
{
|
{
|
||||||
SetTable<T>(key,value, null,null);
|
SetTable<T>(key,value, null,null);
|
||||||
|
@@ -254,6 +254,11 @@ namespace SqlSugar
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
|
public override bool TruncateTable(string tableName)
|
||||||
|
{
|
||||||
|
base.TruncateTable(tableName);
|
||||||
|
return this.Context.Ado.ExecuteCommand($"UPDATE sqlite_sequence SET seq = 0 WHERE name = '{tableName}'") > 0;
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///by current connection string
|
///by current connection string
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@@ -108,7 +108,8 @@ namespace SqlSugar
|
|||||||
IsAutoRemoveDataCache = it.MoreSettings.IsAutoRemoveDataCache,
|
IsAutoRemoveDataCache = it.MoreSettings.IsAutoRemoveDataCache,
|
||||||
IsWithNoLockQuery = it.MoreSettings.IsWithNoLockQuery,
|
IsWithNoLockQuery = it.MoreSettings.IsWithNoLockQuery,
|
||||||
TableEnumIsString = it.MoreSettings.TableEnumIsString,
|
TableEnumIsString = it.MoreSettings.TableEnumIsString,
|
||||||
DisableMillisecond = it.MoreSettings.DisableMillisecond
|
DisableMillisecond = it.MoreSettings.DisableMillisecond,
|
||||||
|
DbMinDate=it.MoreSettings.DbMinDate
|
||||||
},
|
},
|
||||||
SqlMiddle = it.SqlMiddle == null ? null : new SqlMiddle
|
SqlMiddle = it.SqlMiddle == null ? null : new SqlMiddle
|
||||||
{
|
{
|
||||||
@@ -730,13 +731,34 @@ namespace SqlSugar
|
|||||||
string FirstDay = datetime.AddDays(daydiff).ToString("yyyy-MM-dd");
|
string FirstDay = datetime.AddDays(daydiff).ToString("yyyy-MM-dd");
|
||||||
return Convert.ToDateTime(FirstDay);
|
return Convert.ToDateTime(FirstDay);
|
||||||
}
|
}
|
||||||
|
public static string GetSqlString(DbType dbType, string sql, SugarParameter [] parametres,bool DisableNvarchar=false)
|
||||||
public static string GetSqlString(ConnectionConfig connectionConfig,KeyValuePair<string, List<SugarParameter>> sqlObj, string result)
|
|
||||||
{
|
{
|
||||||
|
if (parametres == null)
|
||||||
|
parametres = new SugarParameter[] { };
|
||||||
|
return GetSqlString(new ConnectionConfig()
|
||||||
|
{
|
||||||
|
DbType = dbType,
|
||||||
|
MoreSettings=new ConnMoreSettings()
|
||||||
|
{
|
||||||
|
DisableNvarchar=DisableNvarchar
|
||||||
|
}
|
||||||
|
},new KeyValuePair<string, List<SugarParameter>>(sql,parametres.ToList()));
|
||||||
|
}
|
||||||
|
public static string GetSqlString(ConnectionConfig connectionConfig,KeyValuePair<string, List<SugarParameter>> sqlObj)
|
||||||
|
{
|
||||||
|
var result = sqlObj.Key;
|
||||||
if (sqlObj.Value != null)
|
if (sqlObj.Value != null)
|
||||||
{
|
{
|
||||||
foreach (var item in sqlObj.Value.OrderByDescending(it => it.ParameterName.Length))
|
foreach (var item in sqlObj.Value.OrderByDescending(it => it.ParameterName.Length))
|
||||||
{
|
{
|
||||||
|
if (connectionConfig.MoreSettings == null)
|
||||||
|
{
|
||||||
|
connectionConfig.MoreSettings = new ConnMoreSettings();
|
||||||
|
}
|
||||||
|
if (item.Value != null && item.Value is DateTime &&((DateTime)item.Value==DateTime.MinValue))
|
||||||
|
{
|
||||||
|
item.Value = connectionConfig.MoreSettings.DbMinDate;
|
||||||
|
}
|
||||||
if (item.Value == null || item.Value == DBNull.Value)
|
if (item.Value == null || item.Value == DBNull.Value)
|
||||||
{
|
{
|
||||||
result = result.Replace(item.ParameterName, "null");
|
result = result.Replace(item.ParameterName, "null");
|
||||||
@@ -745,6 +767,16 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
result = result.Replace(item.ParameterName, item.Value.ObjToString());
|
result = result.Replace(item.ParameterName, item.Value.ObjToString());
|
||||||
}
|
}
|
||||||
|
else if (item.Value is byte[])
|
||||||
|
{
|
||||||
|
result = result.Replace(item.ParameterName, "0x" + BitConverter.ToString((byte[])item.Value));
|
||||||
|
}
|
||||||
|
else if (item.Value.GetType() !=UtilConstants.StringType&& connectionConfig.DbType == DbType.PostgreSQL&& PostgreSQLDbBind.MappingTypesConst.Any(x =>x.Value.ToString().EqualCase(item.Value.GetType().Name)))
|
||||||
|
{
|
||||||
|
var type = PostgreSQLDbBind.MappingTypesConst.First(x => x.Value.ToString().EqualCase(item.Value.GetType().Name)).Key;
|
||||||
|
var replaceValue= string.Format("CAST('{0}' AS {1})", item.Value, type);
|
||||||
|
result = result.Replace(item.ParameterName, replaceValue);
|
||||||
|
}
|
||||||
else if (connectionConfig.MoreSettings?.DisableNvarchar == true || item.DbType == System.Data.DbType.AnsiString || connectionConfig.DbType == DbType.Sqlite)
|
else if (connectionConfig.MoreSettings?.DisableNvarchar == true || item.DbType == System.Data.DbType.AnsiString || connectionConfig.DbType == DbType.Sqlite)
|
||||||
{
|
{
|
||||||
result = result.Replace(item.ParameterName, $"'{item.Value.ObjToString()}'");
|
result = result.Replace(item.ParameterName, $"'{item.Value.ObjToString()}'");
|
||||||
|
Reference in New Issue
Block a user