Update Oracle

This commit is contained in:
sunkaixuan 2017-10-14 17:34:30 +08:00
parent a82d174804
commit a3af101bce
2 changed files with 14 additions and 7 deletions

View File

@ -61,12 +61,12 @@ namespace SqlSugar
RestoreMapping();
return Convert.ToInt64( Ado.GetScalar(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()));
}
public T ExecuteReturnEntity()
public virtual T ExecuteReturnEntity()
{
ExecuteCommandIdentityIntoEntity();
return InsertObjs.First();
}
public bool ExecuteCommandIdentityIntoEntity()
public virtual bool ExecuteCommandIdentityIntoEntity()
{
var result = InsertObjs.First();
var identityKeys = GetIdentityKeys();

View File

@ -7,11 +7,12 @@ namespace SqlSugar
{
public class OracleInsertable<T> : InsertableProvider<T> where T : class, new()
{
protected override List<string> GetIdentityKeys()
{
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();
}
@ -26,13 +27,19 @@ namespace SqlSugar
string sql = InsertBuilder.ToSqlString();
RestoreMapping();
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;
}
public override int ExecuteCommand()
{
base.ExecuteCommand();
return base.InsertObjs.Count();
}
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()
@ -40,7 +47,7 @@ namespace SqlSugar
var identities = GetSeqNames();
var insertCount = InsertObjs.Count();
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");
foreach (var seqName in identities)
@ -49,7 +56,7 @@ namespace SqlSugar
this.Ado.ExecuteCommand("alter sequence " + seqName + " increment by " + insertCount);
seqBeginValue = this.Ado.GetInt("select " + seqName + ".Nextval from dual") - insertCount;
this.Ado.ExecuteCommand("alter sequence " + seqName + " increment by " + 1);
InsertBuilder.OracleSeqInfoList.Add(seqName,seqBeginValue);
InsertBuilder.OracleSeqInfoList.Add(seqName, seqBeginValue);
}
}
base.PreToSql();