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