mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-23 04:23:47 +08:00
Add Ccheck , Dbfirst and Codefirst requires system table permissions
This commit is contained in:
@@ -22,6 +22,10 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
public void InitTables(Type entityType)
|
public void InitTables(Type entityType)
|
||||||
{
|
{
|
||||||
|
if (!this.Context.DbMaintenance.IsAnySystemTablePermissions())
|
||||||
|
{
|
||||||
|
Check.Exception(true, "Dbfirst and Codefirst requires system table permissions");
|
||||||
|
}
|
||||||
Check.Exception(this.Context.IsSystemTablesConfig, "Please set SqlSugarClent Parameter ConnectionConfig.InitKeyType=InitKeyType.Attribute ");
|
Check.Exception(this.Context.IsSystemTablesConfig, "Please set SqlSugarClent Parameter ConnectionConfig.InitKeyType=InitKeyType.Attribute ");
|
||||||
var executeResult = Context.Ado.UseTran(() =>
|
var executeResult = Context.Ado.UseTran(() =>
|
||||||
{
|
{
|
||||||
|
@@ -39,6 +39,9 @@ namespace SqlSugar
|
|||||||
|
|
||||||
public void Init()
|
public void Init()
|
||||||
{
|
{
|
||||||
|
if (!this.Context.DbMaintenance.IsAnySystemTablePermissions()) {
|
||||||
|
Check.Exception(true, "Dbfirst and Codefirst requires system table permissions");
|
||||||
|
}
|
||||||
this.TableInfoList =this.Context.RewritableMethods.TranslateCopy(this.Context.DbMaintenance.GetTableInfoList());
|
this.TableInfoList =this.Context.RewritableMethods.TranslateCopy(this.Context.DbMaintenance.GetTableInfoList());
|
||||||
var viewList = this.Context.RewritableMethods.TranslateCopy(this.Context.DbMaintenance.GetViewInfoList());
|
var viewList = this.Context.RewritableMethods.TranslateCopy(this.Context.DbMaintenance.GetViewInfoList());
|
||||||
if (viewList.IsValuable())
|
if (viewList.IsValuable())
|
||||||
|
@@ -99,6 +99,19 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
return this.Context.Ado.GetInt("select object_id('" + constraintName + "')") > 0;
|
return this.Context.Ado.GetInt("select object_id('" + constraintName + "')") > 0;
|
||||||
}
|
}
|
||||||
|
public virtual bool IsAnySystemTablePermissions()
|
||||||
|
{
|
||||||
|
string sql = this.CheckSystemTablePermissionsSql;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
this.Context.Ado.ExecuteCommand(sql);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region DDL
|
#region DDL
|
||||||
|
@@ -32,6 +32,10 @@ namespace SqlSugar
|
|||||||
protected abstract string RenameColumnSql { get; }
|
protected abstract string RenameColumnSql { get; }
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Check
|
||||||
|
protected abstract string CheckSystemTablePermissionsSql { get; }
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Scattered
|
#region Scattered
|
||||||
protected abstract string CreateTableNull { get; }
|
protected abstract string CreateTableNull { get; }
|
||||||
protected abstract string CreateTableNotNull { get; }
|
protected abstract string CreateTableNotNull { get; }
|
||||||
|
@@ -22,6 +22,7 @@ namespace SqlSugar
|
|||||||
bool IsPrimaryKey(string tableName, string column);
|
bool IsPrimaryKey(string tableName, string column);
|
||||||
bool IsIdentity(string tableName, string column);
|
bool IsIdentity(string tableName, string column);
|
||||||
bool IsAnyConstraint(string ConstraintName);
|
bool IsAnyConstraint(string ConstraintName);
|
||||||
|
bool IsAnySystemTablePermissions();
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region DDL
|
#region DDL
|
||||||
|
@@ -152,13 +152,25 @@ namespace SqlSugar
|
|||||||
return "ALTER TABLE {0} DROP CONSTRAINT {1}";
|
return "ALTER TABLE {0} DROP CONSTRAINT {1}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
protected override string RenameColumnSql {
|
protected override string RenameColumnSql
|
||||||
get {
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
return "exec sp_rename '{0}.{1}','{2}','column';";
|
return "exec sp_rename '{0}.{1}','{2}','column';";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Check
|
||||||
|
protected override string CheckSystemTablePermissionsSql
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "select top 1 id from sysobjects";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Scattered
|
#region Scattered
|
||||||
protected override string CreateTableNull
|
protected override string CreateTableNull
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user