mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-12-29 09:54:44 +08:00
-
This commit is contained in:
@@ -8,34 +8,47 @@ namespace SqlSugar
|
||||
public abstract partial class DbMaintenanceProvider : IDbMaintenance
|
||||
{
|
||||
#region DML
|
||||
public virtual List<DbTableInfo> GetViewInfoList()
|
||||
public virtual List<DbTableInfo> GetViewInfoList(bool isCache = true)
|
||||
{
|
||||
string cacheKey = "DbMaintenanceProvider.GetViewInfoList";
|
||||
cacheKey = GetCacheKey(cacheKey);
|
||||
var result = GetListOrCache<DbTableInfo>(cacheKey, this.GetViewInfoListSql);
|
||||
var result = new List<DbTableInfo>();
|
||||
if (isCache)
|
||||
result = GetListOrCache<DbTableInfo>(cacheKey, this.GetViewInfoListSql);
|
||||
else
|
||||
result = this.Context.Ado.SqlQuery<DbTableInfo>(this.GetViewInfoListSql);
|
||||
foreach (var item in result)
|
||||
{
|
||||
item.DbObjectType = DbObjectType.View;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public virtual List<DbTableInfo> GetTableInfoList()
|
||||
public virtual List<DbTableInfo> GetTableInfoList(bool isCache = true)
|
||||
{
|
||||
string cacheKey = "DbMaintenanceProvider.GetTableInfoList";
|
||||
cacheKey = GetCacheKey(cacheKey);
|
||||
var result = GetListOrCache<DbTableInfo>(cacheKey, this.GetTableInfoListSql);
|
||||
var result = new List<DbTableInfo>();
|
||||
if (isCache)
|
||||
result = GetListOrCache<DbTableInfo>(cacheKey, this.GetTableInfoListSql);
|
||||
else
|
||||
result = this.Context.Ado.SqlQuery<DbTableInfo>(this.GetTableInfoListSql);
|
||||
foreach (var item in result)
|
||||
{
|
||||
item.DbObjectType = DbObjectType.Table;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public virtual List<DbColumnInfo> GetColumnInfosByTableName(string tableName)
|
||||
public virtual List<DbColumnInfo> GetColumnInfosByTableName(string tableName, bool isCache = true)
|
||||
{
|
||||
if (string.IsNullOrEmpty(tableName)) return new List<DbColumnInfo>();
|
||||
string cacheKey = "DbMaintenanceProvider.GetColumnInfosByTableName." + this.SqlBuilder.GetNoTranslationColumnName(tableName).ToLower();
|
||||
cacheKey = GetCacheKey(cacheKey);
|
||||
return GetListOrCache<DbColumnInfo>(cacheKey, string.Format(this.GetColumnInfosByTableNameSql, tableName));
|
||||
var sql = string.Format(this.GetColumnInfosByTableNameSql, tableName);
|
||||
if (isCache)
|
||||
return GetListOrCache<DbColumnInfo>(cacheKey, sql);
|
||||
else
|
||||
return this.Context.Ado.SqlQuery<DbColumnInfo>(sql);
|
||||
|
||||
}
|
||||
public virtual List<string> GetIsIdentities(string tableName)
|
||||
{
|
||||
@@ -60,10 +73,10 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Check
|
||||
public virtual bool IsAnyTable(string tableName)
|
||||
public virtual bool IsAnyTable(string tableName, bool isCache = true)
|
||||
{
|
||||
tableName = this.SqlBuilder.GetNoTranslationColumnName(tableName);
|
||||
var tables = GetTableInfoList();
|
||||
var tables = GetTableInfoList(isCache);
|
||||
if (tables == null) return false;
|
||||
else return tables.Any(it => it.Name.Equals(tableName, StringComparison.CurrentCultureIgnoreCase));
|
||||
}
|
||||
|
||||
@@ -9,15 +9,15 @@ namespace SqlSugar
|
||||
SqlSugarClient Context { get; set; }
|
||||
|
||||
#region DML
|
||||
List<DbTableInfo> GetViewInfoList();
|
||||
List<DbTableInfo> GetTableInfoList();
|
||||
List<DbColumnInfo> GetColumnInfosByTableName(string tableName);
|
||||
List<DbTableInfo> GetViewInfoList(bool isCache=true);
|
||||
List<DbTableInfo> GetTableInfoList(bool isCache=true);
|
||||
List<DbColumnInfo> GetColumnInfosByTableName(string tableName,bool isCache=true);
|
||||
List<string> GetIsIdentities(string tableName);
|
||||
List<string> GetPrimaries(string tableName);
|
||||
#endregion
|
||||
|
||||
#region Check
|
||||
bool IsAnyTable(string tableName);
|
||||
bool IsAnyTable(string tableName, bool isCache = true);
|
||||
bool IsAnyColumn(string tableName, string column);
|
||||
bool IsPrimaryKey(string tableName, string column);
|
||||
bool IsIdentity(string tableName, string column);
|
||||
|
||||
@@ -172,12 +172,22 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
public override List<DbColumnInfo> GetColumnInfosByTableName(string tableName)
|
||||
public override List<DbColumnInfo> GetColumnInfosByTableName(string tableName,bool isCache=true)
|
||||
{
|
||||
string cacheKey = "DbMaintenanceProvider.GetColumnInfosByTableName." + this.SqlBuilder.GetNoTranslationColumnName(tableName).ToLower();
|
||||
cacheKey = GetCacheKey(cacheKey);
|
||||
if (!isCache)
|
||||
return GetColumnInfosByTableName(tableName);
|
||||
else
|
||||
return this.Context.Utilities.GetReflectionInoCacheInstance().GetOrCreate(cacheKey,
|
||||
() =>
|
||||
{
|
||||
return GetColumnInfosByTableName(tableName);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private List<DbColumnInfo> GetColumnInfosByTableName(string tableName)
|
||||
{
|
||||
string sql = "select * from " + tableName + " WHERE 1=2 ";
|
||||
var oldIsEnableLog = this.Context.Ado.IsEnableLogEvent;
|
||||
@@ -206,9 +216,8 @@ namespace SqlSugar
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private List<string> GetPrimaryKeyByTableNames(string tableName)
|
||||
{
|
||||
string cacheKey = "DbMaintenanceProvider.GetPrimaryKeyByTableNames." + this.SqlBuilder.GetNoTranslationColumnName(tableName).ToLower();
|
||||
|
||||
@@ -164,12 +164,23 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
public override List<DbColumnInfo> GetColumnInfosByTableName(string tableName)
|
||||
public override List<DbColumnInfo> GetColumnInfosByTableName(string tableName, bool isCache = true)
|
||||
{
|
||||
string cacheKey = "DbMaintenanceProvider.GetColumnInfosByTableName." + this.SqlBuilder.GetNoTranslationColumnName(tableName).ToLower();
|
||||
cacheKey = GetCacheKey(cacheKey);
|
||||
if (!isCache)
|
||||
{
|
||||
return GetColumnInfosByTableName(tableName);
|
||||
}
|
||||
return this.Context.Utilities.GetReflectionInoCacheInstance().GetOrCreate(cacheKey,
|
||||
() =>
|
||||
{
|
||||
return GetColumnsByTableName(tableName);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private List<DbColumnInfo> GetColumnsByTableName(string tableName)
|
||||
{
|
||||
string sql = "select * from " + tableName + " limit 0,1";
|
||||
var oldIsEnableLog = this.Context.Ado.IsEnableLogEvent;
|
||||
@@ -197,8 +208,6 @@ namespace SqlSugar
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public override bool CreateTable(string tableName, List<DbColumnInfo> columns, bool isCreatePrimaryKey = true)
|
||||
@@ -219,7 +228,8 @@ namespace SqlSugar
|
||||
}
|
||||
}
|
||||
string sql = GetCreateTableSql(tableName, columns);
|
||||
if (!isCreatePrimaryKey) {
|
||||
if (!isCreatePrimaryKey)
|
||||
{
|
||||
sql = sql.Replace("PRIMARY KEY AUTOINCREMENT", "").Replace("PRIMARY KEY", "");
|
||||
}
|
||||
this.Context.Ado.ExecuteCommand(sql);
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user