Update GetSqlString()

This commit is contained in:
sunkaixuan 2022-05-22 14:47:29 +08:00
parent 44799f9f2e
commit 4cb5bfa326
5 changed files with 19 additions and 6 deletions

View File

@ -447,7 +447,7 @@ namespace SqlSugar
var sqlObj = this.ToSql();
var result = sqlObj.Key;
if (result == null) return null;
result = UtilMethods.GetSqlString(this.Context.CurrentConnectionConfig, sqlObj, result);
result = UtilMethods.GetSqlString(this.Context.CurrentConnectionConfig, sqlObj);
return result;
}
public KeyValuePair<string, List<SugarParameter>> ToSql()

View File

@ -58,7 +58,7 @@ namespace SqlSugar
var sqlObj = this.ToSql();
var result = sqlObj.Key;
if (result == null) return null;
result = UtilMethods.GetSqlString(this.Context.CurrentConnectionConfig, sqlObj, result);
result = UtilMethods.GetSqlString(this.Context.CurrentConnectionConfig, sqlObj);
return result;
}
public virtual KeyValuePair<string, List<SugarParameter>> ToSql()

View File

@ -1937,7 +1937,7 @@ namespace SqlSugar
var sqlObj = this.Clone().ToSql();
var result = sqlObj.Key;
if (result == null) return null;
result = UtilMethods.GetSqlString(this.Context.CurrentConnectionConfig,sqlObj, result);
result = UtilMethods.GetSqlString(this.Context.CurrentConnectionConfig,sqlObj);
return result;
}

View File

@ -43,7 +43,7 @@ namespace SqlSugar
var sqlObj = this.ToSql();
var result = sqlObj.Key;
if (result == null) return null;
result = UtilMethods.GetSqlString(this.Context.CurrentConnectionConfig, sqlObj, result);
result = UtilMethods.GetSqlString(this.Context.CurrentConnectionConfig, sqlObj);
return result;
}

View File

@ -731,9 +731,22 @@ namespace SqlSugar
string FirstDay = datetime.AddDays(daydiff).ToString("yyyy-MM-dd");
return Convert.ToDateTime(FirstDay);
}
public static string GetSqlString(ConnectionConfig connectionConfig,KeyValuePair<string, List<SugarParameter>> sqlObj, string result)
public static string GetSqlString(DbType dbType, string sql, SugarParameter [] parametres,bool DisableNvarchar=false)
{
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)
{
foreach (var item in sqlObj.Value.OrderByDescending(it => it.ParameterName.Length))