Esempio n. 1
0
    protected override IEnumerable <Command> OnAlter(IMetadata sourceMetadata, IMetadata targetMetadata, IComparerContext context)
    {
        var otherTrigger = FindOtherChecked(targetMetadata.MetadataTriggers.TriggersByName, TriggerName, "trigger");

        if ((TriggerClass != otherTrigger.TriggerClass) ||
            (TriggerClass == TriggerClassType.DB && TriggerType != otherTrigger.TriggerType) ||
            (TriggerClass == TriggerClassType.DDL && TriggerType != otherTrigger.TriggerType))
        {
            throw new NotSupportedOnFirebirdException($"Altering DB and DDL trigger type is not supported ({TriggerName}).");
        }
        else if (SqlSecurity == null && otherTrigger.SqlSecurity != null)
        {
            yield return(new Command().Append($"ALTER TRIGGER {TriggerName.AsSqlIndentifier()} DROP SQL SECURITY"));
        }
        else if (SqlSecurity != null && otherTrigger.SqlSecurity != null && SqlSecurity != otherTrigger.SqlSecurity)
        {
            yield return(new Command().Append($"ALTER TRIGGER {TriggerName.AsSqlIndentifier()} SQL SECURITY {SqlHelper.SqlSecurityString(SqlSecurity)}"));
        }
        else
        {
            foreach (var item in OnCreate(sourceMetadata, targetMetadata, context))
            {
                yield return(item);
            }
        }
    }
Esempio n. 2
0
    protected override IEnumerable <Command> OnCreate(IMetadata sourceMetadata, IMetadata targetMetadata, IComparerContext context)
    {
        var command = SqlHelper.IsValidExternalEngine(this) ? new Command() : new PSqlCommand();

        command
        .Append($"CREATE OR ALTER TRIGGER {TriggerName.AsSqlIndentifier()}")
        .AppendLine()
        .Append($"{(Inactive ? "INACTIVE" : "ACTIVE")} ");
        switch (TriggerClass)
        {
        case TriggerClassType.DML:
        case TriggerClassType.DDL:
            command.Append($"{TriggerBeforeAfter.ToDescription()} {TriggerEvents[0].ToDescription()} ");
            foreach (var item in TriggerEvents.Skip(1))
            {
                command.Append($"OR {item.ToDescription()} ");
            }
            break;

        case TriggerClassType.DB:
            command.Append($"ON {TriggerEvents[0].ToDescription()} ");
            break;
        }
        command
        .Append($"POSITION {TriggerSequence}")
        .AppendLine();
        if (TriggerClass == TriggerClassType.DML)
        {
            command
            .Append($"ON {RelationName.AsSqlIndentifier()}")
            .AppendLine();
        }
        if (SqlHelper.IsValidExternalEngine(this))
        {
            command.Append($"EXTERNAL NAME '{SqlHelper.DoubleSingleQuotes(EntryPoint)}'");
            command.AppendLine();
            command.Append($"ENGINE {EngineName.AsSqlIndentifier()}");
        }
        else
        {
            if (SqlSecurity != null)
            {
                command.Append($"SQL SECURITY {SqlHelper.SqlSecurityString(SqlSecurity)}");
                command.AppendLine();
            }
            command.Append(TriggerSource);
        }
        yield return(command);
    }
Esempio n. 3
0
        protected override IEnumerable <Command> OnCreate(IMetadata sourceMetadata, IMetadata targetMetadata, IComparerContext context)
        {
            var command = new PSqlCommand();

            command
            .Append($"CREATE OR ALTER TRIGGER {TriggerName.AsSqlIndentifier()}")
            .AppendLine()
            .Append($"{(Inactive ? "INACTIVE" : "ACTIVE")} ");

            if (TriggerClass == TriggerClassType.DB)
            {
                command.Append($"ON {TriggerAction1.ToDescription()} ");
            }
            else if (TriggerClass == TriggerClassType.DML)
            {
                var beforeOrAfter = TriggerAction1.In(new[] { TriggerActionType.BEFORE_INSERT, TriggerActionType.BEFORE_UPDATE, TriggerActionType.BEFORE_DELETE }) ? "BEFORE" : "AFTER";
                command.Append($"{beforeOrAfter} {TriggerAction1.ToDescription()} ");
                if (TriggerAction2 != null)
                {
                    command.Append($"OR {TriggerAction2.ToDescription()} ");
                }
                if (TriggerAction3 != null)
                {
                    command.Append($"OR {TriggerAction3.ToDescription()} ");
                }
            }
            else
            {
                throw new ArgumentOutOfRangeException($"Unknown trigger class {TriggerClass}.");
            }

            command
            .Append($"POSITION {TriggerSequence}")
            .AppendLine();

            if (TriggerClass == TriggerClassType.DML)
            {
                command
                .Append($"ON {RelationName.AsSqlIndentifier()}")
                .AppendLine();
            }

            command.Append(TriggerSource);
            yield return(command);
        }
Esempio n. 4
0
 protected override IEnumerable <Command> OnDrop(IMetadata sourceMetadata, IMetadata targetMetadata, IComparerContext context)
 {
     yield return(new Command()
                  .Append($"DROP TRIGGER {TriggerName.AsSqlIndentifier()}"));
 }