Beispiel #1
0
 public void AddDefaultAutoName()
 {
     var tbl = new Table("test")
         .AddColumn(new Column("testid", System.Data.DbType.Int32));
     tbl.Default("100500");
     Assert.AreEqual("DF_TEST_TESTID", tbl.Columns[0].Constraint.Name);
 }
Beispiel #2
0
 public void AddDefaultAtPrimaryKeyColumn()
 {
     var tbl = new Table("test")
         .AddColumn(new Column("testid", System.Data.DbType.Int32))
         .AddPrimaryKey("testid");
     Assert.Throws<ConflictingDataException>(() => tbl.Default("test"));
 }
Beispiel #3
0
 /// <summary>
 /// Добавляет колонку
 /// </summary>
 /// <param name="table">Таблица</param>
 /// <param name="column">Колонка</param>
 public void AddColumn(Table table, Column column)
 {
     try
     {
         strategy.AddColumn(table, column);
     }
     catch
     {
     }
 }
Beispiel #4
0
 public void AddOneDefaultAtLastColumn()
 {
     var tbl = new Table("test")
         .AddColumn(new Column("testid", System.Data.DbType.Int32))
         .AddColumn(new Column("col2", System.Data.DbType.Int32))
         .AddColumn(new Column("col3", System.Data.DbType.Int32))
         .AddPrimaryKey("testid");
     tbl.Default("100500");
     var constraint = tbl.Columns.Last().Constraint as ValueDefault;
     Assert.IsNotNull(constraint);
     Assert.AreEqual("100500", constraint.Value);
 }
Beispiel #5
0
 public void WithoutCollumns()
 {
     strategy = ObjectFactory.GetInstance<IDatabaseStrategy>();
     var table = new Table("TestTable");
     Assert.Throws<ColumnExpectedException>(() => strategy.CreateTable(table));
 }
Beispiel #6
0
 public void WithDefault()
 {
     strategy = ObjectFactory.GetInstance<IDatabaseStrategy>();
     command.SetupSet(x => x.CommandText = It.IsAny<string>()).Verifiable();
     var table = new Table("TestTable");
     table.AddColumn(new Column("test", DbType.Int32)).Default("100500");
     table.AddColumn(new Column("test2", DbType.String.Size(50))).Default("this is the test");
     strategy.CreateTable(table);
     command.VerifySet(x => x.CommandText = WithDefaultCommand);
 }
Beispiel #7
0
 public void RegularCreateTableWithIdentity()
 {
     strategy = ObjectFactory.GetInstance<IDatabaseStrategy>();
     command.SetupSet(x => x.CommandText = It.IsAny<string>()).Verifiable();
     var table = new Table("TestTable");
     table.AddColumn(new Column("test", DbType.Int32, false, true));
     table.AddColumn(new Column("test2", DbType.String.Size(50)));
     strategy.CreateTable(table);
     command.VerifySet(x => x.CommandText = RegularCreateTableWithIdentityCommand);
 }
Beispiel #8
0
        /// <summary>
        /// ������ �������
        /// </summary>
        /// <param name="table">�������</param>
        public void CreateTable(Table table)
        {
            if (table.Columns == null || table.Columns.Count == 0)
            {
                throw new ColumnExpectedException();
            }

            ExecuteNonQuery(razor.Parse(TemplateManager.GetCreateTableTemplate(), table, "create table"));
            log.Info("������� {0} ������� � ������� {1}", table.Name, table.PartitionName);
        }
Beispiel #9
0
        /// <summary>
        /// ��������� �������
        /// </summary>
        /// <param name="table">�������</param>
        /// <param name="column">�������</param>
        public void AddColumn(Table table, Column column)
        {
            if (!column.Nullable && (column.Constraint == null || !(column.Constraint is Default)))
            {
                throw new ArgumentException();
            }

            try
            {
                ExecuteNonQuery(razor.Parse(TemplateManager.GetAddColumnTemplate(), new object[] { table, column }, "add column"));
            }
            catch (TemplateCompilationException ex)
            {
                ex.Errors.ToList().ForEach(p => Console.WriteLine(p.ErrorText));
            }

            log.Info("�������� ������� {0} � ������� {1}", column.Name, table.Name);
        }
Beispiel #10
0
 public void AddPrimaryCollumnConstraint()
 {
     var tbl = new Table("test")
         .AddColumn(new Column("testid", System.Data.DbType.Int32))
         .AddPrimaryKey("testid");
     Assert.IsNotNull(tbl.Columns[0].Constraint);
 }
Beispiel #11
0
 /// <summary>
 /// Конструктор
 /// </summary>
 /// <param name="name">Название объекта</param>
 /// <param name="table">Таблица</param>
 /// <param name="partitionName">Партиция</param>
 /// <param name="indexType">Тип индекса</param>
 /// <param name="isUnique">Уникальный индекс</param>
 public Index(string name, Table table, string partitionName = "", IndexType indexType = IndexType.Nonclustered, bool isUnique = false)
     : this(name, table, new IndexColumn[0], partitionName, indexType, isUnique)
 {
 }
Beispiel #12
0
 public void AddDefaultWithoutColumn()
 {
     var tbl = new Table("test");
     Assert.Throws<ColumnExpectedException>(() => tbl.Default("test"));
 }
Beispiel #13
0
 public void AddPrimaryKeyWithoutColumn()
 {
     Table tbl = new Table("test");
     Assert.Throws<ColumnExpectedException>(() => tbl.AddPrimaryKey("testid"));
 }
Beispiel #14
0
 public void AddPrimaryKeyPrimaryKeyName()
 {
     var tbl = new Table("test")
         .AddColumn(new Column("testid", System.Data.DbType.Int32))
         .AddPrimaryKey("testid");
     Assert.AreEqual("PK_TEST", tbl.Columns[0].Constraint.Name);
 }
Beispiel #15
0
 /// <summary>
 /// Создаёт таблицу
 /// </summary>
 /// <param name="table">Таблица</param>
 public void CreateTable(Table table)
 {
     try
     {
         strategy.CreateTable(table);
     }
     catch
     {
     }
 }
Beispiel #16
0
 public void WithPrimaryKeyCustomPartition()
 {
     strategy = ObjectFactory.GetInstance<IDatabaseStrategy>();
     command.SetupSet(x => x.CommandText = It.IsAny<string>()).Verifiable();
     var table = new Table(
         "TestTable")
         .AddColumn(new Column("testid", DbType.Int32))
         .AddColumn(new Column("test2", DbType.String.Size(50)))
         .AddPrimaryKey("testid", "TESTPARTIOTION");
     strategy.CreateTable(table);
     command.VerifySet(x => x.CommandText = WithPrimaryKeyCustomPartitionCommand);
 }
Beispiel #17
0
 public void WithStandartDefaultGuid()
 {
     strategy = ObjectFactory.GetInstance<IDatabaseStrategy>();
     command.SetupSet(x => x.CommandText = It.IsAny<string>()).Verifiable();
     var table = new Table("TestTable");
     table.AddColumn(new Column("test", DbType.Int32)).Default(StandartDefaultType.guid);
     strategy.CreateTable(table);
     command.VerifySet(x => x.CommandText = WithStandartDefaultGuidCommand);
 }
Beispiel #18
0
 /// <summary>
 /// Конструктор
 /// </summary>
 /// <param name="name">Название индекса</param>
 /// <param name="table">Таблица</param>
 /// <param name="columns">Столбцы для индекса</param>
 /// <param name="partitionName">Партиция</param>
 /// <param name="indexType">Тип индекса</param>
 /// <param name="isUnique">Уникальный индекс</param>
 public Index(string name, Table table, IEnumerable<IndexColumn> columns, string partitionName = "", IndexType indexType = IndexType.Nonclustered, bool isUnique = false)
     : base(name)
 {
     this.table = table;
     this.columns = new List<IndexColumn>(columns);
     this.indexType = indexType;
     this.partitionName = partitionName;
     this.isUnique = isUnique;
 }