mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-19 18:22:23 +08:00
Update Oracle
This commit is contained in:
@@ -58,6 +58,8 @@ namespace OrmTest.Demo
|
||||
|
||||
//Column is null no update
|
||||
db.Updateable(updateObj).Where(true).ExecuteCommand();
|
||||
|
||||
db.Updateable(new Student[] { new Student() { Id=2, Name="a2" }, new Student() { Id = 1, Name = "a1" } }).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -25,7 +25,7 @@ namespace SqlSugar
|
||||
private bool IsOffIdentity { get; set; }
|
||||
public MappingTableList OldMappingTableList { get; set; }
|
||||
public bool IsAs { get; set; }
|
||||
public int ExecuteCommand()
|
||||
public virtual int ExecuteCommand()
|
||||
{
|
||||
PreToSql();
|
||||
Check.Exception(UpdateBuilder.WhereValues.IsNullOrEmpty() && GetPrimaryKeys().IsNullOrEmpty(), "You cannot have no primary key and no conditions");
|
||||
|
@@ -10,8 +10,32 @@ namespace SqlSugar
|
||||
{
|
||||
protected override string TomultipleSqlString(List<IGrouping<int, DbColumnInfo>> groupList)
|
||||
{
|
||||
throw new NotSupportedException("Oracle Waiting for updates updateable(List<T>)");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.AppendLine("Begin");
|
||||
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(m)).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 = isFirst ? " " : " AND ";
|
||||
whereString += GetOracleUpdateColums(item);
|
||||
whereList.Add(whereString);
|
||||
}
|
||||
return string.Format("{0} {1} WHERE {2};", updateTable, setValues, string.Join("AND",whereList));
|
||||
}).ToArray()));
|
||||
sb.AppendLine("End;");
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
private string GetOracleUpdateColums(DbColumnInfo m)
|
||||
{
|
||||
return string.Format("\"{0}\"={1}", m.DbColumnName.ToUpper(), FormatValue(m.Value));
|
||||
}
|
||||
|
||||
public override object FormatValue(object value)
|
||||
{
|
||||
if (value == null)
|
||||
|
@@ -11,5 +11,10 @@ namespace SqlSugar
|
||||
{
|
||||
return this.EntityInfo.Columns.Where(it => it.OracleSequenceName.HasValue()).Select(it => it.DbColumnName).ToList();
|
||||
}
|
||||
public override int ExecuteCommand()
|
||||
{
|
||||
base.ExecuteCommand();
|
||||
return base.UpdateObjs.Count();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user