mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-24 18:04:52 +08:00
Update Sqlite Insertable
This commit is contained in:
parent
7bf72aa4bb
commit
ccfa7177b1
@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
@ -33,7 +35,48 @@ namespace SqlSugar
|
||||
return "INSERT INTO {0} ({1})";
|
||||
}
|
||||
}
|
||||
public override string ToSqlString()
|
||||
{
|
||||
if (IsNoInsertNull)
|
||||
{
|
||||
DbColumnInfoList = DbColumnInfoList.Where(it => it.Value != null).ToList();
|
||||
}
|
||||
var groupList = DbColumnInfoList.GroupBy(it => it.TableId).ToList();
|
||||
var isSingle = groupList.Count() == 1;
|
||||
string columnsString = string.Join(",", groupList.First().Select(it => Builder.GetTranslationColumnName(it.DbColumnName)));
|
||||
if (isSingle)
|
||||
{
|
||||
string columnParametersString = string.Join(",", this.DbColumnInfoList.Select(it => Builder.SqlParameterKeyWord + it.DbColumnName));
|
||||
return string.Format(SqlTemplate, GetTableNameString, columnsString, columnParametersString);
|
||||
}
|
||||
else
|
||||
{
|
||||
StringBuilder batchInsetrSql = new StringBuilder();
|
||||
batchInsetrSql.Append("INSERT INTO " + GetTableNameString + " ");
|
||||
batchInsetrSql.Append("(");
|
||||
batchInsetrSql.Append(columnsString);
|
||||
batchInsetrSql.Append(") VALUES");
|
||||
string insertColumns = "";
|
||||
foreach (var item in groupList)
|
||||
{
|
||||
batchInsetrSql.Append("(");
|
||||
insertColumns = string.Join(",", item.Select(it => FormatValue(it.Value)));
|
||||
batchInsetrSql.Append(insertColumns);
|
||||
if (groupList.Last() == item)
|
||||
{
|
||||
batchInsetrSql.Append(") ");
|
||||
}
|
||||
else
|
||||
{
|
||||
batchInsetrSql.Append("), ");
|
||||
}
|
||||
}
|
||||
|
||||
batchInsetrSql.AppendLine(";SELECT LAST_INSERT_ROWID();");
|
||||
var result = batchInsetrSql.ToString();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
public override object FormatValue(object value)
|
||||
{
|
||||
if (value == null)
|
||||
|
Loading…
Reference in New Issue
Block a user