Example #1
0
 public SelectColumnWhere(string table, CompareWhere c, string[] columns)
 {
     m_table       = table;
     m_compare     = c;
     m_columnNames = new List <string>();
     foreach (string cl in columns)
     {
         m_columnNames.Add(cl);
     }
 }
Example #2
0
        public Table Select(string table, List <string> selects, CompareWhere compared, User user)
        {
            Table values = null;
            List <TableColumn> select = new List <TableColumn>();
            Table t = GetTable(table);
            List <TableColumn> TableColumns = t.GetList();
            TableColumn        column;

            //we get the select list of columns
            foreach (string s in selects)
            {
                select.Add(t.GetColumn(s));
            }

            //We create the table which we will return as the select
            values = new Table("selectResult", new List <TableColumn>());

            //We see if we have any condition
            if (compared == null)
            {
                //we make an iteration for the columns
                foreach (TableColumn s in select)
                {
                    //we create a column that we will add in the return list
                    column = new TableColumn(s.GetName(), s.GetColumnType());

                    //we get each value we want
                    foreach (string value in s.GetList())
                    {
                        column.AddValue(value);
                    }
                    values.AddTableColumn(column);
                }
            }
            else
            {
                //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
                foreach (TableColumn s in select)
                {
                    //we create a column that we will add in the return list
                    column = new TableColumn(s.GetName(), s.GetColumnType());

                    //we get each value we want
                    foreach (string value in s.GetValues(valuesCompared))
                    {
                        column.AddValue(value);
                    }
                    values.AddTableColumn(column);
                }
            }
            return(values);
        }
Example #3
0
        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);
        }
Example #4
0
        public List <int> GetPositions(CompareWhere compared)
        {
            List <int> positions = new List <int>();

            if (compared.GetComparator().CompareTo("=") == 0)
            {
                for (int i = 0; i < m_data.Count; i++)
                {
                    if (compared.GetName() == m_data.ElementAt(i))
                    {
                        positions.Add(i);
                    }
                }
                ;
            }

            else if (compared.GetComparator().CompareTo("<") == 0)
            {
                for (int i = 0; i < m_data.Count; i++)
                {
                    if (compared.GetName().CompareTo(m_data.ElementAt(i)) == 1)
                    {
                        positions.Add(i);
                    }
                }
                ;
            }

            else if (compared.GetComparator().CompareTo(">") == 0)
            {
                for (int i = 0; i < m_data.Count; i++)
                {
                    if (compared.GetName().CompareTo(m_data.ElementAt(i)) == -1)
                    {
                        positions.Add(i);
                    }
                }
                ;
            }

            return(positions);
        }
Example #5
0
 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);
     }
 }
Example #6
0
 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);
     }
 }