SqlServer and MySql
This commit is contained in:
1 parent
42405492b6
commit
011e60afa9
53 files changed
+3419
-1238
No files matched your search
@@ -14,76 +14,77 @@ namespace CloudBuilder.Security.Entity
|
||||
{
|
||||
}
|
||||
|
||||
[Column("colid")]
|
||||
public long Colid { get; set; }
|
||||
[Column("field_default_value")]
|
||||
public string FieldDefaultValue { get; set; }
|
||||
[Column("table_name")]
|
||||
public string TableName { get; set; }
|
||||
[Column("field_name")]
|
||||
public string? FieldName { get; set; }
|
||||
[Column("find_by")]
|
||||
public int FindBy { get; set; }
|
||||
[Column("is_identity")]
|
||||
public long IsIdentity { get; set; }
|
||||
[Column("is_null_able")]
|
||||
public string IsNullAble { get; set; }
|
||||
[Column("type_name")]
|
||||
public string? TypeName { get; set; }
|
||||
[Column("type_of_name")]
|
||||
public string? TypeOfName { get; set; }
|
||||
[Column("max_length")]
|
||||
public long MaxLength { get; set; }
|
||||
[Column("scale",TypeName = "decimal(20,0)")]
|
||||
public decimal Scale { get; set; }
|
||||
[Column("is_null_able")]
|
||||
public string IsNullAble { get; set; }
|
||||
[Column("field_default_value")]
|
||||
public string FieldDefaultValue { get; set; }
|
||||
[Column("xtype")]
|
||||
public string? Xtype { get; set; }
|
||||
[Column("find_by")]
|
||||
public int FindBy { get; set; }
|
||||
[Column("operation")]
|
||||
public int Operation { get; set; }
|
||||
[Column("pk")]
|
||||
public long Pk { get; set; }
|
||||
[Column("pk_name")]
|
||||
public string PkName { get; set; }
|
||||
[Column("scale",TypeName = "decimal(20,0)")]
|
||||
public decimal Scale { get; set; }
|
||||
[Column("table_name")]
|
||||
public string TableName { get; set; }
|
||||
[Column("type_name")]
|
||||
public string? TypeName { get; set; }
|
||||
[Column("type_of_name")]
|
||||
public string? TypeOfName { get; set; }
|
||||
[Column("xtype")]
|
||||
public string? Xtype { get; set; }
|
||||
[Column("is_identity")]
|
||||
public long IsIdentity { get; set; }
|
||||
[Column("colid")]
|
||||
public long Colid { get; set; }
|
||||
|
||||
public const string COLID = "Colid";
|
||||
public const string FIELD_DEFAULT_VALUE = "FieldDefaultValue";
|
||||
public const string TABLE_NAME = "TableName";
|
||||
public const string FIELD_NAME = "FieldName";
|
||||
public const string FIND_BY = "FindBy";
|
||||
public const string IS_IDENTITY = "IsIdentity";
|
||||
public const string IS_NULL_ABLE = "IsNullAble";
|
||||
public const string TYPE_NAME = "TypeName";
|
||||
public const string TYPE_OF_NAME = "TypeOfName";
|
||||
public const string MAX_LENGTH = "MaxLength";
|
||||
public const string SCALE = "Scale";
|
||||
public const string IS_NULL_ABLE = "IsNullAble";
|
||||
public const string FIELD_DEFAULT_VALUE = "FieldDefaultValue";
|
||||
public const string XTYPE = "Xtype";
|
||||
public const string FIND_BY = "FindBy";
|
||||
public const string OPERATION = "Operation";
|
||||
public const string PK = "Pk";
|
||||
public const string PK_NAME = "PkName";
|
||||
public const string SCALE = "Scale";
|
||||
public const string TABLE_NAME = "TableName";
|
||||
public const string TYPE_NAME = "TypeName";
|
||||
public const string TYPE_OF_NAME = "TypeOfName";
|
||||
public const string XTYPE = "Xtype";
|
||||
public const string IS_IDENTITY = "IsIdentity";
|
||||
public const string COLID = "Colid";
|
||||
|
||||
public const string DB_NAME_SYS_TABLE_SCHEMA_VIEW = "sys_table_schema_view";
|
||||
public const string DB_NAME_FIELDS="colid,field_default_value,field_name,find_by,is_identity,is_null_able,max_length,operation,pk,pk_name,scale,table_name,type_name,type_of_name,xtype";
|
||||
public const string DB_NAME_FIELDS="table_name,field_name,type_name,type_of_name,max_length,scale,is_null_able,field_default_value,xtype,find_by,operation,pk,pk_name,is_identity,colid";
|
||||
|
||||
public const string DB_COLID = "colid";
|
||||
public const string DB_FIELD_DEFAULT_VALUE = "field_default_value";
|
||||
public const string DB_TABLE_NAME = "table_name";
|
||||
public const string DB_FIELD_NAME = "field_name";
|
||||
public const string DB_FIND_BY = "find_by";
|
||||
public const string DB_IS_IDENTITY = "is_identity";
|
||||
public const string DB_IS_NULL_ABLE = "is_null_able";
|
||||
public const string DB_TYPE_NAME = "type_name";
|
||||
public const string DB_TYPE_OF_NAME = "type_of_name";
|
||||
public const string DB_MAX_LENGTH = "max_length";
|
||||
public const string DB_SCALE = "scale";
|
||||
public const string DB_IS_NULL_ABLE = "is_null_able";
|
||||
public const string DB_FIELD_DEFAULT_VALUE = "field_default_value";
|
||||
public const string DB_XTYPE = "xtype";
|
||||
public const string DB_FIND_BY = "find_by";
|
||||
public const string DB_OPERATION = "operation";
|
||||
public const string DB_PK = "pk";
|
||||
public const string DB_PK_NAME = "pk_name";
|
||||
public const string DB_SCALE = "scale";
|
||||
public const string DB_TABLE_NAME = "table_name";
|
||||
public const string DB_TYPE_NAME = "type_name";
|
||||
public const string DB_TYPE_OF_NAME = "type_of_name";
|
||||
public const string DB_XTYPE = "xtype";
|
||||
public const string DB_IS_IDENTITY = "is_identity";
|
||||
public const string DB_COLID = "colid";
|
||||
|
||||
public string ProviderName { get; set; }
|
||||
|
||||
public static SysTableSchemaViewEntity GetInstance()
|
||||
public static SysTableSchemaViewEntity GetInstance(string providerName)
|
||||
{
|
||||
return new SysTableSchemaViewEntity();
|
||||
return new SysTableSchemaViewEntity() { ProviderName = providerName };
|
||||
}
|
||||
|
||||
public virtual void CopyFrom(SysTableSchemaViewEntity source)
|
||||
@@ -98,21 +99,21 @@ namespace CloudBuilder.Security.Entity
|
||||
throw new NullReferenceException("Source entity is null.");
|
||||
}
|
||||
|
||||
this.Colid = source.Colid;
|
||||
this.FieldDefaultValue = source.FieldDefaultValue;
|
||||
this.TableName = source.TableName;
|
||||
this.FieldName = source.FieldName;
|
||||
this.FindBy = source.FindBy;
|
||||
this.IsIdentity = source.IsIdentity;
|
||||
this.IsNullAble = source.IsNullAble;
|
||||
this.TypeName = source.TypeName;
|
||||
this.TypeOfName = source.TypeOfName;
|
||||
this.MaxLength = source.MaxLength;
|
||||
this.Scale = source.Scale;
|
||||
this.IsNullAble = source.IsNullAble;
|
||||
this.FieldDefaultValue = source.FieldDefaultValue;
|
||||
this.Xtype = source.Xtype;
|
||||
this.FindBy = source.FindBy;
|
||||
this.Operation = source.Operation;
|
||||
this.Pk = source.Pk;
|
||||
this.PkName = source.PkName;
|
||||
this.Scale = source.Scale;
|
||||
this.TableName = source.TableName;
|
||||
this.TypeName = source.TypeName;
|
||||
this.TypeOfName = source.TypeOfName;
|
||||
this.Xtype = source.Xtype;
|
||||
this.IsIdentity = source.IsIdentity;
|
||||
this.Colid = source.Colid;
|
||||
|
||||
if (includeSystemFields)
|
||||
{
|
||||
@@ -120,23 +121,86 @@ namespace CloudBuilder.Security.Entity
|
||||
}
|
||||
|
||||
public override string GetSelectFrom()
|
||||
{
|
||||
if (ProviderName.Contains("MySql"))
|
||||
{
|
||||
return GetSelectFromByMySql();
|
||||
}
|
||||
else if (ProviderName.Contains("SqlServer"))
|
||||
{
|
||||
return GetSelectFromByBySqlServer();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotSupportedException($"不支持的数据库提供程序:{ProviderName}");
|
||||
}
|
||||
}
|
||||
public string GetSelectFromByMySql()
|
||||
{
|
||||
return $" select {DB_NAME_FIELDS} from { DB_NAME_SYS_TABLE_SCHEMA_VIEW} with(nolock) ";
|
||||
}
|
||||
public string GetSelectFromByBySqlServer()
|
||||
{
|
||||
return $" select {DB_NAME_FIELDS} from { DB_NAME_SYS_TABLE_SCHEMA_VIEW} ";
|
||||
}
|
||||
|
||||
|
||||
public override string GetSelectCountFrom(string sqlWhere)
|
||||
{
|
||||
if (ProviderName.Contains("MySql"))
|
||||
{
|
||||
return GetSelectCountFromByMySql(sqlWhere);
|
||||
}
|
||||
else if (ProviderName.Contains("SqlServer"))
|
||||
{
|
||||
return GetSelectCountFromBySqlServer(sqlWhere);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotSupportedException($"不支持的数据库提供程序:{ProviderName}");
|
||||
}
|
||||
}
|
||||
|
||||
public string GetSelectCountFromByMySql(string sqlWhere)
|
||||
{
|
||||
return $" select count(*) from { DB_NAME_SYS_TABLE_SCHEMA_VIEW} where 1=1 {sqlWhere}";
|
||||
}
|
||||
|
||||
public override string GetSelectTopFrom(int limit, int start,string orderby,string orderbytag, string sqlWhere)
|
||||
public string GetSelectCountFromBySqlServer(string sqlWhere)
|
||||
{
|
||||
return $" select count(*) from { DB_NAME_SYS_TABLE_SCHEMA_VIEW} with(nolock) where 1=1 {sqlWhere}";
|
||||
}
|
||||
|
||||
public override string GetSelectTopFrom(int limit, int start, string orderby, string orderbytag, string sqlWhere)
|
||||
{
|
||||
if (ProviderName.Contains("MySql"))
|
||||
{
|
||||
return GetSelectTopFromByMySql(limit, start, orderby, orderbytag, sqlWhere);
|
||||
}
|
||||
else if (ProviderName.Contains("SqlServer"))
|
||||
{
|
||||
return GetSelectTopFromBySqlServer(limit, start, orderby, orderbytag, sqlWhere);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotSupportedException($"不支持的数据库提供程序:{ProviderName}");
|
||||
}
|
||||
}
|
||||
|
||||
public string GetSelectTopFromByMySql(int limit, int start,string orderby,string orderbytag, string sqlWhere)
|
||||
{
|
||||
if (string.IsNullOrEmpty(orderbytag) || orderbytag.Trim() != "desc") orderbytag = "asc";
|
||||
|
||||
if (string.IsNullOrEmpty(orderby) || !DB_NAME_FIELDS.Contains(orderby)) orderby = DB_COLID ; int offset = limit * (start - 1);
|
||||
if (string.IsNullOrEmpty(orderby) || !DB_NAME_FIELDS.Contains(orderby)) orderby = DB_TABLE_NAME ; int offset = limit * (start - 1);
|
||||
return $" select {DB_NAME_FIELDS} from (select {DB_NAME_FIELDS} ,row_number() over(order by {orderby} {orderbytag}) as num from { DB_NAME_SYS_TABLE_SCHEMA_VIEW} where 1=1 {sqlWhere} ) a where num> {offset} LIMIT {offset},{limit} ";
|
||||
}
|
||||
|
||||
public string GetSelectTopFromBySqlServer(int limit, int start,string orderby,string orderbytag, string sqlWhere)
|
||||
{
|
||||
if (string.IsNullOrEmpty(orderbytag) || orderbytag.Trim() != "desc") orderbytag = "asc";
|
||||
|
||||
if (string.IsNullOrEmpty(orderby) || !DB_NAME_FIELDS.Contains(orderby)) orderby = DB_TABLE_NAME ; string top = limit > 0 ? $"top {limit}" : "";
|
||||
return $" select {top} {DB_NAME_FIELDS} from (select {DB_NAME_FIELDS} ,row_number() over(order by {orderby} {orderbytag}) as num from { DB_NAME_SYS_TABLE_SCHEMA_VIEW} with(nolock) where 1=1 {sqlWhere} ) a where num> {limit * (start - 1)}";
|
||||
}
|
||||
|
||||
public SysTableSchemaViewEntity Clone()
|
||||
{
|
||||
SysTableSchemaViewEntity result = new SysTableSchemaViewEntity();
|
||||
|
||||
Reference in new issue
Block a user