Synchronization code

This commit is contained in:
sunkaixuan 2022-10-06 13:49:05 +08:00
parent 8c44c9574e
commit 9748e1e67d

View File

@ -48,6 +48,38 @@ namespace SqlSugar
return string.Format(SqlTemplate, GetTableNameString, columnsString, columnParametersString);
}
else
{
var bigSize = 500;
if (groupList.Count < bigSize)
{
string result = Small(identities, groupList, columnsString);
return result;
}
else
{
string result = Big(identities, groupList, columnsString);
return result;
}
}
}
private string Big(List<EntityColumnInfo> identities, List<IGrouping<int, DbColumnInfo>> groupList, string columnsString)
{
this.Context.Utilities.PageEach(groupList, 100, groupListPasge =>
{
var sql = Small(identities, groupListPasge, columnsString);
this.Context.Ado.ExecuteCommand(sql);
});
if (identities!=null&identities.Count > 0&& this.OracleSeqInfoList!=null&& this.OracleSeqInfoList.Any())
{
return $"SELECT {this.OracleSeqInfoList.First().Value-1} FROM DUAL";
}
else
{
return $"SELECT {groupList.Count} FROM DUAL";
}
}
private string Small(List<EntityColumnInfo> identities, List<IGrouping<int, DbColumnInfo>> groupList, string columnsString)
{
StringBuilder batchInsetrSql = new StringBuilder();
batchInsetrSql.AppendLine("INSERT ALL");
@ -66,7 +98,7 @@ namespace SqlSugar
batchInsetrSql.Append("(");
insertColumns = string.Join(",", item.Select(it =>FormatValue(it.Value,it.PropertyName)));
insertColumns = string.Join(",", item.Select(it => FormatValue(it.Value, it.PropertyName)));
batchInsetrSql.Append(insertColumns);
if (identities.HasValue())
{
@ -77,7 +109,7 @@ namespace SqlSugar
this.OracleSeqInfoList[idn.OracleSequenceName] = this.OracleSeqInfoList[idn.OracleSequenceName] + 1;
if (identities.Last() == idn)
{
batchInsetrSql.Append(seqvalue );
batchInsetrSql.Append(seqvalue);
}
else
{
@ -90,16 +122,16 @@ namespace SqlSugar
}
if (identities.HasValue())
{
batchInsetrSql.AppendLine("SELECT "+ (this.OracleSeqInfoList.First().Value-1) + " FROM DUAL");
batchInsetrSql.AppendLine("SELECT " + (this.OracleSeqInfoList.First().Value - 1) + " FROM DUAL");
}
else
{
batchInsetrSql.AppendLine("SELECT 1 FROM DUAL");
}
var result= batchInsetrSql.ToString();
var result = batchInsetrSql.ToString();
return result;
}
}
int i = 0;
public object FormatValue(object value,string name)
{