public static void DropConstraint()
        {
            var statement = new AlterTableStatement(ObjectName.Parse("APP.test"), new DropConstraintAction("unique_id"));

            var sql      = statement.ToString();
            var expected = "ALTER TABLE APP.test DROP CONSTRAINT unique_id";

            Assert.AreEqual(expected, sql);
        }
        public static void DropDefault()
        {
            var statement = new AlterTableStatement(ObjectName.Parse("test"), new DropDefaultAction("a"));

            var sql      = statement.ToString();
            var expected = "ALTER TABLE test DROP DEFAULT a";

            Assert.AreEqual(expected, sql);
        }
        public static void DropPrimaryKey()
        {
            var statement = new AlterTableStatement(ObjectName.Parse("APP.test"), new DropPrimaryKeyAction());

            var sql      = statement.ToString();
            var expected = "ALTER TABLE APP.test DROP PRIMARY KEY";

            Assert.AreEqual(expected, sql);
        }
Ejemplo n.º 4
0
        public static void DropColumn()
        {
            var statement = new AlterTableStatement(ObjectName.Parse("APP.test"), new DropColumnAction("a"));

            var sql = statement.ToString();
            var expected = new StringBuilder();
            expected.Append("ALTER TABLE APP.test DROP COLUMN a");

            Assert.AreEqual(expected.ToString(), sql);
        }
Ejemplo n.º 5
0
        public static void AddPrimaryKey()
        {
            var constraint = new SqlTableConstraint(ConstraintType.PrimaryKey, new[] { "id" });
            var statement = new AlterTableStatement(ObjectName.Parse("test"), new AddConstraintAction(constraint));

            var sql = statement.ToString();
            var expected = new StringBuilder();
            expected.Append("ALTER TABLE test ADD CONSTRAINT PRIMARY KEY(id)");

            Assert.AreEqual(expected.ToString(), sql);
        }
Ejemplo n.º 6
0
        public static void AddUnique()
        {
            var constraint = new SqlTableConstraint("unique_id", ConstraintType.Unique, new[] { "id" });
            var statement = new AlterTableStatement(ObjectName.Parse("test"), new AddConstraintAction(constraint));

            var sql = statement.ToString();
            var expected = new StringBuilder();
            expected.Append("ALTER TABLE test ADD CONSTRAINT unique_id UNIQUE(id)");

            Assert.AreEqual(expected.ToString(), sql);
        }
        public static void DropColumn()
        {
            var statement = new AlterTableStatement(ObjectName.Parse("APP.test"), new DropColumnAction("a"));

            var sql      = statement.ToString();
            var expected = new StringBuilder();

            expected.Append("ALTER TABLE APP.test DROP COLUMN a");

            Assert.AreEqual(expected.ToString(), sql);
        }
Ejemplo n.º 8
0
        public void AlterTable_AddColumn()
        {
            var addColumn = new AddColumnAction(new SqlTableColumn("a", PrimitiveTypes.BigInt()));
            var statement = new AlterTableStatement(ObjectName.Parse("APP.test_table1"), addColumn);

            SerializeAndAssert(statement, (serialized, deserialized) => {
                Assert.IsNotNull(deserialized);
                Assert.IsNotNull(statement.TableName);
                Assert.IsNotNull(statement.Action);
                Assert.IsInstanceOf<AddColumnAction>(statement.Action);
            });
        }
Ejemplo n.º 9
0
        public static void AddColumn()
        {
            var column = new SqlTableColumn("a", PrimitiveTypes.Integer());
            var statement = new AlterTableStatement(ObjectName.Parse("APP.test_table"), new AddColumnAction(column));

            var sql = statement.ToString();
            var expected = new StringBuilder();
            expected.Append("ALTER TABLE APP.test_table ");
            expected.Append("ADD COLUMN a INTEGER");

            Assert.AreEqual(expected.ToString(), sql);
        }
        public static void AddPrimaryKey()
        {
            var constraint = new SqlTableConstraint(ConstraintType.PrimaryKey, new[] { "id" });
            var statement  = new AlterTableStatement(ObjectName.Parse("test"), new AddConstraintAction(constraint));

            var sql      = statement.ToString();
            var expected = new StringBuilder();

            expected.Append("ALTER TABLE test ADD CONSTRAINT PRIMARY KEY(id)");

            Assert.AreEqual(expected.ToString(), sql);
        }
        public static void AddUnique()
        {
            var constraint = new SqlTableConstraint("unique_id", ConstraintType.Unique, new[] { "id" });
            var statement  = new AlterTableStatement(ObjectName.Parse("test"), new AddConstraintAction(constraint));

            var sql      = statement.ToString();
            var expected = new StringBuilder();

            expected.Append("ALTER TABLE test ADD CONSTRAINT unique_id UNIQUE(id)");

            Assert.AreEqual(expected.ToString(), sql);
        }
        public static void AddColumn()
        {
            var column    = new SqlTableColumn("a", PrimitiveTypes.Integer());
            var statement = new AlterTableStatement(ObjectName.Parse("APP.test_table"), new AddColumnAction(column));

            var sql      = statement.ToString();
            var expected = new StringBuilder();

            expected.Append("ALTER TABLE APP.test_table ");
            expected.Append("ADD COLUMN a INTEGER");

            Assert.AreEqual(expected.ToString(), sql);
        }
Ejemplo n.º 13
0
        public static void AddCheck()
        {
            var constraint = new SqlTableConstraint(ConstraintType.Check) {
                CheckExpression = SqlExpression.Equal(SqlExpression.Reference(new ObjectName("a")),
                    SqlExpression.Constant(2))
            };

            var statement = new AlterTableStatement(ObjectName.Parse("test"), new AddConstraintAction(constraint));

            var sql = statement.ToString();
            var expected = new StringBuilder();
            expected.Append("ALTER TABLE test ADD CONSTRAINT ");
            expected.Append("CHECK a = 2");

            Assert.AreEqual(expected.ToString(), sql);
        }
        public static void AddCheck()
        {
            var constraint = new SqlTableConstraint(ConstraintType.Check)
            {
                CheckExpression = SqlExpression.Equal(SqlExpression.Reference(new ObjectName("a")),
                                                      SqlExpression.Constant(2))
            };

            var statement = new AlterTableStatement(ObjectName.Parse("test"), new AddConstraintAction(constraint));

            var sql      = statement.ToString();
            var expected = new StringBuilder();

            expected.Append("ALTER TABLE test ADD CONSTRAINT ");
            expected.Append("CHECK a = 2");

            Assert.AreEqual(expected.ToString(), sql);
        }
        public void AlterTableAddColumn()
        {
            var tableName = ObjectName.Parse("APP.test_table");
            var column = new SqlTableColumn("reserved", PrimitiveTypes.Boolean());
            var statement = new AlterTableStatement(tableName, new AddColumnAction(column));

            ITable result = null;
            Assert.DoesNotThrow(() => result = statement.Execute(Query));
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.RowCount);
            Assert.AreEqual(1, result.TableInfo.ColumnCount);
            Assert.AreEqual(0,  ((SqlNumber) result.GetValue(0,0).Value).ToInt32());

            var testTable = Query.GetTable(new ObjectName("test_table"));

            Assert.IsNotNull(testTable);
            Assert.AreEqual(6, testTable.TableInfo.ColumnCount);
        }
Ejemplo n.º 16
0
        public void AlterTableAddColumn()
        {
            var tableName = ObjectName.Parse("APP.test_table");
            var column    = new SqlTableColumn("reserved", PrimitiveTypes.Boolean());
            var statement = new AlterTableStatement(tableName, new AddColumnAction(column));

            ITable result = null;

            Assert.DoesNotThrow(() => result = statement.Execute(Query));
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.RowCount);
            Assert.AreEqual(1, result.TableInfo.ColumnCount);
            Assert.AreEqual(0, ((SqlNumber)result.GetValue(0, 0).Value).ToInt32());

            var testTable = Query.GetTable(new ObjectName("test_table"));

            Assert.IsNotNull(testTable);
            Assert.AreEqual(6, testTable.TableInfo.ColumnCount);
        }
        public static void SimpleAddForeignKey()
        {
            var constraint = new SqlTableConstraint(ConstraintType.ForeignKey, new[] { "ref_id" })
            {
                ReferenceTable   = "test_table1",
                ReferenceColumns = new[] { "id" }
            };

            var statement = new AlterTableStatement(ObjectName.Parse("test"), new AddConstraintAction(constraint));

            var sql      = statement.ToString();
            var expected = new StringBuilder();

            expected.Append("ALTER TABLE test ADD CONSTRAINT FOREIGN KEY(ref_id) ");
            expected.Append("REFERENCES test_table1(id) ");
            expected.Append("ON DELETE NO ACTION ");
            expected.Append("ON UPDATE NO ACTION");

            Assert.AreEqual(expected.ToString(), sql);
        }
Ejemplo n.º 18
0
        public static void DropConstraint()
        {
            var statement = new AlterTableStatement(ObjectName.Parse("APP.test"), new DropConstraintAction("unique_id"));

            var sql = statement.ToString();
            var expected = "ALTER TABLE APP.test DROP CONSTRAINT unique_id";

            Assert.AreEqual(expected, sql);
        }
Ejemplo n.º 19
0
        public static void SimpleAddForeignKey()
        {
            var constraint = new SqlTableConstraint(ConstraintType.ForeignKey, new[] { "ref_id" }) {
                ReferenceTable = "test_table1",
                ReferenceColumns = new[] { "id" }
            };

            var statement = new AlterTableStatement(ObjectName.Parse("test"), new AddConstraintAction(constraint));

            var sql = statement.ToString();
            var expected = new StringBuilder();
            expected.Append("ALTER TABLE test ADD CONSTRAINT FOREIGN KEY(ref_id) ");
            expected.Append("REFERENCES test_table1(id) ");
            expected.Append("ON DELETE NO ACTION ");
            expected.Append("ON UPDATE NO ACTION");

            Assert.AreEqual(expected.ToString(), sql);
        }
Ejemplo n.º 20
0
        public static void DropPrimaryKey()
        {
            var statement = new AlterTableStatement(ObjectName.Parse("APP.test"), new DropPrimaryKeyAction());

            var sql = statement.ToString();
            var expected = "ALTER TABLE APP.test DROP PRIMARY KEY";

            Assert.AreEqual(expected, sql);
        }
Ejemplo n.º 21
0
 protected virtual SqlStatement VisitAlterTable(AlterTableStatement statement)
 {
     return new AlterTableStatement(statement.TableName, statement.Action);
 }
Ejemplo n.º 22
0
        public static void DropDefault()
        {
            var statement = new AlterTableStatement(ObjectName.Parse("test"), new DropDefaultAction("a"));

            var sql = statement.ToString();
            var expected = "ALTER TABLE test DROP DEFAULT a";

            Assert.AreEqual(expected, sql);
        }
Ejemplo n.º 23
0
 protected virtual SqlStatement VisitAlterTable(AlterTableStatement statement)
 {
     return(new AlterTableStatement(statement.TableName, statement.Action));
 }