Ejemplo n.º 1
0
       public List<ConstraintInfo> Copyfrom(EntityInfo info)
       {
           cons.Clear();
           ConstraintInfo con = null;
           for (int i = 0; i < info.constraints.Count; i++)
           {
               con = new ConstraintInfo();
               con = info.constraints[i];
               cons.Add(con);
           }

           //foreach (ConstraintInfo co in info.constraints)
           //{
           //    cons.Add(co.Copy());
           //}

           return cons;
       }
Ejemplo n.º 2
0
 public ConstraintInfo Copy()
 {
     ConstraintInfo cos = new ConstraintInfo();
     cos.Constraint_catalog = Constraint_catalog;
     cos.Constraint_schema = Constraint_schema;
     cos.Constraint_name = Constraint_name;
     cos.Table_Catalog = Table_Catalog;
     cos.Table_Schema = Table_Schema;
     cos.Table_Name = Table_Name;
     cos.Column_Name = Column_Name;
     cos.ORDINAL_POSITION = ORDINAL_POSITION;
     cos.POSITION_IN_UNIQUE_CONSTRAINT = POSITION_IN_UNIQUE_CONSTRAINT;
     cos.REFERENCED_TABLE_SCHEMA = REFERENCED_TABLE_SCHEMA;
     cos.REFERENCED_TABLE_NAME = REFERENCED_TABLE_NAME;
     cos.REFERENCED_COLUMN_NAME = REFERENCED_COLUMN_NAME;
     cos.Using = this.Using;
     cos.Notes = this.Notes;
     return cos;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 添加一个新的外键.
        /// </summary>
        /// <param name="entity1"></param>
        /// <param name="att1"></param>
        /// <param name="entity2"></param>
        /// <param name="att2"></param>
        /// <returns></returns>
        public ConstraintInfo AddConstraint(string Fori_NAME,  EntityInfo entity1, AttributeInfo att1, EntityInfo entity2, AttributeInfo att2)
        {
            ConstraintInfo constraint = new ConstraintInfo();
            if (Fori_NAME== "")
            {
                constraint.Constraint_name = "FK_" + entity1.ClassName + "_" + att1.ColumnName + "_" + entity2.ClassName + "_" + att2.ColumnName;

            }
            constraint.Table_Name = entity1.ClassName;
            constraint.Column_Name = att1.ColumnName;
            constraint.ORDINAL_POSITION = entity1.Attributes.IndexOf(att1).ToString();

            constraint.POSITION_IN_UNIQUE_CONSTRAINT = entity2.Attributes.IndexOf(att2).ToString();
            constraint.REFERENCED_TABLE_NAME = entity2.ClassName;
            constraint.REFERENCED_COLUMN_NAME = att2.ColumnName;

            entity1.constraints.Add(constraint);
            return constraint;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 返回外键,主键不在这里返回.
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="dbtype"></param>
        /// <param name="table_schema"></param>
        /// <returns></returns>
        public List<ConstraintInfo> GetConstaint(string tableName, DBTYPE dbtype, string table_schema)
        {
            List<ConstraintInfo> constrains = new List<ConstraintInfo>();
            switch (dbtype)
            {
                case DBTYPE.UNKNOW:
                    break;
                case DBTYPE.SQLSERVER:
                    return null;
                    
                case DBTYPE.MYSQL_MARIADB:
                    using (MySqlConnection conn = new MySqlConnection(formConf.connectionString))
                    {
                        conn.Open();
                        string cmdText = "select * from INFORMATION_SCHEMA.KEY_COLUMN_USAGE  where TABLE_NAME='" + tableName + "' and CONSTRAINT_NAME !='PRIMARY'";
                        MySqlCommand cmd = new MySqlCommand(cmdText, conn);

                        using (MySqlDataReader dr = cmd.ExecuteReader())
                        {
                            while (dr.Read())
                            {
                                ConstraintInfo constraint = new ConstraintInfo();

                                constraint.Constraint_catalog = dr["CONSTRAINT_CATALOG"].ToString();
                                constraint.Constraint_schema = dr["CONSTRAINT_SCHEMA"].ToString();
                                constraint.Constraint_name = dr["CONSTRAINT_NAME"].ToString();
                                constraint.Table_Catalog = dr["TABLE_CATALOG"].ToString();
                                constraint.Table_Schema = dr["TABLE_SCHEMA"].ToString();
                                constraint.Table_Name = dr["TABLE_NAME"].ToString();
                                constraint.Column_Name = dr["COLUMN_NAME"].ToString();
                                constraint.ORDINAL_POSITION = dr["ORDINAL_POSITION"].ToString();
                                constraint.POSITION_IN_UNIQUE_CONSTRAINT = dr["POSITION_IN_UNIQUE_CONSTRAINT"].ToString();
                                constraint.REFERENCED_TABLE_SCHEMA = dr["REFERENCED_TABLE_SCHEMA"].ToString();
                                constraint.REFERENCED_TABLE_NAME = dr["REFERENCED_TABLE_NAME"].ToString();
                                constraint.REFERENCED_COLUMN_NAME = dr["REFERENCED_COLUMN_NAME"].ToString();

                                constrains.Add(constraint);
                            }
                        }
                        return constrains;
                    }
                case DBTYPE.ORACLE:
                    break;
                default:
                    break;
            }
            return constrains;
        }