This commit is contained in:
skx
2020-11-04 19:56:52 +08:00
parent ddd21e9064
commit 1b05f4d956

View File

@@ -50,7 +50,7 @@ namespace SqlSugar
var isDisableMasterSlaveSeparation = this.Context.Ado.IsDisableMasterSlaveSeparation; var isDisableMasterSlaveSeparation = this.Context.Ado.IsDisableMasterSlaveSeparation;
this.Context.Ado.IsDisableMasterSlaveSeparation = true; this.Context.Ado.IsDisableMasterSlaveSeparation = true;
var count = Ado.ExecuteCommand(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()); var count = Ado.ExecuteCommand(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray());
var result = (this.GetIdentityKeys().IsNullOrEmpty() || count == 0) ? 0 :Convert.ToInt64(GetSeqValue(GetSeqName())); var result = (this.GetIdentityKeys().IsNullOrEmpty() || count == 0) ? 0 : Convert.ToInt64(GetSeqValue(GetSeqName()));
this.Context.Ado.IsDisableMasterSlaveSeparation = isDisableMasterSlaveSeparation; this.Context.Ado.IsDisableMasterSlaveSeparation = isDisableMasterSlaveSeparation;
AutoEnd(oldIsAuto); AutoEnd(oldIsAuto);
@@ -67,7 +67,7 @@ namespace SqlSugar
RestoreMapping(); RestoreMapping();
var isDisableMasterSlaveSeparation = this.Context.Ado.IsDisableMasterSlaveSeparation; var isDisableMasterSlaveSeparation = this.Context.Ado.IsDisableMasterSlaveSeparation;
this.Context.Ado.IsDisableMasterSlaveSeparation = true; this.Context.Ado.IsDisableMasterSlaveSeparation = true;
var count =await Ado.ExecuteCommandAsync(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()); var count = await Ado.ExecuteCommandAsync(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray());
var result = (this.GetIdentityKeys().IsNullOrEmpty() || count == 0) ? 0 : GetSeqValue(GetSeqName()).ObjToInt(); var result = (this.GetIdentityKeys().IsNullOrEmpty() || count == 0) ? 0 : GetSeqValue(GetSeqName()).ObjToInt();
this.Context.Ado.IsDisableMasterSlaveSeparation = isDisableMasterSlaveSeparation; this.Context.Ado.IsDisableMasterSlaveSeparation = isDisableMasterSlaveSeparation;
@@ -85,7 +85,7 @@ namespace SqlSugar
RestoreMapping(); RestoreMapping();
var isDisableMasterSlaveSeparation = this.Context.Ado.IsDisableMasterSlaveSeparation; var isDisableMasterSlaveSeparation = this.Context.Ado.IsDisableMasterSlaveSeparation;
this.Context.Ado.IsDisableMasterSlaveSeparation = true; this.Context.Ado.IsDisableMasterSlaveSeparation = true;
var count =await Ado.ExecuteCommandAsync(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()); 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())); var result = (this.GetIdentityKeys().IsNullOrEmpty() || count == 0) ? 0 : Convert.ToInt64(GetSeqValue(GetSeqName()));
this.Context.Ado.IsDisableMasterSlaveSeparation = isDisableMasterSlaveSeparation; this.Context.Ado.IsDisableMasterSlaveSeparation = isDisableMasterSlaveSeparation;
@@ -98,7 +98,8 @@ namespace SqlSugar
if (oldIsAuto) if (oldIsAuto)
{ {
this.Context.Context.CurrentConnectionConfig.IsAutoCloseConnection = oldIsAuto; this.Context.Context.CurrentConnectionConfig.IsAutoCloseConnection = oldIsAuto;
this.Context.Ado.Close(); if (this.Ado.Transaction == null)
this.Context.Ado.Close();
} }
} }
@@ -114,7 +115,7 @@ namespace SqlSugar
} }
private object GetSeqValue(string seqName) private object GetSeqValue(string seqName)
{ {
return Ado.GetScalar(" SELECT " + seqName + ".currval FROM DUAL"); return Ado.GetScalar(" SELECT " + seqName + ".currval FROM DUAL");
} }
protected override void PreToSql() protected override void PreToSql()
{ {
@@ -129,15 +130,15 @@ namespace SqlSugar
int seqBeginValue = 0; int seqBeginValue = 0;
seqBeginValue = this.Ado.GetInt("select " + seqName + ".Nextval from dual"); seqBeginValue = this.Ado.GetInt("select " + seqName + ".Nextval from dual");
//Console.WriteLine(seqBeginValue); //Console.WriteLine(seqBeginValue);
var nextLength= insertCount - 1; var nextLength = insertCount - 1;
if (nextLength > 0) if (nextLength > 0)
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.AppendLine(" select "+ seqName + ".nextval,t.* from ("); sb.AppendLine(" select " + seqName + ".nextval,t.* from (");
for (int i = 0; i < nextLength; i++) for (int i = 0; i < nextLength; i++)
{ {
sb.AppendLine(" select 1 from dual"); sb.AppendLine(" select 1 from dual");
if (i<(nextLength - 1) ) if (i < (nextLength - 1))
{ {
sb.AppendLine("union all"); sb.AppendLine("union all");
} }