Ejemplo n.º 1
0
        public static void AddConstraint(this IQuery query, ObjectName tableName, ConstraintInfo constraintInfo)
        {
            if (constraintInfo.ConstraintType == ConstraintType.PrimaryKey)
            {
                var columnNames = constraintInfo.ColumnNames;
                if (columnNames.Length > 1)
                {
                    throw new ArgumentException();
                }

                query.AddPrimaryKey(tableName, columnNames[0], constraintInfo.ConstraintName);
            }
            else if (constraintInfo.ConstraintType == ConstraintType.Unique)
            {
                query.AddUniqueKey(tableName, constraintInfo.ColumnNames, constraintInfo.ConstraintName);
            }
            else if (constraintInfo.ConstraintType == ConstraintType.Check)
            {
                query.AddCheck(tableName, constraintInfo.CheckExpression, constraintInfo.ConstraintName);
            }
            else if (constraintInfo.ConstraintType == ConstraintType.ForeignKey)
            {
                query.AddForeignKey(tableName, constraintInfo.ColumnNames, constraintInfo.ForeignTable,
                                    constraintInfo.ForeignColumnNames, constraintInfo.OnDelete, constraintInfo.OnUpdate, constraintInfo.ConstraintName);
            }
        }
Ejemplo n.º 2
0
        protected override bool OnSetUp(string testName, IQuery query)
        {
            if (testName.EndsWith("Violation"))
            {
                CreateTables(query, testName);

                if (testName.Equals("UniqueKeyViolation") ||
                    testName.Equals("PrimaryKeyViolation"))
                {
                    InsertData(query);
                }
                else if (testName.Equals("CheckViolation"))
                {
                    query.AddCheck(new ObjectName("a"),
                                   SqlExpression.SmallerOrEqualThan(SqlExpression.Reference(new ObjectName("id")), SqlExpression.Constant(100)));
                }
            }

            return(true);
        }
Ejemplo n.º 3
0
        protected override bool OnSetUp(string testName, IQuery query)
        {
            if (testName.EndsWith("Violation")) {
                CreateTables(query, testName);

                if (testName.Equals("UniqueKeyViolation") ||
                    testName.Equals("PrimaryKeyViolation")) {
                    InsertData(query);
                } else if (testName.Equals("CheckViolation")) {
                    query.AddCheck(new ObjectName("a"),
                        SqlExpression.SmallerOrEqualThan(SqlExpression.Reference(new ObjectName("id")), SqlExpression.Constant(100)));
                }
            }

            return true;
        }