private static SQL.Components.Field CreatePrimaryKey(Table t)
 {
     SQL.Components.Field f = null;
     try
     {
         f = new SQL.Components.Field()
         {
             AllowNull             = false,
             IsPrimary             = true,
             IsClustered           = true,
             IdentitySpecification = new IdentitySpecification(),
             Name     = t.Name + "Id",
             DataType = new Enums.DataType()
             {
                 HasTypeError = false,
                 IsBaseType   = true,
                 IsList       = false,
                 IsNullable   = false,
                 Name         = Enums.SQLCondensedDataType.SMALLINT.ToString()
             },
             OriginalName = "Missing Primary Key"
         };
     }
     catch (Exception ae)
     { string s = ae.ToString(); }
     return(f);
 }
        public static Table ConfirmPrimaryKeys(Table t)
        {
            try
            {
                //Test for tables without a primary key
                if (t.Fields.Count(f => f.IsPrimary) != 1)
                {
                    if (t.Fields.Count(f => f.IsPrimary) < 1)
                    {
                        //Table does NOT have a Primary Key
                        SQL.Components.Field pkN = CreatePrimaryKey(t);
                        t.Fields.Insert(0, pkN);
                    }
                    else if (t.Fields.Count(f => f.IsPrimary) > 1)
                    {
                    }
                }

                //Test for tables with an unrecognised primary key name
                SQL.Components.Field pk = t.Fields.FirstOrDefault(f => f.IsPrimary);
                if (pk.Name != t.Name + "Id")
                {
                    SQL.Components.Field fpk = CreatePrimaryKey(t);
                    t.Fields.Insert(0, fpk);
                }
            }
            catch (Exception ae)
            { string s = ae.ToString(); }
            return(t);
        }
 public static Table LimitedTextLengths(Table t)
 {
     try
     {
         SQL.Components.Field f = t.Fields.FirstOrDefault(fs => fs.IsPrimary == true);
         if (!f.DataType.Name.Contains("INT"))
         {
             if (f.DataType.Name == "NVARCHAR")
             {
                 f.DataType.Para1 = 255;
             }
             else if (f.DataType.Name == "VARCHAR")
             {
                 f.DataType.Para1 = 512;
             }
             else
             {
                 f.DataType.Para1 = 512;
             }
         }
     }
     catch (Exception ae)
     { string s = ae.ToString(); }
     return(t);
 }
示例#4
0
 public static string HasValidName(SQL.Components.Field f, SQL.Components.Table t)
 {
     try
     {
         if (f.Name == null || f.Name == "")
         {
             string s = t.Name + "Missing";
             return(s);
         }
     }
     catch (Exception ae)
     { string s = ae.ToString(); }
     return(f.Name);
 }