// Deletes rows in a table of RA result according to some select conditions. // The RA result is made a copy before using select conditions. func findAndDelete(t *table.Table, query *ra.Result, conditions ...ra.Condition) int { _, status := query.Copy().MultipleSelect(conditions...) if status != st.OK { return status } for _, i := range query.Tables[t.Name].RowNumbers { status = t.Delete(i) if status != st.OK { return status } } return t.Flush() }
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 }