mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-20 10:38:09 +08:00
Update Oracle
This commit is contained in:
@@ -61,12 +61,12 @@ namespace SqlSugar
|
|||||||
RestoreMapping();
|
RestoreMapping();
|
||||||
return Convert.ToInt64( Ado.GetScalar(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()));
|
return Convert.ToInt64( Ado.GetScalar(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()));
|
||||||
}
|
}
|
||||||
public T ExecuteReturnEntity()
|
public virtual T ExecuteReturnEntity()
|
||||||
{
|
{
|
||||||
ExecuteCommandIdentityIntoEntity();
|
ExecuteCommandIdentityIntoEntity();
|
||||||
return InsertObjs.First();
|
return InsertObjs.First();
|
||||||
}
|
}
|
||||||
public bool ExecuteCommandIdentityIntoEntity()
|
public virtual bool ExecuteCommandIdentityIntoEntity()
|
||||||
{
|
{
|
||||||
var result = InsertObjs.First();
|
var result = InsertObjs.First();
|
||||||
var identityKeys = GetIdentityKeys();
|
var identityKeys = GetIdentityKeys();
|
||||||
|
@@ -7,11 +7,12 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
public class OracleInsertable<T> : InsertableProvider<T> where T : class, new()
|
public class OracleInsertable<T> : InsertableProvider<T> where T : class, new()
|
||||||
{
|
{
|
||||||
|
|
||||||
protected override List<string> GetIdentityKeys()
|
protected override List<string> GetIdentityKeys()
|
||||||
{
|
{
|
||||||
return this.EntityInfo.Columns.Where(it => it.OracleSequenceName.HasValue()).Select(it => it.DbColumnName).ToList();
|
return this.EntityInfo.Columns.Where(it => it.OracleSequenceName.HasValue()).Select(it => it.DbColumnName).ToList();
|
||||||
}
|
}
|
||||||
protected string GetSeqName()
|
protected string GetSeqName()
|
||||||
{
|
{
|
||||||
return this.EntityInfo.Columns.Where(it => it.OracleSequenceName.HasValue()).Select(it => it.OracleSequenceName).First();
|
return this.EntityInfo.Columns.Where(it => it.OracleSequenceName.HasValue()).Select(it => it.OracleSequenceName).First();
|
||||||
}
|
}
|
||||||
@@ -26,13 +27,19 @@ namespace SqlSugar
|
|||||||
string sql = InsertBuilder.ToSqlString();
|
string sql = InsertBuilder.ToSqlString();
|
||||||
RestoreMapping();
|
RestoreMapping();
|
||||||
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 : GetSeqValue(GetSeqName() );
|
var result = (this.GetIdentityKeys().IsNullOrEmpty() || count == 0) ? 0 : GetSeqValue(GetSeqName());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override int ExecuteCommand()
|
||||||
|
{
|
||||||
|
base.ExecuteCommand();
|
||||||
|
return base.InsertObjs.Count();
|
||||||
|
}
|
||||||
|
|
||||||
private int GetSeqValue(string seqName)
|
private int GetSeqValue(string seqName)
|
||||||
{
|
{
|
||||||
return Ado.GetInt(" SELECT " + seqName+ ".currval FROM DUAL");
|
return Ado.GetInt(" SELECT " + seqName + ".currval FROM DUAL");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void PreToSql()
|
protected override void PreToSql()
|
||||||
@@ -40,7 +47,7 @@ namespace SqlSugar
|
|||||||
var identities = GetSeqNames();
|
var identities = GetSeqNames();
|
||||||
var insertCount = InsertObjs.Count();
|
var insertCount = InsertObjs.Count();
|
||||||
InsertBuilder.OracleSeqInfoList = new Dictionary<string, int>();
|
InsertBuilder.OracleSeqInfoList = new Dictionary<string, int>();
|
||||||
if (identities.HasValue()&& insertCount > 1)
|
if (identities.HasValue() && insertCount > 1)
|
||||||
{
|
{
|
||||||
Check.Exception(identities.Count != identities.Distinct().Count(), "The field sequence needs to be unique");
|
Check.Exception(identities.Count != identities.Distinct().Count(), "The field sequence needs to be unique");
|
||||||
foreach (var seqName in identities)
|
foreach (var seqName in identities)
|
||||||
@@ -49,7 +56,7 @@ namespace SqlSugar
|
|||||||
this.Ado.ExecuteCommand("alter sequence " + seqName + " increment by " + insertCount);
|
this.Ado.ExecuteCommand("alter sequence " + seqName + " increment by " + insertCount);
|
||||||
seqBeginValue = this.Ado.GetInt("select " + seqName + ".Nextval from dual") - insertCount;
|
seqBeginValue = this.Ado.GetInt("select " + seqName + ".Nextval from dual") - insertCount;
|
||||||
this.Ado.ExecuteCommand("alter sequence " + seqName + " increment by " + 1);
|
this.Ado.ExecuteCommand("alter sequence " + seqName + " increment by " + 1);
|
||||||
InsertBuilder.OracleSeqInfoList.Add(seqName,seqBeginValue);
|
InsertBuilder.OracleSeqInfoList.Add(seqName, seqBeginValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
base.PreToSql();
|
base.PreToSql();
|
||||||
|
Reference in New Issue
Block a user