Update Core

This commit is contained in:
sunkaixuna
2021-10-05 20:42:37 +08:00
parent 40e1be196b
commit 5d1155c1f7
6 changed files with 29 additions and 17 deletions

View File

@@ -781,6 +781,7 @@ namespace SqlSugar
}
else
{
return this.Select<TResult>(this.SqlBuilder.SqlSelectAll);
}
}

View File

@@ -606,8 +606,14 @@ namespace SqlSugar
}
var result = Builder.GetTranslationTableName(name);
result += UtilConstants.Space;
if (result.Contains("MergeTable") && result.Trim().EndsWith(" MergeTable"))
if (IsSingle() && result.Contains("MergeTable") && result.Trim().EndsWith(" MergeTable") && TableShortName != null)
{
result = result.Replace(") MergeTable ", ") " + TableShortName);
TableShortName = null;
}
if (IsSingle() && result.Contains("unionTable") && result.Trim().EndsWith(" unionTable")&& TableShortName!=null)
{
result = result.Replace(" ) unionTable ", ") "+TableShortName);
TableShortName = null;
}
if (this.TableShortName.HasValue())

View File

@@ -13,6 +13,7 @@ namespace SqlSugar
switch (expressiontype)
{
case ExpressionType.And:
return "&";
case ExpressionType.AndAlso:
return "AND";
case ExpressionType.Equal:
@@ -28,6 +29,7 @@ namespace SqlSugar
case ExpressionType.NotEqual:
return "<>";
case ExpressionType.Or:
return "|";
case ExpressionType.OrElse:
return "OR";
case ExpressionType.Add:

View File

@@ -34,7 +34,7 @@ namespace SqlSugar
}
}
public override object FormatValue(object value)
public object FormatValue(object value,string name,int i)
{
if (value == null)
{
@@ -45,12 +45,9 @@ namespace SqlSugar
var type = value.GetType();
if (type == UtilConstants.DateType)
{
var date = value.ObjToDate();
if (date < Convert.ToDateTime("1900-1-1"))
{
date = Convert.ToDateTime("1900-1-1");
}
return "'" + date.ToString("yyyy-MM-dd HH:mm:ss.fff") + "'";
var parameterName = this.Builder.SqlParameterKeyWord + name + i;
this.Parameters.Add(new SugarParameter(parameterName, value));
return parameterName;
}
else if (type == UtilConstants.ByteArrayType)
{
@@ -148,7 +145,7 @@ namespace SqlSugar
dbType = "varchar";
}
}
return string.Format("CAST({0} AS {1})", FormatValue(it.Value), dbType);
return string.Format("CAST({0} AS {1})", FormatValue(it.Value,it.DbColumnName,i), dbType);
})) + ")");
++i;

View File

@@ -14,14 +14,14 @@ namespace SqlSugar
sb.AppendLine(string.Join("\r\n", groupList.Select(t =>
{
var updateTable = string.Format("UPDATE {0} SET", base.GetTableNameStringNoWith);
var setValues = string.Join(",", t.Where(s => !s.IsPrimarykey).Select(m => GetOracleUpdateColums(i,m)).ToArray());
var setValues = string.Join(",", t.Where(s => !s.IsPrimarykey).Select(m => GetOracleUpdateColums(i,m,false)).ToArray());
var pkList = t.Where(s => s.IsPrimarykey).ToList();
List<string> whereList = new List<string>();
foreach (var item in pkList)
{
var isFirst = pkList.First() == item;
var whereString = "";
whereString += GetOracleUpdateColums(i,item);
whereString += GetOracleUpdateColums(i,item,true);
whereList.Add(whereString);
}
i++;
@@ -30,12 +30,12 @@ namespace SqlSugar
return sb.ToString();
}
private string GetOracleUpdateColums(int i,DbColumnInfo m)
private string GetOracleUpdateColums(int i,DbColumnInfo m,bool iswhere)
{
return string.Format("\"{0}\"={1}", m.DbColumnName.ToUpper(), FormatValue(i,m.DbColumnName,m.Value));
return string.Format("\"{0}\"={1}", m.DbColumnName.ToUpper(), FormatValue(i,m.DbColumnName,m.Value,iswhere));
}
public object FormatValue(int i,string name,object value)
public object FormatValue(int i,string name,object value,bool iswhere)
{
if (value == null)
{
@@ -44,7 +44,7 @@ namespace SqlSugar
else
{
var type = UtilMethods.GetUnderType(value.GetType());
if (type == UtilConstants.DateType)
if (type == UtilConstants.DateType && iswhere == false)
{
var date = value.ObjToDate();
if (date < Convert.ToDateTime("1900-1-1"))
@@ -53,6 +53,12 @@ namespace SqlSugar
}
return "'" + date.ToString("yyyy-MM-dd HH:mm:ss.fff") + "'";
}
else if (type == UtilConstants.DateType && iswhere)
{
var parameterName = this.Builder.SqlParameterKeyWord + name + i;
this.Parameters.Add(new SugarParameter(parameterName, value));
return parameterName;
}
else if (type.IsEnum())
{
return Convert.ToInt64(value);

View File

@@ -140,9 +140,9 @@ namespace SqlSugar
itemSql = Regex.Replace(itemSql, string.Format(@"\+{0}\+", "\\" + itemParameter.ParameterName), "+" + newName + "+", RegexOptions.IgnoreCase);
itemSql = Regex.Replace(itemSql, string.Format(@"\+{0} ", "\\" + itemParameter.ParameterName), "+" + newName + " ", RegexOptions.IgnoreCase);
itemSql = Regex.Replace(itemSql, string.Format(@" {0}\+", "\\" + itemParameter.ParameterName), " " + newName + "+", RegexOptions.IgnoreCase);
itemSql = Regex.Replace(itemSql, string.Format(@"\|\|{0}\|\|", "\\" + itemParameter.ParameterName), "+" + newName + "+", RegexOptions.IgnoreCase);
itemSql = Regex.Replace(itemSql, string.Format(@"\|\|{0}\|\|", "\\" + itemParameter.ParameterName), "||" + newName + "||", RegexOptions.IgnoreCase);
itemSql = Regex.Replace(itemSql, string.Format(@"\={0}\+", "\\" + itemParameter.ParameterName), "=" + newName + "+", RegexOptions.IgnoreCase);
itemSql = Regex.Replace(itemSql, string.Format(@"{0}\|\|", "\\" + itemParameter.ParameterName), newName + "+", RegexOptions.IgnoreCase);
itemSql = Regex.Replace(itemSql, string.Format(@"{0}\|\|", "\\" + itemParameter.ParameterName), newName + "||", RegexOptions.IgnoreCase);
return itemSql;
}
internal static Type GetRootBaseType(Type entityType)