/// <summary> /// 确定指定的 Object 是否等于当前的 Object。 /// </summary> /// <param name="obj"></param> /// <returns></returns> public override bool Equals(object obj) { if (obj == null) { return(false); } XTable table = obj as XTable; if (table == null) { return(false); } if (this.Name != table.Name) { return(false); } if (this.Readme != table.Readme) { return(false); } if (this.IsView != table.IsView) { return(false); } //比较字段 List <XField> list1 = new List <XField>(Fields); List <XField> list2 = new List <XField>(table.Fields); foreach (XField item in list1) { XField match = null; //在第二个列表里面找该字段 foreach (XField elm in list2) { if (item == elm) { match = elm; break; } } //如果找不到,表明第二个列表没有该字段 if (match == null) { return(false); } list2.Remove(match); } //如果第二个列表还不为空,表明字段数不对应 if (list2.Count > 0) { return(false); } return(true); }
/// <summary> /// 确定指定的 Object 是否等于当前的 Object。 /// </summary> /// <param name="obj"></param> /// <returns></returns> public override bool Equals(object obj) { if (obj == null) { return(false); } XField field = obj as XField; if (field == null) { return(false); } if (this.Name != field.Name) { return(false); } if (this.FieldType != field.FieldType) { return(false); } if (this.Identity != field.Identity) { return(false); } if (this.PrimaryKey != field.PrimaryKey) { return(false); } if (this.Length != field.Length) { return(false); } if (this.NumOfByte != field.NumOfByte) { return(false); } if (this.Digit != field.Digit) { return(false); } if (this.Nullable != field.Nullable) { return(false); } if (this.Default != field.Default) { return(false); } if (this.Readme != field.Readme) { return(false); } return(true); }
//private DataTable allfields; /// <summary> /// 取得指定表的所有列构架 /// </summary> /// <param name="xt"></param> /// <returns></returns> protected override XField[] GetFields(XTable xt) { //if (allfields == null) allfields = Query(SchemaSql).Tables[0]; DataTable allfields = Query(String.Format(SchemaSql, xt.Name)).Tables[0]; if (allfields == null) { return(base.GetFields(xt)); } List <XField> list = new List <XField>(); //DataRow[] drs = allfields.Select("表名='" + xt.Name + "'", "字段序号"); //if (drs == null || drs.Length < 1) return base.GetFields(xt); if (allfields.Rows == null || allfields.Rows.Count < 1) { return(base.GetFields(xt)); } List <String> pks = GetPrimaryKeys(xt); List <Dictionary <String, String> > fks = GetForeignKeys(xt); foreach (DataRow dr in allfields.Rows) { XField xf = new XField(); xf.ID = Int32.Parse(dr["字段序号"].ToString()); xf.Name = dr["字段名"].ToString(); xf.FieldType = FieldTypeToClassType(dr["类型"].ToString()); xf.Identity = Boolean.Parse(dr["标识"].ToString()); //xf.PrimaryKey = pks != null && pks.Contains(xf.Name); xf.PrimaryKey = Boolean.Parse(dr["主键"].ToString()); xf.ForeignKey = false; xf.ForeignTableName = ""; xf.ForeignTablePrimaryName = ""; if (fks != null) { foreach (Dictionary <String, String> dic in fks) { if (dic["FK_COLUMN_NAME"] == xf.Name) { xf.ForeignKey = true; xf.ForeignTableName = dic["PK_TABLE_NAME"]; xf.ForeignTablePrimaryName = dic["PK_COLUMN_NAME"]; break; } } } xf.Length = Int32.Parse(dr["长度"].ToString()); xf.NumOfByte = Int32.Parse(dr["占用字节数"].ToString()); xf.Digit = Int32.Parse(dr["小数位数"].ToString()); xf.Nullable = Boolean.Parse(dr["允许空"].ToString()); xf.Default = dr["默认值"].ToString(); xf.Readme = dr["字段说明"].ToString(); list.Add(xf); } return(list.ToArray()); }
/// <summary> /// 取得指定表的所有列构架 /// </summary> /// <param name="xt"></param> /// <returns></returns> protected virtual XField[] GetFields(XTable xt) { DataTable dt = GetSchema("Columns", new String[] { null, null, xt.Name }); List <XField> list = new List <XField>(); DataRow[] drs = dt.Select("", "ORDINAL_POSITION"); List <String> pks = GetPrimaryKeys(xt); List <Dictionary <String, String> > fks = GetForeignKeys(xt); foreach (DataRow dr in drs) { XField xf = new XField(); xf.ID = Int32.Parse(dr["ORDINAL_POSITION"].ToString()); xf.Name = dr["COLUMN_NAME"].ToString(); xf.FieldType = FieldTypeToClassType(dr["DATA_TYPE"].ToString()); xf.Identity = dr["DATA_TYPE"].ToString() == "3" && (dr["COLUMN_FLAGS"].ToString() == "16" || dr["COLUMN_FLAGS"].ToString() == "90"); xf.PrimaryKey = pks != null && pks.Contains(xf.Name); xf.ForeignKey = false; xf.ForeignTableName = ""; xf.ForeignTablePrimaryName = ""; if (fks != null) { foreach (Dictionary <String, String> dic in fks) { if (dic["FK_COLUMN_NAME"] == xf.Name) { xf.ForeignKey = true; xf.ForeignTableName = dic["PK_TABLE_NAME"]; xf.ForeignTablePrimaryName = dic["PK_COLUMN_NAME"]; break; } } } if (xf.FieldType == "Int32" || xf.FieldType == "Double") { xf.Length = dr["NUMERIC_PRECISION"] == DBNull.Value ? 0 : Int32.Parse(dr["NUMERIC_PRECISION"].ToString()); xf.NumOfByte = 0; xf.Digit = dr["NUMERIC_SCALE"] == DBNull.Value ? 0 : Int32.Parse(dr["NUMERIC_SCALE"].ToString()); } else if (xf.FieldType == "DateTime") { xf.Length = dr["DATETIME_PRECISION"] == DBNull.Value ? 0 : Int32.Parse(dr["DATETIME_PRECISION"].ToString()); xf.NumOfByte = 0; xf.Digit = 0; } else { if (dr["DATA_TYPE"].ToString() == "130" && dr["COLUMN_FLAGS"].ToString() == "234") //备注类型 { xf.Length = Int32.MaxValue; xf.NumOfByte = Int32.MaxValue; } else { xf.Length = dr["CHARACTER_MAXIMUM_LENGTH"] == DBNull.Value ? 0 : Int32.Parse(dr["CHARACTER_MAXIMUM_LENGTH"].ToString()); xf.NumOfByte = dr["CHARACTER_OCTET_LENGTH"] == DBNull.Value ? 0 : Int32.Parse(dr["CHARACTER_OCTET_LENGTH"].ToString()); } xf.Digit = 0; } try { xf.Nullable = Boolean.Parse(dr["IS_NULLABLE"].ToString()); } catch { xf.Nullable = dr["IS_NULLABLE"].ToString() == "YES"; } try { xf.Default = dr["COLUMN_HASDEFAULT"].ToString() == "False" ? "" : dr["COLUMN_DEFAULT"].ToString(); } catch { xf.Default = dr["COLUMN_DEFAULT"].ToString(); } try { xf.Readme = dr["DESCRIPTION"] == DBNull.Value ? "" : dr["DESCRIPTION"].ToString(); } catch { xf.Readme = ""; } list.Add(xf); } return(list.ToArray()); }