public string Update(List <string> setAttribute, List <string> value, string table, CompareWhere compared, User user) { if (!(user.GetName() == "admin") || !m_security.CheckPrivilege(user, PrivilegeType.Update, table)) { return(Messages.SecurityNotSufficientPrivileges); } else { Table t = GetTable(table); if (m_tables.Contains(t)) { if (t.GetList().Contains(t.GetColumn(compared.GetColumn()))) { //we have the values where condition is true List <int> valuesCompared = t.CompareValues(compared); //we make an iteration for the columns to search those we want int count = 0; foreach (TableColumn s in t.GetList()) { foreach (string cl in setAttribute) { if (t.GetList().Contains(t.GetColumn(cl))) { //attribute we have to change if (s.GetName().CompareTo(cl) == 0) { //loop each position we gonna change foreach (int str in (valuesCompared)) { //change value in the position we are s.GetList()[str] = value[count]; } count++; } } else { return(Messages.ColumnDoesNotExist); } } } } else { return(Messages.ColumnDoesNotExist); } } else { return(Messages.TableDoesNotExist); } return(Messages.TupleUpdateSuccess); } }
public List <int> CompareValues(CompareWhere compared) { List <int> positions = null; foreach (TableColumn x in m_list) { if (x.GetName() == (compared.GetColumn())) { positions = x.GetPositions(compared); } } return(positions); }
public string Delete(string table, CompareWhere compared, User user) { if (!(user.GetName() == "admin") || !m_security.CheckPrivilege(user, PrivilegeType.Delete, table)) { return(Messages.SecurityNotSufficientPrivileges); } else { Table t = GetTable(table); if (m_tables.Contains(t)) { if (t.GetList().Contains(t.GetColumn(compared.GetColumn()))) { List <int> positions = t.CompareValues(compared); foreach (TableColumn tc in t.GetList()) { List <string> newList = new List <string>(); for (int i = 0; i < tc.GetList().Count; i++) { if (!positions.Contains(i)) { newList.Add(tc.GetList().ElementAt(i)); } } tc.SetList(newList); } } else { return(Messages.ColumnDoesNotExist); } } else { return(Messages.TableDoesNotExist); } return(Messages.TupleDeleteSuccess); } }