private static byte[] SerializeArguments(TriggerArgument args) { using (var stream = new MemoryStream()) { var serializer = new BinarySerializer(); serializer.Serialize(stream, args); stream.Flush(); return(stream.ToArray()); } }
public void CreateTrigger(TriggerInfo triggerInfo) { if (!transaction.TableExists(SystemSchema.TriggerTableName)) { return; } try { var args = new TriggerArgument(triggerInfo.Arguments.ToArray()); var binArgs = SerializeArguments(args); var schema = triggerInfo.TriggerName.ParentName; var name = triggerInfo.TriggerName.Name; var type = (int)triggerInfo.TriggerType; var onTable = triggerInfo.TableName == null ? null : triggerInfo.TableName.FullName; var procedureName = triggerInfo.ProcedureName != null ? triggerInfo.ProcedureName.FullName : null; var action = (int)triggerInfo.EventType; // TODO: if the trigger has a body, create a special procedure and set the name // Insert the entry into the trigger table, var table = transaction.GetMutableTable(SystemSchema.TriggerTableName); var row = table.NewRow(); row.SetValue(0, DataObject.String(schema)); row.SetValue(1, DataObject.String(name)); row.SetValue(2, DataObject.Integer(type)); row.SetValue(3, DataObject.String(onTable)); row.SetValue(4, DataObject.Integer(action)); row.SetValue(5, DataObject.String(procedureName)); row.SetValue(6, DataObject.Binary(binArgs)); table.AddRow(row); InvalidateTriggerCache(); transaction.Registry.RegisterEvent(new ObjectCreatedEvent(triggerInfo.TriggerName, DbObjectType.Trigger)); tableModified = true; } catch (Exception) { // TODO: use a specialized exception throw; } }
public void CreateTrigger(TriggerInfo triggerInfo) { if (!transaction.TableExists(TriggerTableName)) return; var schema = triggerInfo.TriggerName.ParentName; var name = triggerInfo.TriggerName.Name; var onTable = triggerInfo.TableName.FullName; var time = (int) triggerInfo.EventTime; var action = (int) triggerInfo.EventType; int type; if (triggerInfo is ProcedureTriggerInfo) { type = ProcedureType; } else if (triggerInfo is PlSqlTriggerInfo) { type = PlSqlType; } else { throw new ArgumentException("The specified trigger info is invalid."); } // Insert the entry into the trigger table, var table = transaction.GetMutableTable(TriggerTableName); var row = table.NewRow(); row.SetValue(0, Field.String(schema)); row.SetValue(1, Field.String(name)); row.SetValue(2, Field.Integer(type)); row.SetValue(3, Field.String(onTable)); row.SetValue(4, Field.Integer(time)); row.SetValue(5, Field.Integer(action)); if (type == ProcedureType) { var procInfo = (ProcedureTriggerInfo) triggerInfo; var args = new TriggerArgument(procInfo.Arguments); var binArgs = SerializeArguments(args); var procedureName = procInfo.ProcedureName.FullName; row.SetValue(6, Field.String(procedureName)); row.SetValue(7, Field.Binary(binArgs)); } else if (type == PlSqlType) { var plsqlInfo = (PlSqlTriggerInfo) triggerInfo; var body = Field.Binary(SqlBinary.ToBinary(plsqlInfo.Body)); row.SetValue(8, body); } row.SetValue(9, Field.TinyInt((byte) triggerInfo.Status)); table.AddRow(row); InvalidateTriggerCache(); transaction.OnObjectCreated(DbObjectType.Trigger, triggerInfo.TriggerName); tableModified = true; }
private static byte[] SerializeArguments(TriggerArgument args) { using (var stream = new MemoryStream()) { var serializer = new BinarySerializer(); serializer.Serialize(stream, args); stream.Flush(); return stream.ToArray(); } }
public void CreateTrigger(TriggerInfo triggerInfo) { if (!transaction.TableExists(SystemSchema.TriggerTableName)) return; try { var args = new TriggerArgument(triggerInfo.Arguments.ToArray()); var binArgs = SerializeArguments(args); var schema = triggerInfo.TriggerName.ParentName; var name = triggerInfo.TriggerName.Name; var type = (int) triggerInfo.TriggerType; var onTable = triggerInfo.TableName == null ? null : triggerInfo.TableName.FullName; var procedureName = triggerInfo.ProcedureName != null ? triggerInfo.ProcedureName.FullName : null; var action = (int) triggerInfo.EventType; // TODO: if the trigger has a body, create a special procedure and set the name // Insert the entry into the trigger table, var table = transaction.GetMutableTable(SystemSchema.TriggerTableName); var row = table.NewRow(); row.SetValue(0, DataObject.String(schema)); row.SetValue(1, DataObject.String(name)); row.SetValue(2, DataObject.Integer(type)); row.SetValue(3, DataObject.String(onTable)); row.SetValue(4, DataObject.Integer(action)); row.SetValue(5, DataObject.String(procedureName)); row.SetValue(6, DataObject.Binary(binArgs)); table.AddRow(row); InvalidateTriggerCache(); transaction.Registry.RegisterEvent(new ObjectCreatedEvent(triggerInfo.TriggerName, DbObjectType.Trigger)); tableModified = true; } catch (Exception) { // TODO: use a specialized exception throw; } }
public void CreateTrigger(TriggerInfo triggerInfo) { if (!transaction.TableExists(TriggerTableName)) { return; } var schema = triggerInfo.TriggerName.ParentName; var name = triggerInfo.TriggerName.Name; var onTable = triggerInfo.TableName.FullName; var time = (int)triggerInfo.EventTime; var action = (int)triggerInfo.EventType; int type; if (triggerInfo is ProcedureTriggerInfo) { type = ProcedureType; } else if (triggerInfo is PlSqlTriggerInfo) { type = PlSqlType; } else { throw new ArgumentException("The specified trigger info is invalid."); } // Insert the entry into the trigger table, var table = transaction.GetMutableTable(TriggerTableName); var row = table.NewRow(); row.SetValue(0, Field.String(schema)); row.SetValue(1, Field.String(name)); row.SetValue(2, Field.Integer(type)); row.SetValue(3, Field.String(onTable)); row.SetValue(4, Field.Integer(time)); row.SetValue(5, Field.Integer(action)); if (type == ProcedureType) { var procInfo = (ProcedureTriggerInfo)triggerInfo; var args = new TriggerArgument(procInfo.Arguments); var binArgs = SerializeArguments(args); var procedureName = procInfo.ProcedureName.FullName; row.SetValue(6, Field.String(procedureName)); row.SetValue(7, Field.Binary(binArgs)); } else if (type == PlSqlType) { var plsqlInfo = (PlSqlTriggerInfo)triggerInfo; var body = Field.Binary(SqlBinary.ToBinary(plsqlInfo.Body)); row.SetValue(8, body); } row.SetValue(9, Field.TinyInt((byte)triggerInfo.Status)); table.AddRow(row); InvalidateTriggerCache(); transaction.OnObjectCreated(DbObjectType.Trigger, triggerInfo.TriggerName); tableModified = true; }