Oracle 12C+ Identity

This commit is contained in:
sunkaixuan
2023-06-20 15:58:08 +08:00
parent 858b0dd423
commit 83a9a8c260
9 changed files with 92 additions and 3 deletions

View File

@@ -619,6 +619,10 @@ namespace SqlSugar
{ {
return false; 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) if (properyTypeName?.ToLower() == "int" && dataType?.ToLower() == "decimal"&&dc.Length==22&&dc.Scale==0&&this.Context.CurrentConnectionConfig.DbType==DbType.Oracle)
{ {
return false; return false;

View File

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

View File

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

View File

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

View File

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

View File

@@ -28,6 +28,18 @@ namespace SqlSugar
InsertBuilder.IsReturnIdentity = true; InsertBuilder.IsReturnIdentity = true;
PreToSql(); PreToSql();
string sql = InsertBuilder.ToSqlString(); 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(); RestoreMapping();
var isDisableMasterSlaveSeparation = this.Context.Ado.IsDisableMasterSlaveSeparation; var isDisableMasterSlaveSeparation = this.Context.Ado.IsDisableMasterSlaveSeparation;
this.Context.Ado.IsDisableMasterSlaveSeparation = true; this.Context.Ado.IsDisableMasterSlaveSeparation = true;
@@ -36,8 +48,16 @@ namespace SqlSugar
this.Context.Ado.IsDisableMasterSlaveSeparation = isDisableMasterSlaveSeparation; this.Context.Ado.IsDisableMasterSlaveSeparation = isDisableMasterSlaveSeparation;
After(sql,result); After(sql,result);
AutoEnd(oldIsAuto); AutoEnd(oldIsAuto);
if (isIdEntityEnable())
{
return this.InsertBuilder.Parameters.FirstOrDefault(it => it.ParameterName == ":newId01")?.Value?.ObjToInt()??0;
}
return result; return result;
} }
private bool isIdEntityEnable()
{
return this.Context.CurrentConnectionConfig?.MoreSettings?.EnableOracleIdentity == true;
}
public override long ExecuteReturnBigIdentity() public override long ExecuteReturnBigIdentity()
{ {
@@ -46,6 +66,18 @@ namespace SqlSugar
InsertBuilder.IsReturnIdentity = true; InsertBuilder.IsReturnIdentity = true;
PreToSql(); PreToSql();
string sql = InsertBuilder.ToSqlString(); 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(); RestoreMapping();
var isDisableMasterSlaveSeparation = this.Context.Ado.IsDisableMasterSlaveSeparation; var isDisableMasterSlaveSeparation = this.Context.Ado.IsDisableMasterSlaveSeparation;
this.Context.Ado.IsDisableMasterSlaveSeparation = true; this.Context.Ado.IsDisableMasterSlaveSeparation = true;
@@ -54,6 +86,10 @@ namespace SqlSugar
this.Context.Ado.IsDisableMasterSlaveSeparation = isDisableMasterSlaveSeparation; this.Context.Ado.IsDisableMasterSlaveSeparation = isDisableMasterSlaveSeparation;
After(sql, result); After(sql, result);
AutoEnd(oldIsAuto); AutoEnd(oldIsAuto);
if (isIdEntityEnable())
{
return this.InsertBuilder.Parameters.FirstOrDefault(it => it.ParameterName == ":newId01")?.Value?.ObjToLong() ?? 0;
}
return result; return result;
} }
@@ -64,6 +100,18 @@ namespace SqlSugar
InsertBuilder.IsReturnIdentity = true; InsertBuilder.IsReturnIdentity = true;
PreToSql(); PreToSql();
string sql = InsertBuilder.ToSqlString(); 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(); RestoreMapping();
var isDisableMasterSlaveSeparation = this.Context.Ado.IsDisableMasterSlaveSeparation; var isDisableMasterSlaveSeparation = this.Context.Ado.IsDisableMasterSlaveSeparation;
this.Context.Ado.IsDisableMasterSlaveSeparation = true; this.Context.Ado.IsDisableMasterSlaveSeparation = true;
@@ -72,6 +120,10 @@ namespace SqlSugar
this.Context.Ado.IsDisableMasterSlaveSeparation = isDisableMasterSlaveSeparation; this.Context.Ado.IsDisableMasterSlaveSeparation = isDisableMasterSlaveSeparation;
After(sql, result); After(sql, result);
AutoEnd(oldIsAuto); AutoEnd(oldIsAuto);
if (isIdEntityEnable())
{
return this.InsertBuilder.Parameters.FirstOrDefault(it => it.ParameterName == ":newId01")?.Value?.ObjToInt() ?? 0;
}
return result; return result;
} }
@@ -82,6 +134,18 @@ namespace SqlSugar
InsertBuilder.IsReturnIdentity = true; InsertBuilder.IsReturnIdentity = true;
PreToSql(); PreToSql();
string sql = InsertBuilder.ToSqlString(); 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(); RestoreMapping();
var isDisableMasterSlaveSeparation = this.Context.Ado.IsDisableMasterSlaveSeparation; var isDisableMasterSlaveSeparation = this.Context.Ado.IsDisableMasterSlaveSeparation;
this.Context.Ado.IsDisableMasterSlaveSeparation = true; this.Context.Ado.IsDisableMasterSlaveSeparation = true;
@@ -90,6 +154,10 @@ namespace SqlSugar
this.Context.Ado.IsDisableMasterSlaveSeparation = isDisableMasterSlaveSeparation; this.Context.Ado.IsDisableMasterSlaveSeparation = isDisableMasterSlaveSeparation;
After(sql, result); After(sql, result);
AutoEnd(oldIsAuto); AutoEnd(oldIsAuto);
if (isIdEntityEnable())
{
return this.InsertBuilder.Parameters.FirstOrDefault(it => it.ParameterName == ":newId01")?.Value?.ObjToLong() ?? 0;
}
return result; return result;
} }

View File

@@ -33,11 +33,16 @@ namespace SqlSugar
{ {
DbColumnInfoList = DbColumnInfoList.Where(it => it.Value != null).ToList(); 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 groupList = DbColumnInfoList.GroupBy(it => it.TableId).ToList();
var isSingle = groupList.Count() == 1; var isSingle = groupList.Count() == 1;
string columnsString = string.Join(",", groupList.First().Select(it => Builder.GetTranslationColumnName(it.DbColumnName))); string columnsString = string.Join(",", groupList.First().Select(it => Builder.GetTranslationColumnName(it.DbColumnName)));
if (isSingle && this.EntityInfo.EntityName != "Dictionary`2") if (isSingle && this.EntityInfo.EntityName != "Dictionary`2")
{ {
string columnParametersString = string.Join(",", this.DbColumnInfoList.Select(it => base.GetDbColumn(it, Builder.SqlParameterKeyWord + it.DbColumnName))); string columnParametersString = string.Join(",", this.DbColumnInfoList.Select(it => base.GetDbColumn(it, Builder.SqlParameterKeyWord + it.DbColumnName)));
if (identities.HasValue()) if (identities.HasValue())
{ {

View File

@@ -2,7 +2,7 @@
<package > <package >
<metadata> <metadata>
<id>SqlSugar</id> <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> <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> <authors>sun kaixuan</authors>
<owners>landa</owners> <owners>landa</owners>

View File

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