From cbeb4e247d2dcaa0db8d2ac476695ac281f3c879 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Fri, 25 Sep 2020 14:47:19 +0800 Subject: [PATCH] Update Oracle Insertable(list) --- Src/Asp.Net/OracleTest/Config.cs | 6 +- .../Oracle/SqlBuilder/OracleInsertBuilder.cs | 65 ++++++++++--------- 2 files changed, 38 insertions(+), 33 deletions(-) diff --git a/Src/Asp.Net/OracleTest/Config.cs b/Src/Asp.Net/OracleTest/Config.cs index 38338a263..92568ce83 100644 --- a/Src/Asp.Net/OracleTest/Config.cs +++ b/Src/Asp.Net/OracleTest/Config.cs @@ -8,8 +8,8 @@ namespace OrmTest { public class Config { - public static string ConnectionString = "Data Source=localhost/orcl;User ID=system;Password=jhl856615011;"; - public static string ConnectionString2 = "Data Source=localhost/orcl;User ID=system;Password=jhl856615011;"; - public static string ConnectionString3= "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=jhl52771;"; + public static string ConnectionString3= "Data Source=localhost/orcl;User ID=system;Password=jhl52771;"; } } diff --git a/Src/Asp.Net/SqlSugar/Realization/Oracle/SqlBuilder/OracleInsertBuilder.cs b/Src/Asp.Net/SqlSugar/Realization/Oracle/SqlBuilder/OracleInsertBuilder.cs index 892f40d8c..d77a1821d 100644 --- a/Src/Asp.Net/SqlSugar/Realization/Oracle/SqlBuilder/OracleInsertBuilder.cs +++ b/Src/Asp.Net/SqlSugar/Realization/Oracle/SqlBuilder/OracleInsertBuilder.cs @@ -49,42 +49,47 @@ namespace SqlSugar else { StringBuilder batchInsetrSql = new StringBuilder(); - int pageSize = 200; - int pageIndex = 1; - 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))); - } - while (pageCount >= pageIndex) + batchInsetrSql.AppendLine("INSERT ALL"); + foreach (var item in groupList) { - batchInsetrSql.AppendFormat(SqlTemplateBatch, GetTableNameString, columnsString); - int i = 0; - foreach (var columns in groupList.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList()) + batchInsetrSql.Append("INTO " + GetTableNameString + " "); + string insertColumns = ""; + + batchInsetrSql.Append("("); + batchInsetrSql.Append(columnsString); + if (identities.HasValue()) { - var isFirst = i == 0; - 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()) + 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))); + batchInsetrSql.Append(insertColumns); + if (identities.HasValue()) + { + batchInsetrSql.Append(","); + foreach (var idn in identities) { - insertColumns = insertColumns.TrimEnd(',') + "," + string.Join(",", identities.Select(it => + var seqvalue = this.OracleSeqInfoList[idn.OracleSequenceName]; + this.OracleSeqInfoList[idn.OracleSequenceName] = this.OracleSeqInfoList[idn.OracleSequenceName] + 1; + if (identities.Last() == idn) + { + batchInsetrSql.Append(seqvalue + 1 ); + } + else { - var seqValue = this.OracleSeqInfoList[it.OracleSequenceName]; - this.OracleSeqInfoList[it.OracleSequenceName] = this.OracleSeqInfoList[it.OracleSequenceName] + 1; - return seqValue + 1+" AS "+it.DbColumnName; - })); + batchInsetrSql.Append(seqvalue + 1 + ","); + } } - batchInsetrSql.Append("\r\n SELECT " + insertColumns + " FROM DUAL "); - ++i; } - pageIndex++; - batchInsetrSql.Append("\r\n;\r\n"); + 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) @@ -103,7 +108,7 @@ namespace SqlSugar { 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()) {