private TriggerInfo FormTrigger(Row row) { var schema = row.GetValue(0).Value.ToString(); var name = row.GetValue(1).Value.ToString(); var triggerName = new ObjectName(new ObjectName(schema), name); var triggerType = ((SqlNumber)row.GetValue(2).Value).ToInt32(); var tableName = ObjectName.Parse(((SqlString)row.GetValue(3).Value).ToString()); var eventTime = (TriggerEventTime)((SqlNumber)row.GetValue(4).Value).ToInt32(); var eventType = (TriggerEventType)((SqlNumber)row.GetValue(5).Value).ToInt32(); TriggerInfo triggerInfo; if (triggerType == ProcedureType) { var procNameString = row.GetValue(6).Value.ToString(); var procName = ObjectName.Parse(procNameString); var argsBinary = (SqlBinary)row.GetValue(7).Value; var args = DeserializeArguments(argsBinary.ToByteArray()); triggerInfo = new ProcedureTriggerInfo(triggerName, tableName, eventTime, eventType, procName); if (args != null && args.Length > 0) { foreach (var expression in args) { ((ProcedureTriggerInfo)triggerInfo).Arguments = args; } } } else if (triggerType == PlSqlType) { var binary = (SqlBinary)row.GetValue(8).Value; var body = binary.ToObject <PlSqlBlockStatement>(); triggerInfo = new PlSqlTriggerInfo(triggerName, tableName, eventTime, eventType, body); } else { throw new InvalidOperationException(); } triggerInfo.Status = (TriggerStatus)((SqlNumber)row.GetValue(9).Value).ToByte(); return(triggerInfo); }
private void CreateTriggers(IQuery query, ObjectName tableName) { var triggerName = ObjectName.Parse("APP.trigger1"); var eventTime = TriggerEventTime.Before; var eventType = TriggerEventType.Insert | TriggerEventType.Update; var body = new PlSqlBlockStatement(); body.Declarations.Add(new DeclareVariableStatement("a", PrimitiveTypes.Integer())); body.Statements.Add(new AssignVariableStatement(SqlExpression.VariableReference("a"), SqlExpression.Constant(33))); var triggerInfo = new PlSqlTriggerInfo(triggerName, tableName, eventTime, eventType, body); query.Access().CreateObject(triggerInfo); }
private TriggerInfo FormTrigger(Row row) { var schema = row.GetValue(0).Value.ToString(); var name = row.GetValue(1).Value.ToString(); var triggerName = new ObjectName(new ObjectName(schema), name); var triggerType = ((SqlNumber)row.GetValue(2).Value).ToInt32(); var tableName = ObjectName.Parse(((SqlString) row.GetValue(3).Value).ToString()); var eventTime = (TriggerEventTime)((SqlNumber)row.GetValue(4).Value).ToInt32(); var eventType = (TriggerEventType) ((SqlNumber) row.GetValue(5).Value).ToInt32(); TriggerInfo triggerInfo; if (triggerType == ProcedureType) { var procNameString = row.GetValue(6).Value.ToString(); var procName = ObjectName.Parse(procNameString); var argsBinary = (SqlBinary)row.GetValue(7).Value; var args = DeserializeArguments(argsBinary.ToByteArray()); triggerInfo = new ProcedureTriggerInfo(triggerName,tableName, eventTime, eventType, procName); if (args != null && args.Length > 0) { foreach (var expression in args) { ((ProcedureTriggerInfo) triggerInfo).Arguments = args; } } } else if (triggerType == PlSqlType) { var binary = (SqlBinary) row.GetValue(8).Value; var body = binary.ToObject<PlSqlBlockStatement>(); triggerInfo = new PlSqlTriggerInfo(triggerName, tableName, eventTime, eventType, body); } else { throw new InvalidOperationException(); } triggerInfo.Status = (TriggerStatus) ((SqlNumber) row.GetValue(9).Value).ToByte(); return triggerInfo; }
public PlSqlTrigger(PlSqlTriggerInfo triggerInfo) : base(triggerInfo) { }
protected override void ExecuteStatement(ExecutionContext context) { //if (!context.User.CanCreateInSchema(TriggerName.ParentName)) // throw new SecurityException(String.Format("The user '{0}' cannot create in schema '{1}'.", context.User.Name, TriggerName.ParentName)); if (!context.DirectAccess.TableExists(TableName)) throw new ObjectNotFoundException(TableName); // TODO: Discover the accessed objects in the Body and verifies the user has the rights if (context.DirectAccess.ObjectExists(DbObjectType.Trigger, TriggerName)) { if (!ReplaceIfExists) throw new StatementException(String.Format("A trigger named '{0}' already exists.", TriggerName)); context.DirectAccess.DropObject(DbObjectType.Trigger, TriggerName); } var triggerInfo = new PlSqlTriggerInfo(TriggerName, TableName, EventTime, EventType, Body); if (Status != TriggerStatus.Unknown) triggerInfo.Status = Status; context.DirectAccess.CreateObject(triggerInfo); context.DirectAccess.GrantOn(DbObjectType.Trigger, TableName, context.User.Name, PrivilegeSets.SchemaAll, true); }