Synchronous code

This commit is contained in:
sunkaixuan
2025-07-01 12:33:44 +08:00
parent d48271238f
commit 325860d075
6 changed files with 37 additions and 2 deletions

View File

@@ -24,7 +24,10 @@ namespace SqlSugar
result2.DbFastestProperties.IsOffIdentity = this.IsOffIdentity;
return result2;
case DbType.Sqlite:
return new SqliteFastBuilder(this.entityInfo);
var resultSqlite= new SqliteFastBuilder(this.entityInfo);
if (resultSqlite.DbFastestProperties != null)
resultSqlite.DbFastestProperties.IsIgnoreInsertError = this.IsIgnoreInsertError;
return resultSqlite;
case DbType.Oracle:
return new OracleFastBuilder(this.entityInfo);
case DbType.PostgreSQL:

View File

@@ -15,6 +15,7 @@ namespace SqlSugar
private string CharacterSet { get; set; }
private bool IsDataAop { get; set; }
private bool IsOffIdentity { get; set; }
private bool IsIgnoreInsertError { get; set; }
public IFastest<T> SetCharacterSet(string CharacterSet)
{
this.CharacterSet = CharacterSet;
@@ -25,6 +26,11 @@ namespace SqlSugar
this.IsDataAop = true;
return this;
}
public IFastest<T> IgnoreInsertError()
{
this.IsIgnoreInsertError = true;
return this;
}
public IFastest<T> RemoveDataCache()
{
CacheKey = typeof(T).FullName;

View File

@@ -568,6 +568,11 @@ namespace SqlSugar
this.InsertBuilder.MySqlIgnore = true;
return this;
}
public IInsertable<T> IgnoreInsertError()
{
this.InsertBuilder.MySqlIgnore = true;
return this;
}
public IInsertable<T> MySqlIgnore(bool isIgnore) {
if (isIgnore)
{

View File

@@ -104,7 +104,14 @@ namespace SqlSugar
public DateTime GetDate()
{
var sqlBuilder = InstanceFactory.GetSqlbuilder(this.Context.CurrentConnectionConfig);
return this.Ado.GetDateTime(sqlBuilder.FullSqlDateNow);
var obj= this.Ado.GetScalar(sqlBuilder.FullSqlDateNow);
if (obj is DateTime s)
return s;
else if(obj is DateTimeOffset off)
{
return UtilMethods.ConvertFromDateTimeOffset(off);
}
return Convert.ToDateTime(obj);
}
public ISugarQueryable<T> MasterQueryable<T>()
{

View File

@@ -15,5 +15,6 @@ namespace SqlSugar
public bool IsNoCopyDataTable { get; set; }
public bool IsConvertDateTimeOffsetToDateTime { get; set; }
public bool NoPage { get; set; }
public bool IsIgnoreInsertError { get; internal set; }
}
}

View File

@@ -81,12 +81,14 @@ namespace SqlSugar
foreach (DataRow item in dt.Rows)
{
cmd.CommandText = this.Context.Insertable(UtilMethods.DataRowToDictionary(item)).AS(dt.TableName).ToSqlString().Replace(";SELECT LAST_INSERT_ROWID();", "");
TransformInsertCommand(cmd);
i += await cmd.ExecuteNonQueryAsync();
}
}
else
{
cmd.CommandText = this.Context.Insertable(dictionary.First()).AS(dt.TableName).ToSql().Key.Replace(";SELECT LAST_INSERT_ROWID();", "");
TransformInsertCommand(cmd);
foreach (DataRow dataRow in dt.Rows)
{
foreach (DataColumn item in dt.Columns)
@@ -201,6 +203,17 @@ namespace SqlSugar
});
return result;
}
private void TransformInsertCommand(SQLiteCommand cmd)
{
if (this.DbFastestProperties?.IsIgnoreInsertError == true)
{
const string insertPrefix = "INSERT INTO ";
if (cmd.CommandText.StartsWith(insertPrefix))
{
cmd.CommandText = "REPLACE INTO " + cmd.CommandText.Substring(insertPrefix.Length);
}
}
}
private static bool IsBoolFalse(DataRow dataRow, DataColumn item)
{
return dataRow[item.ColumnName] != null && dataRow[item.ColumnName] is string && dataRow[item.ColumnName].ToString() == ("isSqliteCore_False");