Browse Source

Oracle 12C+ Identity

pull/38/MERGE
sunkaixuan 1 year ago
parent
commit
83a9a8c260
  1. 4
      Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs
  2. 5
      Src/Asp.Net/SqlSugar/Abstract/EntityMaintenance/EntityMaintenance.cs
  3. 3
      Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertableHelper.cs
  4. 1
      Src/Asp.Net/SqlSugar/Entities/ConnMoreSettings.cs
  5. 4
      Src/Asp.Net/SqlSugar/Realization/Oracle/DbMaintenance/OracleDbMaintenance.cs
  6. 68
      Src/Asp.Net/SqlSugar/Realization/Oracle/Insertable/OracleInsertable.cs
  7. 5
      Src/Asp.Net/SqlSugar/Realization/Oracle/SqlBuilder/OracleInsertBuilder.cs
  8. 2
      Src/Asp.Net/SqlSugar/SqlSugar.nuspec
  9. 3
      Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs

4
Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs

@ -619,6 +619,10 @@ namespace SqlSugar
{
return false;
}
if (this.Context.CurrentConnectionConfig?.MoreSettings?.EnableOracleIdentity==true&&properyTypeName?.ToLower() == "int" && dataType?.ToLower() == "decimal")
{
return false;
}
if (properyTypeName?.ToLower() == "int" && dataType?.ToLower() == "decimal"&&dc.Length==22&&dc.Scale==0&&this.Context.CurrentConnectionConfig.DbType==DbType.Oracle)
{
return false;

5
Src/Asp.Net/SqlSugar/Abstract/EntityMaintenance/EntityMaintenance.cs

@ -386,6 +386,11 @@ namespace SqlSugar
column.Length = 0;
column.DecimalDigits = 0;
}
if (column.OracleSequenceName.HasValue() &&
this.Context.CurrentConnectionConfig?.MoreSettings?.EnableOracleIdentity == true)
{
column.OracleSequenceName = null;
}
result.Columns.Add(column);
}
}

3
Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertableHelper.cs

@ -248,7 +248,8 @@ namespace SqlSugar
InsertSql = column.InsertSql,
InsertServerTime = column.InsertServerTime,
DataType=column.DataType,
SqlParameterDbType= column.SqlParameterDbType
SqlParameterDbType= column.SqlParameterDbType ,
IsIdentity= column.IsIdentity
};
if (column.DbColumnName == null)

1
Src/Asp.Net/SqlSugar/Entities/ConnMoreSettings.cs

@ -23,5 +23,6 @@ namespace SqlSugar
public bool IsAutoUpdateQueryFilter { get; set; }
public bool IsAutoDeleteQueryFilter { get; set; }
public bool EnableModelFuncMappingColumn { get; set; }
public bool EnableOracleIdentity { get; set; }
}
}

4
Src/Asp.Net/SqlSugar/Realization/Oracle/DbMaintenance/OracleDbMaintenance.cs

@ -535,6 +535,10 @@ namespace SqlSugar
{
item.Length = 50;
}
if (item.IsIdentity && this.Context.CurrentConnectionConfig?.MoreSettings?.EnableOracleIdentity == true)
{
item.DataType = "NUMBER GENERATED ALWAYS AS IDENTITY";
}
}
}
string sql = GetCreateTableSql(tableName, columns);

68
Src/Asp.Net/SqlSugar/Realization/Oracle/Insertable/OracleInsertable.cs

@ -28,6 +28,18 @@ namespace SqlSugar
InsertBuilder.IsReturnIdentity = true;
PreToSql();
string sql = InsertBuilder.ToSqlString();
if (isIdEntityEnable())
{
if (sql?.StartsWith("INSERT ALL")==true)
{
return this.UseParameter().ExecuteCommand();
}
else
{
sql = sql + " RETURNING ID INTO :newId01 ";
}
InsertBuilder.Parameters.Add(new SugarParameter(":newId01", 0,true));
}
RestoreMapping();
var isDisableMasterSlaveSeparation = this.Context.Ado.IsDisableMasterSlaveSeparation;
this.Context.Ado.IsDisableMasterSlaveSeparation = true;
@ -36,8 +48,16 @@ namespace SqlSugar
this.Context.Ado.IsDisableMasterSlaveSeparation = isDisableMasterSlaveSeparation;
After(sql,result);
AutoEnd(oldIsAuto);
if (isIdEntityEnable())
{
return this.InsertBuilder.Parameters.FirstOrDefault(it => it.ParameterName == ":newId01")?.Value?.ObjToInt()??0;
}
return result;
}
private bool isIdEntityEnable()
{
return this.Context.CurrentConnectionConfig?.MoreSettings?.EnableOracleIdentity == true;
}
public override long ExecuteReturnBigIdentity()
{
@ -46,6 +66,18 @@ namespace SqlSugar
InsertBuilder.IsReturnIdentity = true;
PreToSql();
string sql = InsertBuilder.ToSqlString();
if (isIdEntityEnable())
{
if (sql?.StartsWith("INSERT ALL") == true)
{
return this.UseParameter().ExecuteCommand();
}
else
{
sql = sql + " RETURNING ID INTO :newId01 ";
}
InsertBuilder.Parameters.Add(new SugarParameter(":newId01", Convert.ToInt64(0), true));
}
RestoreMapping();
var isDisableMasterSlaveSeparation = this.Context.Ado.IsDisableMasterSlaveSeparation;
this.Context.Ado.IsDisableMasterSlaveSeparation = true;
@ -54,6 +86,10 @@ namespace SqlSugar
this.Context.Ado.IsDisableMasterSlaveSeparation = isDisableMasterSlaveSeparation;
After(sql, result);
AutoEnd(oldIsAuto);
if (isIdEntityEnable())
{
return this.InsertBuilder.Parameters.FirstOrDefault(it => it.ParameterName == ":newId01")?.Value?.ObjToLong() ?? 0;
}
return result;
}
@ -64,6 +100,18 @@ namespace SqlSugar
InsertBuilder.IsReturnIdentity = true;
PreToSql();
string sql = InsertBuilder.ToSqlString();
if (isIdEntityEnable())
{
if (sql?.StartsWith("INSERT ALL") == true)
{
return await this.UseParameter().ExecuteCommandAsync();
}
else
{
sql = sql + " RETURNING ID INTO :newId01 ";
}
InsertBuilder.Parameters.Add(new SugarParameter(":newId01", 0, true));
}
RestoreMapping();
var isDisableMasterSlaveSeparation = this.Context.Ado.IsDisableMasterSlaveSeparation;
this.Context.Ado.IsDisableMasterSlaveSeparation = true;
@ -72,6 +120,10 @@ namespace SqlSugar
this.Context.Ado.IsDisableMasterSlaveSeparation = isDisableMasterSlaveSeparation;
After(sql, result);
AutoEnd(oldIsAuto);
if (isIdEntityEnable())
{
return this.InsertBuilder.Parameters.FirstOrDefault(it => it.ParameterName == ":newId01")?.Value?.ObjToInt() ?? 0;
}
return result;
}
@ -82,6 +134,18 @@ namespace SqlSugar
InsertBuilder.IsReturnIdentity = true;
PreToSql();
string sql = InsertBuilder.ToSqlString();
if (isIdEntityEnable())
{
if (sql?.StartsWith("INSERT ALL") == true)
{
return await this.UseParameter().ExecuteCommandAsync();
}
else
{
sql = sql + " RETURNING ID INTO :newId01 ";
}
InsertBuilder.Parameters.Add(new SugarParameter(":newId01", Convert.ToInt64(0), true));
}
RestoreMapping();
var isDisableMasterSlaveSeparation = this.Context.Ado.IsDisableMasterSlaveSeparation;
this.Context.Ado.IsDisableMasterSlaveSeparation = true;
@ -90,6 +154,10 @@ namespace SqlSugar
this.Context.Ado.IsDisableMasterSlaveSeparation = isDisableMasterSlaveSeparation;
After(sql, result);
AutoEnd(oldIsAuto);
if (isIdEntityEnable())
{
return this.InsertBuilder.Parameters.FirstOrDefault(it => it.ParameterName == ":newId01")?.Value?.ObjToLong() ?? 0;
}
return result;
}

5
Src/Asp.Net/SqlSugar/Realization/Oracle/SqlBuilder/OracleInsertBuilder.cs

@ -33,11 +33,16 @@ namespace SqlSugar
{
DbColumnInfoList = DbColumnInfoList.Where(it => it.Value != null).ToList();
}
if (this.Context.CurrentConnectionConfig?.MoreSettings?.EnableOracleIdentity == true)
{
this.DbColumnInfoList = this.DbColumnInfoList.Where(it => it.IsIdentity == false).ToList();
}
var groupList = DbColumnInfoList.GroupBy(it => it.TableId).ToList();
var isSingle = groupList.Count() == 1;
string columnsString = string.Join(",", groupList.First().Select(it => Builder.GetTranslationColumnName(it.DbColumnName)));
if (isSingle && this.EntityInfo.EntityName != "Dictionary`2")
{
string columnParametersString = string.Join(",", this.DbColumnInfoList.Select(it => base.GetDbColumn(it, Builder.SqlParameterKeyWord + it.DbColumnName)));
if (identities.HasValue())
{

2
Src/Asp.Net/SqlSugar/SqlSugar.nuspec

@ -2,7 +2,7 @@
<package >
<metadata>
<id>SqlSugar</id>
<version>5.1.4.84</version>
<version>5.1.4.85-preview07</version>
<title>.Net Framework 安装此版本, 5.0.3.3-max 最低要求 .Net Framework 4.6 | 5.0.0.2-5.0.3.2 最低要求 .Net Framework 4.5 | 4.0-4.9.11 最低要求 .Net Framework 4.0+ .NET ORM </title>
<authors>sun kaixuan</authors>
<owners>landa</owners>

3
Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs

@ -350,7 +350,8 @@ namespace SqlSugar
IsAutoToUpper=it.MoreSettings.IsAutoToUpper,
IsAutoDeleteQueryFilter=it.MoreSettings.IsAutoDeleteQueryFilter,
IsAutoUpdateQueryFilter = it.MoreSettings.IsAutoUpdateQueryFilter,
EnableModelFuncMappingColumn=it.MoreSettings.EnableModelFuncMappingColumn
EnableModelFuncMappingColumn=it.MoreSettings.EnableModelFuncMappingColumn,
EnableOracleIdentity = it.MoreSettings.EnableOracleIdentity
},
SqlMiddle = it.SqlMiddle == null ? null : new SqlMiddle

Loading…
Cancel
Save