Browse Source

Add Ccheck , Dbfirst and Codefirst requires system table permissions

pull/12/MERGE
sunkaixuan 8 years ago
parent
commit
1ea307d5f2
  1. 4
      SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs
  2. 3
      SqlSugar/Abstract/DbFirstProvider/DbFirstProvider.cs
  3. 13
      SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs
  4. 4
      SqlSugar/Abstract/DbMaintenanceProvider/Properties.cs
  5. 1
      SqlSugar/Interface/IDbMaintenance.cs
  6. 16
      SqlSugar/Realization/SqlServer/DbMaintenance/SqlServerDbMaintenance.cs

4
SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs

@ -22,6 +22,10 @@ namespace SqlSugar
}
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 ");
var executeResult = Context.Ado.UseTran(() =>
{

3
SqlSugar/Abstract/DbFirstProvider/DbFirstProvider.cs

@ -39,6 +39,9 @@ namespace SqlSugar
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());
var viewList = this.Context.RewritableMethods.TranslateCopy(this.Context.DbMaintenance.GetViewInfoList());
if (viewList.IsValuable())

13
SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs

@ -99,6 +99,19 @@ namespace SqlSugar
{
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
#region DDL

4
SqlSugar/Abstract/DbMaintenanceProvider/Properties.cs

@ -32,6 +32,10 @@ namespace SqlSugar
protected abstract string RenameColumnSql { get; }
#endregion
#region Check
protected abstract string CheckSystemTablePermissionsSql { get; }
#endregion
#region Scattered
protected abstract string CreateTableNull { get; }
protected abstract string CreateTableNotNull { get; }

1
SqlSugar/Interface/IDbMaintenance.cs

@ -22,6 +22,7 @@ namespace SqlSugar
bool IsPrimaryKey(string tableName, string column);
bool IsIdentity(string tableName, string column);
bool IsAnyConstraint(string ConstraintName);
bool IsAnySystemTablePermissions();
#endregion
#region DDL

16
SqlSugar/Realization/SqlServer/DbMaintenance/SqlServerDbMaintenance.cs

@ -152,13 +152,25 @@ namespace SqlSugar
return "ALTER TABLE {0} DROP CONSTRAINT {1}";
}
}
protected override string RenameColumnSql {
get {
protected override string RenameColumnSql
{
get
{
return "exec sp_rename '{0}.{1}','{2}','column';";
}
}
#endregion
#region Check
protected override string CheckSystemTablePermissionsSql
{
get
{
return "select top 1 id from sysobjects";
}
}
#endregion
#region Scattered
protected override string CreateTableNull
{

Loading…
Cancel
Save