func (tr *Transaction) Update(t *table.Table, rowNumber int, row map[string]string) int { // Execute "before update" triggers. beforeTable, status := tr.DB.Get("~before") if status != st.OK { return status } original, status := t.Read(rowNumber) if status != st.OK { return status } triggerRA := ra.New() _, status = triggerRA.Load(beforeTable) if status != st.OK { return status } _, status = triggerRA.Select("TABLE", filter.Eq{}, t.Name) if status != st.OK { return status } status = trigger.ExecuteTrigger(tr.DB, t, triggerRA, "UP", row, original) if status != st.OK { return status } // Update the row. status = t.Update(rowNumber, row) if status != st.OK { return status } // Execute "after update" triggers. afterTable, status := tr.DB.Get("~after") if status != st.OK { return status } triggerRA = ra.New() _, status = triggerRA.Load(afterTable) if status != st.OK { return status } _, status = triggerRA.Select("TABLE", filter.Eq{}, t.Name) if status != st.OK { return status } status = trigger.ExecuteTrigger(tr.DB, t, triggerRA, "UP", row, original) if status != st.OK { return status } // Log the updated row. tr.Log(&UndoUpdate{t, rowNumber, original}) return st.OK }
func (tr *Transaction) Delete(t *table.Table, rowNumber int) int { // Execute "before delete" triggers. beforeTable, status := tr.DB.Get("~before") if status != st.OK { return status } row, status := t.Read(rowNumber) if status != st.OK { return status } triggerRA := ra.New() _, status = triggerRA.Load(beforeTable) if status != st.OK { return status } _, status = triggerRA.Select("TABLE", filter.Eq{}, t.Name) if status != st.OK { return status } status = trigger.ExecuteTrigger(tr.DB, t, triggerRA, "DE", row, nil) if status != st.OK { return status } // Update the row. status = t.Delete(rowNumber) if status != st.OK { return status } // Execute "after delete" triggers. afterTable, status := tr.DB.Get("~after") if status != st.OK { return status } triggerRA = ra.New() _, status = triggerRA.Load(afterTable) if status != st.OK { return status } _, status = triggerRA.Select("TABLE", filter.Eq{}, t.Name) if status != st.OK { return status } status = trigger.ExecuteTrigger(tr.DB, t, triggerRA, "DE", row, nil) if status != st.OK { return status } // Log the deleted row. tr.Log(&UndoDelete{t, rowNumber}) return st.OK }
func (tr *Transaction) Insert(t *table.Table, row map[string]string) int { // Execute "before insert" triggers. beforeTable, status := tr.DB.Get("~before") if status != st.OK { return status } triggerRA := ra.New() _, status = triggerRA.Load(beforeTable) if status != st.OK { return status } _, status = triggerRA.Select("TABLE", filter.Eq{}, t.Name) if status != st.OK { return status } status = trigger.ExecuteTrigger(tr.DB, t, triggerRA, "IN", row, nil) if status != st.OK { return status } // Insert the new row to table. numberOfRows, status := t.NumberOfRows() if status != st.OK { return status } status = t.Insert(row) if status != st.OK { return status } // Execute "after insert" triggers. afterTable, status := tr.DB.Get("~after") if status != st.OK { return status } triggerRA = ra.New() _, status = triggerRA.Load(afterTable) if status != st.OK { return status } _, status = triggerRA.Select("TABLE", filter.Eq{}, t.Name) if status != st.OK { return status } status = trigger.ExecuteTrigger(tr.DB, t, triggerRA, "IN", row, nil) if status != st.OK { return status } // Log the inserted row. tr.Log(&UndoInsert{t, numberOfRows}) return st.OK }