Пример #1
0
        private TableInfo FillTable4()
        {
            TableInfo tableInfo = new TableInfo();
            tableInfo.TableName = "TestTbl4";
            tableInfo.Remarks = "测试表4";

            ColumnInfo colInfo = new ColumnInfo();
            colInfo.ColumnName = "Col1";
            colInfo.IsPK = true;
            colInfo.DBType = DbType.AnsiString;
            colInfo.CurrTable = tableInfo;
            colInfo.Remarks = "主键字段1";
            colInfo.MaxLength = 40;
            tableInfo.Columns.Add(colInfo);

            colInfo = new ColumnInfo();
            colInfo.ColumnName = "FKCol1";
            colInfo.DBType = DbType.AnsiString;
            colInfo.CurrTable = tableInfo;
            colInfo.Remarks = "外键1";
            colInfo.MaxLength = 40;
            colInfo.IsFK = true;
            colInfo.RefTableName = "TestTbl2";
            colInfo.RefColumnName = "Col1";
            tableInfo.Columns.Add(colInfo);

            colInfo = new ColumnInfo();
            colInfo.ColumnName = "FKCol2";
            colInfo.DBType = DbType.AnsiString;
            colInfo.CurrTable = tableInfo;
            colInfo.Remarks = "外键2";
            colInfo.MaxLength = 40;
            colInfo.IsFK = true;
            colInfo.RefTableName = "TestTbl3";
            colInfo.RefColumnName = "Col1";
            tableInfo.Columns.Add(colInfo);

            colInfo = new ColumnInfo();
            colInfo.ColumnName = "Col3";
            colInfo.IsUnique = true;
            colInfo.UniqueConstraintName = "Col34";
            colInfo.DBType = DbType.AnsiString;
            colInfo.CurrTable = tableInfo;
            colInfo.Remarks = "唯一字段34";
            colInfo.MaxLength = 40;
            tableInfo.Columns.Add(colInfo);

            colInfo = new ColumnInfo();
            colInfo.ColumnName = "Col4";
            colInfo.IsUnique = true;
            colInfo.UniqueConstraintName = "Col34";
            colInfo.DBType = DbType.AnsiString;
            colInfo.CurrTable = tableInfo;
            colInfo.Remarks = "唯一字段34";
            colInfo.MaxLength = 40;
            tableInfo.Columns.Add(colInfo);

            colInfo = new ColumnInfo();
            colInfo.ColumnName = "Col5";
            colInfo.DBType = DbType.DateTime;
            colInfo.CurrTable = tableInfo;
            colInfo.Remarks = "字段5";
            colInfo.DefaultValue = "1753-01-01";
            tableInfo.Columns.Add(colInfo);

            colInfo = new ColumnInfo();
            colInfo.ColumnName = "Col6";
            colInfo.DBType = DbType.Int32;
            colInfo.CurrTable = tableInfo;
            colInfo.Remarks = "字段6";
            colInfo.DefaultValue = 100;
            tableInfo.Columns.Add(colInfo);

            colInfo = new ColumnInfo();
            colInfo.ColumnName = "Col7";
            colInfo.DBType = DbType.Decimal;
            colInfo.CurrTable = tableInfo;
            colInfo.Remarks = "字段7";
            colInfo.DefaultValue = 100.32;
            colInfo.Precision = 10;
            colInfo.Scale = 2;
            tableInfo.Columns.Add(colInfo);

            return tableInfo;
        }
Пример #2
0
        public void DropColumnTest()
        {
            ColumnInfo colInfo = new ColumnInfo();
            colInfo.ColumnName = "Col9";
            colInfo.IsUnique = true;
            colInfo.DBType = DbType.AnsiString;
            colInfo.CurrTable = tableInfo;
            colInfo.Remarks = "字段9";
            colInfo.MaxLength = 40;
            colInfo.DefaultValue = "1134";
            colInfo.UniqueConstraintName = "Col34";

            NFramework.DBTool.Test.IDal.DalManager.DalFactory.DropColumn(tableInfo, colInfo);
        }
Пример #3
0
        public void AddColumnTest()
        {
            // 增加一般字段
            ColumnInfo colInfo = new ColumnInfo();
            colInfo.ColumnName = "Col8";
            colInfo.DBType = DbType.AnsiString;
            colInfo.CurrTable = tableInfo;
            colInfo.Remarks = "字段8";
            colInfo.MaxLength = 40;
            colInfo.DefaultValue = "1134";
            NFramework.DBTool.Test.IDal.DalManager.DalFactory.AddColumn(tableInfo, colInfo);
            tableInfo.Columns.Add(colInfo);

            // 已存在字段
            try
            {
                colInfo = new ColumnInfo();
                colInfo.ColumnName = "Col2";
                colInfo.IsUnique = true;
                colInfo.UniqueConstraintName = "Col2";
                colInfo.DBType = DbType.AnsiString;
                colInfo.CurrTable = tableInfo;
                colInfo.Remarks = "唯一字段1";
                colInfo.MaxLength = 40;

                NFramework.DBTool.Test.IDal.DalManager.DalFactory.AddColumn(tableInfo, colInfo);
                Assert.IsTrue(false);
            }
            catch(Exception ex)
            {
                Assert.IsTrue(true);
            }

            // 增加同组唯一字段
            colInfo = new ColumnInfo();
            colInfo.ColumnName = "Col9";
            colInfo.IsUnique = true;
            colInfo.DBType = DbType.AnsiString;
            colInfo.CurrTable = tableInfo;
            colInfo.Remarks = "字段9";
            colInfo.MaxLength = 40;
            colInfo.DefaultValue = "1134";
            colInfo.UniqueConstraintName = "Col34";
            NFramework.DBTool.Test.IDal.DalManager.DalFactory.AddColumn(tableInfo, colInfo);
            tableInfo.Columns.Add(colInfo);

            colInfo = new ColumnInfo();
            colInfo.ColumnName = "Col10";
            colInfo.DBType = DbType.AnsiString;
            colInfo.CurrTable = tableInfo;
            colInfo.Remarks = "字段10";
            colInfo.MaxLength = 40;
            colInfo.DefaultValue = "1010";
            NFramework.DBTool.Test.IDal.DalManager.DalFactory.AddColumn(tableInfo, colInfo);
            tableInfo.Columns.Add(colInfo);

            // 增加主键字段
            colInfo = new ColumnInfo();
            colInfo.ColumnName = "Col111";
            colInfo.IsPK = true;
            colInfo.DBType = DbType.AnsiString;
            colInfo.CurrTable = tableInfo;
            colInfo.Remarks = "主键字段111";
            colInfo.MaxLength = 40;
            NFramework.DBTool.Test.IDal.DalManager.DalFactory.AddColumn(tableInfo, colInfo);
            tableInfo.Columns.Add(colInfo);
        }