Example #1
0
 public bool visiteTable(Table table, DatabaseXML db)
 {
     foreach (Column column in table.Columns)
     {
         if (column.accept(this, table, db) == false)
         {
             return(false);
         }
     }
     return(true);
 }
Example #2
0
 public bool visiteDatabaseXML(DatabaseXML db)
 {
     foreach (Table table in db.Content)
     {
         if (table.accept(this, db) == false)
         {
             return(false);
         }
     }
     return(true);
 }
Example #3
0
        public override bool Equals(object obj)
        {
            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }

            DatabaseXML db = (DatabaseXML)obj;

            if (this.Name != db.Name || this.Content != db.Content)
            {
                return(false);
            }

            return(true);
        }
Example #4
0
        public bool visiteColumn(Column column, Table table, DatabaseXML db)
        {
            ForeignKeyHelper fkh = table.getFKHFromColumn(column);

            if (fkh != null)
            {
                Table externTable;
                try
                {
                    externTable = db.getTableByName(fkh.ExternTableName);
                }
                catch (Exception e)
                {
                    errors.Add(e.Message + " of the database " + db.Name);
                    return(false);
                }
                Column externColumn;
                try
                {
                    externColumn = externTable.getColumnByName(fkh.ExternColumnName);
                }
                catch (Exception e)
                {
                    errors.Add(e.Message + " of the database " + db.Name);
                    return(false);
                }
                if (column.Type == externColumn.Type && column.Length == externColumn.Length)
                {
                    return(true);
                }
                else
                {
                    string s = "Un problème de type de champ est apparue dans une clé étrangère entre le champ " + column.Name + " de la table " + table.Name + " et le champ " + externColumn.Name + " de la table " + externTable;
                    errors.Add(s);
                    return(false);
                }
            }
            return(true);
        }
Example #5
0
 public bool accept(ValidationVisitor visitor, Table table, DatabaseXML db)
 {
     return(visitor.visiteColumn(this, table, db));
 }
Example #6
0
File: Table.cs Project: nunch/Crud2
 public bool accept(ValidationVisitor visitor, DatabaseXML db)
 {
     return(visitor.visiteTable(this, db));
 }
Example #7
0
File: Table.cs Project: nunch/Crud2
        public void updateColumn(string previousName, Column newColumn, DatabaseXML db)
        {
            Column c2 = new Column {
                Name   = previousName,
                isNull = newColumn.isNull,
                Length = newColumn.Length,
                Type   = newColumn.Type
            };
            List <Index> tmp1 = new List <Index>();

            foreach (Index index in this.Indexes)
            {
                Index tmp_1 = new Index {
                    Name = index.Name
                };
                foreach (string name in index.List)
                {
                    if (name == previousName)
                    {
                        tmp_1.List.Add(newColumn.Name);
                    }
                    else
                    {
                        tmp_1.List.Add(name);
                    }
                }
                tmp1.Add(tmp_1);
            }
            this.Indexes = tmp1;

            List <UniqueKey> tmp5 = new List <UniqueKey>();

            foreach (UniqueKey uk in this.UniqueKeys)
            {
                UniqueKey tmp_1 = new UniqueKey {
                    Name = uk.Name
                };
                foreach (string name in uk.List)
                {
                    if (name == previousName)
                    {
                        tmp_1.List.Add(newColumn.Name);
                    }
                    else
                    {
                        tmp_1.List.Add(name);
                    }
                }
                tmp5.Add(tmp_1);
            }
            this.UniqueKeys = tmp5;

            List <Column> tmp2 = new List <Column>();

            foreach (Column column in this.Columns)
            {
                if (column.Name == previousName)
                {
                    tmp2.Add(newColumn);
                }
                else
                {
                    tmp2.Add(column);
                }
            }
            this.Columns = tmp2;

            List <string> tmp3 = new List <string>();

            foreach (string name in this.PrimaryKey)
            {
                if (name == previousName)
                {
                    tmp3.Add(newColumn.Name);
                }
                else
                {
                    tmp3.Add(name);
                }
            }
            this.PrimaryKey = tmp3;

            List <ForeignKey> tmp4 = new List <ForeignKey>();

            foreach (ForeignKey fk in this.ForeignKeys)
            {
                ForeignKey fk2 = new ForeignKey
                {
                    ExternTableName = fk.ExternTableName,
                    Info            = new List <ForeignKeyInside>()
                };
                foreach (ForeignKeyInside fki in fk.Info)
                {
                    if (fki.ColumnName == previousName)
                    {
                        fk2.Info.Add(new ForeignKeyInside
                        {
                            ColumnName       = newColumn.Name,
                            ExternColumnName = fki.ExternColumnName
                        });
                    }
                    else
                    {
                        fk2.Info.Add(new ForeignKeyInside
                        {
                            ColumnName       = fki.ColumnName,
                            ExternColumnName = fki.ExternColumnName
                        });
                    }
                }
                tmp4.Add(fk2);
            }
            this.ForeignKeys = tmp4;

            foreach (Table table in db.Content)
            {
                if (table.Name != this.Name)
                {
                    bool keep = true;
                    foreach (ForeignKey fk in table.ForeignKeys)
                    {
                        if (keep == true)
                        {
                            if (fk.ExternTableName == this.Name)
                            {
                                foreach (ForeignKeyInside fki in fk.Info)
                                {
                                    if (keep == true)
                                    {
                                        if (fki.ExternColumnName == previousName)
                                        {
                                            c2.Name = fki.ColumnName;
                                            table.updateColumn(c2.Name, c2, db);
                                            keep = false;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }