mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-05-18 22:19:33 +08:00
Synchronization code
This commit is contained in:
parent
8c44c9574e
commit
9748e1e67d
@ -49,57 +49,89 @@ namespace SqlSugar
|
||||
}
|
||||
else
|
||||
{
|
||||
StringBuilder batchInsetrSql = new StringBuilder();
|
||||
batchInsetrSql.AppendLine("INSERT ALL");
|
||||
foreach (var item in groupList)
|
||||
var bigSize = 500;
|
||||
if (groupList.Count < bigSize)
|
||||
{
|
||||
batchInsetrSql.Append("INTO " + GetTableNameString + " ");
|
||||
string insertColumns = "";
|
||||
|
||||
batchInsetrSql.Append("(");
|
||||
batchInsetrSql.Append(columnsString);
|
||||
if (identities.HasValue())
|
||||
{
|
||||
batchInsetrSql.Append("," + string.Join(",", identities.Select(it => Builder.GetTranslationColumnName(it.DbColumnName))));
|
||||
}
|
||||
batchInsetrSql.Append(") VALUES");
|
||||
|
||||
|
||||
batchInsetrSql.Append("(");
|
||||
insertColumns = string.Join(",", item.Select(it =>FormatValue(it.Value,it.PropertyName)));
|
||||
batchInsetrSql.Append(insertColumns);
|
||||
if (identities.HasValue())
|
||||
{
|
||||
batchInsetrSql.Append(",");
|
||||
foreach (var idn in identities)
|
||||
{
|
||||
var seqvalue = this.OracleSeqInfoList[idn.OracleSequenceName];
|
||||
this.OracleSeqInfoList[idn.OracleSequenceName] = this.OracleSeqInfoList[idn.OracleSequenceName] + 1;
|
||||
if (identities.Last() == idn)
|
||||
{
|
||||
batchInsetrSql.Append(seqvalue );
|
||||
}
|
||||
else
|
||||
{
|
||||
batchInsetrSql.Append(seqvalue + ",");
|
||||
}
|
||||
}
|
||||
}
|
||||
batchInsetrSql.AppendLine(") ");
|
||||
|
||||
string result = Small(identities, groupList, columnsString);
|
||||
return result;
|
||||
}
|
||||
if (identities.HasValue())
|
||||
else
|
||||
{
|
||||
batchInsetrSql.AppendLine("SELECT "+ (this.OracleSeqInfoList.First().Value-1) + " FROM DUAL");
|
||||
string result = Big(identities, groupList, columnsString);
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
batchInsetrSql.AppendLine("SELECT 1 FROM DUAL");
|
||||
}
|
||||
var result= batchInsetrSql.ToString();
|
||||
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");
|
||||
foreach (var item in groupList)
|
||||
{
|
||||
batchInsetrSql.Append("INTO " + GetTableNameString + " ");
|
||||
string insertColumns = "";
|
||||
|
||||
batchInsetrSql.Append("(");
|
||||
batchInsetrSql.Append(columnsString);
|
||||
if (identities.HasValue())
|
||||
{
|
||||
batchInsetrSql.Append("," + string.Join(",", identities.Select(it => Builder.GetTranslationColumnName(it.DbColumnName))));
|
||||
}
|
||||
batchInsetrSql.Append(") VALUES");
|
||||
|
||||
|
||||
batchInsetrSql.Append("(");
|
||||
insertColumns = string.Join(",", item.Select(it => FormatValue(it.Value, it.PropertyName)));
|
||||
batchInsetrSql.Append(insertColumns);
|
||||
if (identities.HasValue())
|
||||
{
|
||||
batchInsetrSql.Append(",");
|
||||
foreach (var idn in identities)
|
||||
{
|
||||
var seqvalue = this.OracleSeqInfoList[idn.OracleSequenceName];
|
||||
this.OracleSeqInfoList[idn.OracleSequenceName] = this.OracleSeqInfoList[idn.OracleSequenceName] + 1;
|
||||
if (identities.Last() == idn)
|
||||
{
|
||||
batchInsetrSql.Append(seqvalue);
|
||||
}
|
||||
else
|
||||
{
|
||||
batchInsetrSql.Append(seqvalue + ",");
|
||||
}
|
||||
}
|
||||
}
|
||||
batchInsetrSql.AppendLine(") ");
|
||||
|
||||
}
|
||||
if (identities.HasValue())
|
||||
{
|
||||
batchInsetrSql.AppendLine("SELECT " + (this.OracleSeqInfoList.First().Value - 1) + " FROM DUAL");
|
||||
}
|
||||
else
|
||||
{
|
||||
batchInsetrSql.AppendLine("SELECT 1 FROM DUAL");
|
||||
}
|
||||
var result = batchInsetrSql.ToString();
|
||||
return result;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
public object FormatValue(object value,string name)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user