Update Oracle Insertable(list)

This commit is contained in:
sunkaixuan 2020-09-25 14:47:19 +08:00
parent 9da41c1d7e
commit cbeb4e247d
2 changed files with 41 additions and 36 deletions

View File

@ -8,8 +8,8 @@ namespace OrmTest
{ {
public class Config public class Config
{ {
public static string ConnectionString = "Data Source=localhost/orcl;User ID=system;Password=jhl856615011;"; public static string ConnectionString = "Data Source=localhost/orcl;User ID=system;Password=jhl52771;";
public static string ConnectionString2 = "Data Source=localhost/orcl;User ID=system;Password=jhl856615011;"; public static string ConnectionString2 = "Data Source=localhost/orcl;User ID=system;Password=jhl52771;";
public static string ConnectionString3= "Data Source=localhost/orcl;User ID=system;Password=jhl856615011;"; public static string ConnectionString3= "Data Source=localhost/orcl;User ID=system;Password=jhl52771;";
} }
} }

View File

@ -49,42 +49,47 @@ namespace SqlSugar
else else
{ {
StringBuilder batchInsetrSql = new StringBuilder(); StringBuilder batchInsetrSql = new StringBuilder();
int pageSize = 200; batchInsetrSql.AppendLine("INSERT ALL");
int pageIndex = 1; foreach (var item in groupList)
int totalRecord = groupList.Count;
int pageCount = (totalRecord + pageSize - 1) / pageSize;
if (identities.HasValue())
{ {
columnsString = columnsString.TrimEnd(',') + "," + string.Join(",", identities.Select(it => Builder.GetTranslationColumnName(it.DbColumnName))); batchInsetrSql.Append("INTO " + GetTableNameString + " ");
} string insertColumns = "";
while (pageCount >= pageIndex)
{ batchInsetrSql.Append("(");
batchInsetrSql.AppendFormat(SqlTemplateBatch, GetTableNameString, columnsString); batchInsetrSql.Append(columnsString);
int i = 0; if (identities.HasValue())
foreach (var columns in groupList.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList())
{ {
var isFirst = i == 0; batchInsetrSql.Append("," + string.Join(",", identities.Select(it => Builder.GetTranslationColumnName(it.DbColumnName))));
if (!isFirst)
{
batchInsetrSql.Append(SqlTemplateBatchUnion);
}
var insertColumns = string.Join(",", columns.Select(it => string.Format(SqlTemplateBatchSelect, FormatValue(it.Value), Builder.GetTranslationColumnName(it.DbColumnName))));
if (identities.HasValue())
{
insertColumns = insertColumns.TrimEnd(',') + "," + string.Join(",", identities.Select(it =>
{
var seqValue = this.OracleSeqInfoList[it.OracleSequenceName];
this.OracleSeqInfoList[it.OracleSequenceName] = this.OracleSeqInfoList[it.OracleSequenceName] + 1;
return seqValue + 1+" AS "+it.DbColumnName;
}));
}
batchInsetrSql.Append("\r\n SELECT " + insertColumns + " FROM DUAL ");
++i;
} }
pageIndex++; batchInsetrSql.Append(") VALUES");
batchInsetrSql.Append("\r\n;\r\n");
batchInsetrSql.Append("(");
insertColumns = string.Join(",", item.Select(it =>FormatValue(it.Value)));
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 + 1 );
}
else
{
batchInsetrSql.Append(seqvalue + 1 + ",");
}
}
}
batchInsetrSql.AppendLine(") ");
} }
return "BEGIN\r\n"+ batchInsetrSql.ToString()+"\r\nEND;"; batchInsetrSql.AppendLine("SELECT 1 FROM DUAL");
var result= batchInsetrSql.ToString();
return result;
} }
} }
public override object FormatValue(object value) public override object FormatValue(object value)
@ -103,7 +108,7 @@ namespace SqlSugar
{ {
date = Convert.ToDateTime("1900-1-1"); date = Convert.ToDateTime("1900-1-1");
} }
return "to_date('"+ date.ToString("yyyy-MM-dd HH:mm:ss") + "', 'YYYY-MM-DD HH24:MI:SS') "; return "to_date('" + date.ToString("yyyy-MM-dd HH:mm:ss") + "', 'YYYY-MM-DD HH24:MI:SS') ";
} }
else if (type.IsEnum()) else if (type.IsEnum())
{ {