From 8aa6beee1edfa6bb3ca36afb7bd45fcc3b0b10cc Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Sat, 26 Feb 2022 21:40:38 +0800 Subject: [PATCH] Support OleDb Insert --- .../Access/SqlBuilder/AccessInsertBuilder.cs | 3 ++- .../InsertableProvider/InsertableProvider.cs | 22 +++++++++++++++++-- .../SqlBuilderProvider/InsertBuilder.cs | 1 + 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Src/Asp.Net/SqlSugar.Access/Access/SqlBuilder/AccessInsertBuilder.cs b/Src/Asp.Net/SqlSugar.Access/Access/SqlBuilder/AccessInsertBuilder.cs index d8d132a1a..a19ebff09 100644 --- a/Src/Asp.Net/SqlSugar.Access/Access/SqlBuilder/AccessInsertBuilder.cs +++ b/Src/Asp.Net/SqlSugar.Access/Access/SqlBuilder/AccessInsertBuilder.cs @@ -8,6 +8,7 @@ namespace SqlSugar.Access { public class AccessInsertBuilder : InsertBuilder { + public override bool IsOleDb { get; set; } = true; public override string SqlTemplate { get @@ -17,7 +18,7 @@ namespace SqlSugar.Access return @"INSERT INTO {0} ({1}) VALUES - ({2}) ;"; + ({2}) ;select @@identity"; } else { diff --git a/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs index b5fb44f37..d6ee50773 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs @@ -69,7 +69,16 @@ namespace SqlSugar return 0; } string sql = _ExecuteReturnIdentity(); - var result = Ado.GetInt(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()); + var result = 0; + if (InsertBuilder.IsOleDb) + { + result = Ado.GetInt(sql.Split(';').First(), InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()); + result = Ado.GetInt(sql.Split(';').Last(), InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()); + } + else + { + result = Ado.GetInt(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()); + } After(sql, result); return result; } @@ -81,7 +90,16 @@ namespace SqlSugar return 0; } string sql = _ExecuteReturnBigIdentity(); - var result = Convert.ToInt64(Ado.GetScalar(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray())); + long result = 0; + if (InsertBuilder.IsOleDb) + { + result = Convert.ToInt64(Ado.GetScalar(sql.Split(';').First(), InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray())); + result = Convert.ToInt64(Ado.GetScalar(sql.Split(';').Last(), InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray())); + } + else + { + result= Convert.ToInt64(Ado.GetScalar(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray())); + } After(sql, result); return result; } diff --git a/Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/InsertBuilder.cs b/Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/InsertBuilder.cs index a5fb8332a..17e4027f8 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/InsertBuilder.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/InsertBuilder.cs @@ -30,6 +30,7 @@ namespace SqlSugar public EntityInfo EntityInfo { get; set; } public Dictionary OracleSeqInfoList { get; set; } public bool IsBlukCopy { get; set; } + public virtual bool IsOleDb { get; set; } #endregion #region SqlTemplate