mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-29 19:56:43 +08:00
Update Oracle
This commit is contained in:
parent
872f0ad1b9
commit
4298986216
@ -15,6 +15,10 @@ namespace SqlSugar
|
||||
{
|
||||
return this.EntityInfo.Columns.Where(it => it.OracleSequenceName.IsValuable()).Select(it => it.OracleSequenceName).First();
|
||||
}
|
||||
protected List<string> GetSeqNames()
|
||||
{
|
||||
return this.EntityInfo.Columns.Where(it => it.OracleSequenceName.IsValuable()).Select(it => it.OracleSequenceName).ToList();
|
||||
}
|
||||
public override int ExecuteReturnIdentity()
|
||||
{
|
||||
InsertBuilder.IsReturnIdentity = true;
|
||||
@ -22,12 +26,18 @@ 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 : Ado.GetInt(" SELECT "+GetSeqName()+".currval FROM DUAL");
|
||||
var result = (this.GetIdentityKeys().IsNullOrEmpty() || count == 0) ? 0 : GetSeqValue(GetSeqName() );
|
||||
return result;
|
||||
}
|
||||
|
||||
private int GetSeqValue(string seqName)
|
||||
{
|
||||
return Ado.GetInt(" SELECT " + seqName+ ".currval FROM DUAL");
|
||||
}
|
||||
|
||||
protected override void PreToSql()
|
||||
{
|
||||
var identities = GetIdentityKeys();
|
||||
var identities = GetSeqNames();
|
||||
var insertCount = InsertObjs.Count();
|
||||
InsertBuilder.OracleSeqInfoList = new Dictionary<string, int>();
|
||||
if (identities.IsValuable()&& insertCount > 1)
|
||||
|
@ -12,13 +12,20 @@ namespace SqlSugar
|
||||
{
|
||||
get
|
||||
{
|
||||
return @"INSERT INTO {0}
|
||||
return @"INSERT INTO {0}
|
||||
({1})
|
||||
VALUES
|
||||
({2}) ";
|
||||
|
||||
}
|
||||
}
|
||||
public override string SqlTemplateBatch
|
||||
{
|
||||
get
|
||||
{
|
||||
return "INSERT INTO {0} ({1})";
|
||||
}
|
||||
}
|
||||
public override string ToSqlString()
|
||||
{
|
||||
var identities = this.EntityInfo.Columns.Where(it => it.OracleSequenceName.IsValuable()).ToList();
|
||||
@ -32,9 +39,10 @@ namespace SqlSugar
|
||||
if (isSingle)
|
||||
{
|
||||
string columnParametersString = string.Join(",", this.DbColumnInfoList.Select(it => Builder.SqlParameterKeyWord + it.DbColumnName));
|
||||
if (identities.IsValuable()) {
|
||||
columnsString = columnsString.TrimEnd(',') + "," + string.Join(",", identities.Select(it=> Builder.GetTranslationColumnName(it.DbColumnName)));
|
||||
columnParametersString = columnParametersString.TrimEnd(',') +"," + string.Join(",", identities.Select(it =>it.OracleSequenceName+ ".nextval"));
|
||||
if (identities.IsValuable())
|
||||
{
|
||||
columnsString = columnsString.TrimEnd(',') + "," + string.Join(",", identities.Select(it => Builder.GetTranslationColumnName(it.DbColumnName)));
|
||||
columnParametersString = columnParametersString.TrimEnd(',') + "," + string.Join(",", identities.Select(it => it.OracleSequenceName + ".nextval"));
|
||||
}
|
||||
return string.Format(SqlTemplate, GetTableNameString, columnsString, columnParametersString);
|
||||
}
|
||||
@ -45,6 +53,10 @@ namespace SqlSugar
|
||||
int pageIndex = 1;
|
||||
int totalRecord = groupList.Count;
|
||||
int pageCount = (totalRecord + pageSize - 1) / pageSize;
|
||||
if (identities.IsValuable())
|
||||
{
|
||||
columnsString = columnsString.TrimEnd(',') + "," + string.Join(",", identities.Select(it => Builder.GetTranslationColumnName(it.DbColumnName)));
|
||||
}
|
||||
while (pageCount >= pageIndex)
|
||||
{
|
||||
batchInsetrSql.AppendFormat(SqlTemplateBatch, GetTableNameString, columnsString);
|
||||
@ -57,13 +69,22 @@ namespace SqlSugar
|
||||
batchInsetrSql.Append(SqlTemplateBatchUnion);
|
||||
}
|
||||
var insertColumns = string.Join(",", columns.Select(it => string.Format(SqlTemplateBatchSelect, FormatValue(it.Value), Builder.GetTranslationColumnName(it.DbColumnName))));
|
||||
if (identities.IsValuable())
|
||||
{
|
||||
insertColumns = insertColumns.TrimEnd(',') + "," + string.Join(",", identities.Select(it =>
|
||||
{
|
||||
var seqValue = this.OracleSeqInfoList[it.OracleSequenceName];
|
||||
this.OracleSeqInfoList[it.OracleSequenceName] = this.OracleSeqInfoList[it.OracleSequenceName] + 1;
|
||||
return seqValue + 1+" AS "+it.DbColumnName;
|
||||
}));
|
||||
}
|
||||
batchInsetrSql.Append("\r\n SELECT " + insertColumns + " FROM DUAL ");
|
||||
++i;
|
||||
}
|
||||
pageIndex++;
|
||||
batchInsetrSql.Append("\r\n;\r\n");
|
||||
}
|
||||
return batchInsetrSql.ToString();
|
||||
return "BEGIN\r\n"+ batchInsetrSql.ToString()+"\r\nEND;";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user