private DBInfo.Core.Statement.CreatePrimaryKey ParseCreatePrimaryKeyStatement(CreatePrimaryKey xmlPrimaryKey)
 {
     DBInfo.Core.Model.Table t = new DBInfo.Core.Model.Table();
     t.TableName      = xmlPrimaryKey.TableName;
     t.PrimaryKeyName = xmlPrimaryKey.PrimaryKeyName;
     foreach (string c in xmlPrimaryKey.Columns)
     {
         t.PrimaryKeyColumns.Add(c);
     }
     DBInfo.Core.Statement.CreatePrimaryKey cpk = new DBInfo.Core.Statement.CreatePrimaryKey();
     cpk.Table = t;
     return(cpk);
 }
Ejemplo n.º 2
0
        private void GenerateConstraints(List <DBInfo.Core.Statement.CreateCheckConstraint> createCheckList,
                                         List <DBInfo.Core.Statement.CreatePrimaryKey> createPKList)
        {
            if (!Directory.Exists(OutputDir + "\\" + ConstraintsDir))
            {
                Directory.CreateDirectory(OutputDir + "\\" + ConstraintsDir);
            }

            List <string> tableNames =
                (from DBInfo.Core.Statement.CreateCheckConstraint ccc in createCheckList
                 select ccc.CheckConstraint.TableName).Union <string>(
                    from DBInfo.Core.Statement.CreatePrimaryKey cpk in createPKList
                    select cpk.Table.TableName).Distinct <string>().ToList <string>();

            foreach (string tableName in tableNames)
            {
                DBInfo.Core.Statement.CreatePrimaryKey createPK =
                    (from DBInfo.Core.Statement.CreatePrimaryKey cpk in createPKList
                     where cpk.Table.TableName == tableName
                     select cpk).FirstOrDefault <DBInfo.Core.Statement.CreatePrimaryKey>();

                List <DBInfo.Core.Statement.CreateCheckConstraint> createCheckStatements =
                    (from DBInfo.Core.Statement.CreateCheckConstraint ccc in createCheckList
                     where ccc.CheckConstraint.TableName == tableName
                     select ccc).ToList <DBInfo.Core.Statement.CreateCheckConstraint>();

                int StatementCount = 0;
                if (createPK != null)
                {
                    StatementCount++;
                }
                StatementCount += createCheckStatements.Count;
                StatementCollection stCol = new StatementCollection();
                stCol.Statement = new Statement[StatementCount];
                int count = 0;

                if (createPK != null)
                {
                    DBInfo.XMLDatabase.CreatePrimaryKey xmlPK = new DBInfo.XMLDatabase.CreatePrimaryKey();
                    xmlPK.TableName      = createPK.Table.TableName;
                    xmlPK.PrimaryKeyName = createPK.Table.PrimaryKeyName;
                    xmlPK.Columns        = new string[createPK.Table.PrimaryKeyColumns.Count];

                    foreach (string c in createPK.Table.PrimaryKeyColumns)
                    {
                        xmlPK.Columns[createPK.Table.PrimaryKeyColumns.IndexOf(c)] = c;
                    }
                    stCol.Statement[0] = xmlPK;
                    count++;
                }

                foreach (DBInfo.Core.Statement.CreateCheckConstraint ccc in createCheckStatements)
                {
                    CreateCheckConstraint xmlCK = new CreateCheckConstraint();
                    xmlCK.TableName           = ccc.CheckConstraint.TableName;
                    xmlCK.CheckConstraintName = ccc.CheckConstraint.CheckConstraintName;
                    xmlCK.SourceCode          = ccc.CheckConstraint.Expression;
                    stCol.Statement[count]    = xmlCK;
                    count++;
                }

                generateXMLOutput(stCol, OutputDir + "\\" + ConstraintsDir + "\\" + tableName + ".constraints.xml", true);
            }
        }