Update Oracle

This commit is contained in:
skx 2020-11-04 19:44:21 +08:00
parent 93487a4283
commit ddd21e9064
2 changed files with 67 additions and 11 deletions

View File

@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("5.0.1")]
[assembly: AssemblyFileVersion("5.0.1")]
[assembly: AssemblyVersion("5.0.1.01")]
[assembly: AssemblyFileVersion("5.0.1.01")]

View File

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SqlSugar
{
@ -22,6 +23,8 @@ namespace SqlSugar
}
public override int ExecuteReturnIdentity()
{
bool oldIsAuto = AutoBegin();
InsertBuilder.IsReturnIdentity = true;
PreToSql();
string sql = InsertBuilder.ToSqlString();
@ -31,11 +34,15 @@ namespace SqlSugar
var count = Ado.ExecuteCommand(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray());
var result = (this.GetIdentityKeys().IsNullOrEmpty() || count == 0) ? 0 : GetSeqValue(GetSeqName()).ObjToInt();
this.Context.Ado.IsDisableMasterSlaveSeparation = isDisableMasterSlaveSeparation;
AutoEnd(oldIsAuto);
return result;
}
public override long ExecuteReturnBigIdentity()
{
bool oldIsAuto = AutoBegin();
InsertBuilder.IsReturnIdentity = true;
PreToSql();
string sql = InsertBuilder.ToSqlString();
@ -45,20 +52,69 @@ namespace SqlSugar
var count = Ado.ExecuteCommand(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray());
var result = (this.GetIdentityKeys().IsNullOrEmpty() || count == 0) ? 0 :Convert.ToInt64(GetSeqValue(GetSeqName()));
this.Context.Ado.IsDisableMasterSlaveSeparation = isDisableMasterSlaveSeparation;
AutoEnd(oldIsAuto);
return result;
}
public async override Task<int> ExecuteReturnIdentityAsync()
{
bool oldIsAuto = AutoBegin();
InsertBuilder.IsReturnIdentity = true;
PreToSql();
string sql = InsertBuilder.ToSqlString();
RestoreMapping();
var isDisableMasterSlaveSeparation = this.Context.Ado.IsDisableMasterSlaveSeparation;
this.Context.Ado.IsDisableMasterSlaveSeparation = true;
var count =await Ado.ExecuteCommandAsync(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray());
var result = (this.GetIdentityKeys().IsNullOrEmpty() || count == 0) ? 0 : GetSeqValue(GetSeqName()).ObjToInt();
this.Context.Ado.IsDisableMasterSlaveSeparation = isDisableMasterSlaveSeparation;
AutoEnd(oldIsAuto);
return result;
}
public async override Task<long> ExecuteReturnBigIdentityAsync()
{
bool oldIsAuto = AutoBegin();
InsertBuilder.IsReturnIdentity = true;
PreToSql();
string sql = InsertBuilder.ToSqlString();
RestoreMapping();
var isDisableMasterSlaveSeparation = this.Context.Ado.IsDisableMasterSlaveSeparation;
this.Context.Ado.IsDisableMasterSlaveSeparation = true;
var count =await Ado.ExecuteCommandAsync(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray());
var result = (this.GetIdentityKeys().IsNullOrEmpty() || count == 0) ? 0 : Convert.ToInt64(GetSeqValue(GetSeqName()));
this.Context.Ado.IsDisableMasterSlaveSeparation = isDisableMasterSlaveSeparation;
AutoEnd(oldIsAuto);
return result;
}
private void AutoEnd(bool oldIsAuto)
{
if (oldIsAuto)
{
this.Context.Context.CurrentConnectionConfig.IsAutoCloseConnection = oldIsAuto;
this.Context.Ado.Close();
}
}
private bool AutoBegin()
{
var oldIsAuto = this.Context.Context.CurrentConnectionConfig.IsAutoCloseConnection;
if (this.Context.Context.CurrentConnectionConfig.IsAutoCloseConnection)
{
this.Context.Context.CurrentConnectionConfig.IsAutoCloseConnection = false;
}
return oldIsAuto;
}
private object GetSeqValue(string seqName)
{
try
{
return Ado.GetScalar(" SELECT " + seqName + ".currval FROM DUAL");
}
catch
{
Ado.GetScalar(" SELECT " + seqName + ".nextval FROM DUAL");
return Ado.GetScalar(" SELECT " + seqName + ".currval-1 FROM DUAL");
}
return Ado.GetScalar(" SELECT " + seqName + ".currval FROM DUAL");
}
protected override void PreToSql()
{