Beispiel #1
0
 public override string ToString()
 {
     // Test for MySQL primary key situation.
     if (CurrentDatabaseProvider == DatabaseProviders.MySql)
     {
         if (Constraint.IsPrimaryKeyConstraint)
         {
             return(string.Format(SqlSyntax.DeleteConstraint,
                                  SqlSyntax.GetQuotedTableName(Constraint.TableName),
                                  "PRIMARY KEY",
                                  ""));
         }
         else
         {
             return(string.Format(SqlSyntax.DeleteConstraint,
                                  SqlSyntax.GetQuotedTableName(Constraint.TableName),
                                  "FOREIGN KEY",
                                  ""));
         }
     }
     else
     {
         return(string.Format(SqlSyntax.DeleteConstraint,
                              SqlSyntax.GetQuotedTableName(Constraint.TableName),
                              SqlSyntax.GetQuotedName(Constraint.ConstraintName)));
     }
 }
Beispiel #2
0
    protected override string GetSql()
    {
        var constraintType = Constraint.IsPrimaryKeyConstraint ? "PRIMARY KEY" : "UNIQUE";

        if (Constraint.IsPrimaryKeyConstraint && SqlSyntax.SupportsClustered())
        {
            constraintType += Constraint.IsPrimaryKeyClustered ? " CLUSTERED" : " NONCLUSTERED";
        }

        if (Constraint.IsNonUniqueConstraint)
        {
            constraintType = string.Empty;
        }

        var columns = new string[Constraint.Columns.Count];

        for (var i = 0; i < Constraint.Columns.Count; i++)
        {
            columns[i] = SqlSyntax.GetQuotedColumnName(Constraint.Columns.ElementAt(i));
        }

        return(string.Format(
                   SqlSyntax.CreateConstraint,
                   SqlSyntax.GetQuotedTableName(Constraint.TableName),
                   SqlSyntax.GetQuotedName(Constraint.ConstraintName),
                   constraintType,
                   string.Join(", ", columns)));
    }
Beispiel #3
0
        public override string ToString()
        {
            if (IsExpressionSupported() == false)
            {
                return(string.Empty);
            }

            if (ForeignKey.ForeignTable == null)
            {
                throw new ArgumentNullException("Table name not specified, ensure you have appended the OnTable extension. Format should be Delete.ForeignKey(KeyName).OnTable(TableName)");
            }

            if (CurrentDatabaseProvider == DatabaseProviders.MySql)
            {
                //MySql naming "convention" for foreignkeys, which aren't explicitly named
                if (string.IsNullOrEmpty(ForeignKey.Name))
                {
                    ForeignKey.Name = string.Format("{0}_ibfk_1", ForeignKey.ForeignTable.ToLower());
                }

                return(string.Format(SqlSyntax.DeleteConstraint,
                                     SqlSyntax.GetQuotedTableName(ForeignKey.ForeignTable),
                                     "FOREIGN KEY",
                                     SqlSyntax.GetQuotedName(ForeignKey.Name)));
            }

            if (string.IsNullOrEmpty(ForeignKey.Name))
            {
                ForeignKey.Name = string.Format("FK_{0}_{1}_{2}", ForeignKey.ForeignTable, ForeignKey.PrimaryTable, ForeignKey.PrimaryColumns.First());
            }

            return(string.Format(SqlSyntax.DeleteConstraint,
                                 SqlSyntax.GetQuotedTableName(ForeignKey.ForeignTable),
                                 SqlSyntax.GetQuotedName(ForeignKey.Name)));
        }
    protected override string GetSql() =>

    // NOTE Should probably investigate if Deleting a Default Constraint is different from deleting a 'regular' constraint
    string.Format(
        SqlSyntax.DeleteConstraint,
        SqlSyntax.GetQuotedTableName(TableName),
        SqlSyntax.GetQuotedName(ConstraintName));
Beispiel #5
0
        public override string ToString()
        {
            //NOTE Should probably investigate if Deleting a Default Constraint is different from deleting a 'regular' constraint

            return(string.Format(SqlSyntax.DeleteConstraint,
                                 SqlSyntax.GetQuotedTableName(TableName),
                                 SqlSyntax.GetQuotedName(ConstraintName)));
        }
 protected override string GetSql() =>
 HasDefaultConstraint
         ? string.Format(
     SqlSyntax.DeleteDefaultConstraint,
     SqlSyntax.GetQuotedTableName(TableName),
     SqlSyntax.GetQuotedColumnName(ColumnName),
     SqlSyntax.GetQuotedName(ConstraintName))
         : string.Empty;
 protected override string GetSql()
 {
     return(DatabaseType.IsMySql()
         ? GetMySql()
         : string.Format(SqlSyntax.DeleteConstraint,
                         SqlSyntax.GetQuotedTableName(Constraint.TableName),
                         SqlSyntax.GetQuotedName(Constraint.ConstraintName)));
 }
        private string GetMySql()
        {
            // MySql naming "convention" for foreignkeys, which aren't explicitly named
            if (string.IsNullOrEmpty(ForeignKey.Name))
            {
                ForeignKey.Name = $"{ForeignKey.ForeignTable.ToLower()}_ibfk_1";
            }

            return(string.Format(SqlSyntax.DeleteConstraint,
                                 SqlSyntax.GetQuotedTableName(ForeignKey.ForeignTable),
                                 "FOREIGN KEY",
                                 SqlSyntax.GetQuotedName(ForeignKey.Name)));
        }
Beispiel #9
0
        protected override string GetSql()
        {
            if (ForeignKey.ForeignTable == null)
            {
                throw new ArgumentNullException("Table name not specified, ensure you have appended the OnTable extension. Format should be Delete.ForeignKey(KeyName).OnTable(TableName)");
            }

            if (string.IsNullOrEmpty(ForeignKey.Name))
            {
                ForeignKey.Name = $"FK_{ForeignKey.ForeignTable}_{ForeignKey.PrimaryTable}_{ForeignKey.PrimaryColumns.First()}";
            }

            return(string.Format(SqlSyntax.DeleteConstraint,
                                 SqlSyntax.GetQuotedTableName(ForeignKey.ForeignTable),
                                 SqlSyntax.GetQuotedName(ForeignKey.Name)));
        }
Beispiel #10
0
 protected override string GetSql()
 {
     return(string.Format(SqlSyntax.DropIndex,
                          SqlSyntax.GetQuotedName(Index.Name),
                          SqlSyntax.GetQuotedTableName(Index.TableName)));
 }
 protected override string GetSql()
 {
     return(string.Format(SqlSyntax.DeleteConstraint,
                          SqlSyntax.GetQuotedTableName(Constraint.TableName),
                          SqlSyntax.GetQuotedName(Constraint.ConstraintName)));
 }
Beispiel #12
0
 public override string ToString()
 {
     return(string.Format(SqlSyntax.DropIndex,
                          SqlSyntax.GetQuotedName(Index.Name),
                          SqlSyntax.GetQuotedTableName(Index.TableName)));
 }