Example #1
0
 public Request GetRequestObject(string token,Statement queryObj,IRootServerCallback callback)
 {
   m_token = token;
   string queryType = queryObj.GetStatementType().ToString();
   try
   {
     switch (queryType)
     {
       case "CREATE_DB":
       CreateDb(queryObj,callback);
         break;
       case "CREATE_TABLE":
       CreateTable(queryObj, callback);
         break;
       case "MOD_TABLE":
       ModifyTable(queryObj, callback);
         break;
       case "DELETE_DB":
       DeleteDb(queryObj, callback);
         break;
       case "DELETE_TABLE":
       DeleteTable(queryObj, callback);
         break;
       case "EMPTY_TABLE":
       EmptyTable(queryObj, callback);
         break;
       case "INSERT_ROW":
       InsertRow(queryObj, callback);
         break;
       case "SELECT_ROW":
       SelectRow(queryObj, callback);
         break;
       case "UPDATE_ROW":
       UpdateRow(queryObj, callback);
         break;
       case "DELETE_ROWS":
       DeleteRows(queryObj, callback);
         break;
       case "SELECT_DB":
       SelectDb(queryObj, callback);
         break;
       case "RENAME_TABLE":
       RenameTable(queryObj, callback);
         break;
       case "RENAME_COLUMN":
       RenameColumn(queryObj, callback);
         break;
       default :
         Console.WriteLine("None of the query type matched");
         break;
     }
   }
   catch (Exception ex)
   {
     Console.WriteLine("Query Processor:" + ex.Message);
   }
   return m_Request;
 }
Example #2
0
 public RootServer()
 {
   m_ClientMap = new ClientMap();
   m_QParser = new QParser();
   m_Statement = new Statement();
   m_RequestQueue = new RequestQueue();
   m_RequestHandler = new RequestHandler(m_RequestQueue);
   m_RequestHandler.startRequestHandler();
   
 }
Example #3
0
 public void SelectDb(Statement queryObj, IRootServerCallback callback)
 {
   SelectDB selectdb = (SelectDB)queryObj;
   
   m_Request = new Request();
   m_Parameters = new Object[1];
   m_Parameters[0] = selectdb.GetDatabaseName();
   
   m_Request.SetCallingMethod("SelectDatabase");
   m_Request.SetRequestType(RequestType.EXECUTE_QUERY);
   m_Request.SetRootServerCallback(callback);
   m_Request.SetMethodParameters(m_Parameters);
   
 }
Example #4
0
    public void DeleteRows(Statement queryObj, IRootServerCallback callback)
    {
      DeleteRows deleteRows = (DeleteRows)queryObj;
      List<TernaryAssociative<string, string, string>> whereList = new List<TernaryAssociative<string, string, string>>();
      
      m_Request = new Request();
      m_Parameters = new Object[3];
      m_Parameters[0] = GetDatabaseName(m_token);
      m_Parameters[1] = deleteRows.GetTableName();

      if (deleteRows.GetWhereListFlag() == true)
      {
        List<WhereEntry> whereEntries = deleteRows.GetWhereList().GetSubWhereList().GetWhereEntryList();
        foreach (WhereEntry whereEntry in whereEntries)
        {
          TernaryAssociative<string, string, string> item = new TernaryAssociative<string, string, string>();
          item.First = whereEntry.GetColumnName();
          item.Second = whereEntry.GetComparisonOperatorType().ToString();

          if (whereEntry.GetColumnValue().GetColumnValueType() == ColValueType.STRING)
          {
            item.Third = whereEntry.GetColumnValue().GetStringColumnValue();
          }
          else if (whereEntry.GetColumnValue().GetColumnValueType() == ColValueType.INTEGER)
          {
            item.Third = whereEntry.GetColumnValue().GetIntColumnValue().ToString();
          }
          else if (whereEntry.GetColumnValue().GetColumnValueType() == ColValueType.DOUBLE)
          {
            item.Third = whereEntry.GetColumnValue().GetDoubleColumnValue().ToString();
          }
          whereList.Add(item);
        }
      }
      m_Parameters[2] = whereList;
      
      m_Request.SetCallingMethod("DeleteRow");
      m_Request.SetRequestType(RequestType.EXECUTE_QUERY);
      m_Request.SetRootServerCallback(callback);
      m_Request.SetMethodParameters(m_Parameters);
    }
Example #5
0
    public void SelectRow(Statement queryObj, IRootServerCallback callback)
    {
      SelectRows selectRows = (SelectRows)queryObj;
      List<TernaryAssociative<string, string, string>> whereList = new List<TernaryAssociative<string, string, string>>();
      List<KeyValuePair<string, string>> orderByColumns = new List<KeyValuePair<string, string>>();

      m_Request = new Request();
      m_Parameters = new Object[8];
      m_Parameters[0] = GetDatabaseName(m_token);
      m_Parameters[1] = selectRows.GetTableName();
      if(selectRows.GetSelectRowTableColList().GetSelectRowColumnType() == SelectRowColumnType.ALL_COLUMNS)
      {
        m_Parameters[2] = new List<string>();
        m_Parameters[3] = "";
      }
      else if (selectRows.GetSelectRowTableColList().GetSelectRowColumnType() == SelectRowColumnType.SPECIFIC_COLUMNS)
      {
        m_Parameters[2] = selectRows.GetSelectRowTableColList().GetTableColumnList().GetList();
        m_Parameters[3] = "";
      }
      else if (selectRows.GetSelectRowTableColList().GetSelectRowColumnType() == SelectRowColumnType.COUNT_ROWS)
      {
        m_Parameters[2] = new List<string>();
        if(selectRows.GetSelectRowTableColList().GetCountRows().GetCountAllRowsFlag() == true)
          m_Parameters[3] = "*";
        else
          m_Parameters[3] = selectRows.GetSelectRowTableColList().GetCountRows().GetColumnName();
      }
      if (selectRows.GetWhereListFlag() == true)
      {
        List<WhereEntry> whereEntries = selectRows.GetWhereList().GetSubWhereList().GetWhereEntryList();
        foreach (WhereEntry whereEntry in whereEntries)
        {
          TernaryAssociative<string, string, string> item = new TernaryAssociative<string, string, string>();
          item.First = whereEntry.GetColumnName();
          item.Second = whereEntry.GetComparisonOperatorType().ToString();

          if (whereEntry.GetColumnValue().GetColumnValueType() == ColValueType.STRING)
          {
            item.Third = whereEntry.GetColumnValue().GetStringColumnValue();
          }
          else if (whereEntry.GetColumnValue().GetColumnValueType() == ColValueType.INTEGER)
          {
            item.Third = whereEntry.GetColumnValue().GetIntColumnValue().ToString();
          }
          else if (whereEntry.GetColumnValue().GetColumnValueType() == ColValueType.DOUBLE)
          {
            item.Third = whereEntry.GetColumnValue().GetDoubleColumnValue().ToString();
          }
          whereList.Add(item);    
        }
      }
      m_Parameters[4] = whereList;
      if (selectRows.GetOrderByFlag() == true)
      {
        List<OrderByEntry> orderByEntries = selectRows.GetOrderByList().GetSubOrderBylist().GetOrderByEntryList();
        foreach (OrderByEntry orderByEntry in orderByEntries)
        {
          KeyValuePair<string, string> item = new KeyValuePair<string, string>(orderByEntry.GetColumnName(),orderByEntry.GetOrderByType());
          orderByColumns.Add(item);
        }
      }
      m_Parameters[5] = orderByColumns;
      if (selectRows.GetLimitRangeFlag() == true)
      {
        m_Parameters[6] = selectRows.GetLimitRange().GetStartIndex();
        m_Parameters[7] = selectRows.GetLimitRange().GetCount();
      }
      else
      {
        m_Parameters[6] = -1;
        m_Parameters[7] = -1;
      }
      
      m_Request.SetCallingMethod("SelectRow");
      m_Request.SetRequestType(RequestType.EXECUTE_QUERY);
      m_Request.SetRootServerCallback(callback);
      m_Request.SetMethodParameters(m_Parameters);
      
    }
Example #6
0
    public void InsertRow(Statement queryObj, IRootServerCallback callback)
    {
      
      InsertRow insertObj = (InsertRow)queryObj;
      List<string> ColumnList = new List<string>();
      ArrayList ColumnValueList = new ArrayList();
  
      foreach (ColumnValue val in insertObj.GetValueList())
      {
        if (val.GetColumnValueType() == ColValueType.STRING)
        {
          ColumnValueList.Add(val.GetStringColumnValue());
        }
        else if (val.GetColumnValueType() == ColValueType.INTEGER)
        {
          ColumnValueList.Add(val.GetIntColumnValue());
        }
        else if (val.GetColumnValueType() == ColValueType.DOUBLE)
        {
          ColumnValueList.Add(val.GetDoubleColumnValue());
        }
      }
      
      m_Request = new Request();
      m_Parameters = new Object[4];
      m_Parameters[0] = GetDatabaseName(m_token);
      m_Parameters[1] = insertObj.GetTableName();
      m_Parameters[2] = insertObj.GetList();
      m_Parameters[3] = ColumnValueList;

      m_Request.SetCallingMethod("InsertRow");
      m_Request.SetRequestType(RequestType.EXECUTE_QUERY);
      m_Request.SetRootServerCallback(callback);
      m_Request.SetMethodParameters(m_Parameters);

    }
Example #7
0
    public void RenameColumn(Statement queryObj, IRootServerCallback callback)
    {
      m_Request = new Request();
      m_Parameters = new Object[4];
      m_Parameters[0] = GetDatabaseName(m_token);
      m_Parameters[1] = ((RenameColumn)queryObj).GetTableName();
      m_Parameters[2] = ((RenameColumn)queryObj).GetOldColumnName();
      m_Parameters[3] = ((RenameColumn)queryObj).GetNewColumnName();

      m_Request.SetCallingMethod("RenameColumn");
      m_Request.SetRequestType(RequestType.EXECUTE_QUERY);
      m_Request.SetRootServerCallback(callback);
      m_Request.SetMethodParameters(m_Parameters);

    }
Example #8
0
    public void EmptyTable(Statement queryObj, IRootServerCallback callback)
    {
      m_Request = new Request();
      m_Parameters = new Object[2];
      m_Parameters[0] = GetDatabaseName(m_token);
      m_Parameters[1] = ((EmptyTable)queryObj).GetTableName();

      m_Request.SetCallingMethod("EmptyTable");
      m_Request.SetRequestType(RequestType.EXECUTE_QUERY);
      m_Request.SetRootServerCallback(callback);
      m_Request.SetMethodParameters(m_Parameters);
    }
Example #9
0
 public void DeleteDb(Statement queryObj,IRootServerCallback callback)
 {
   m_Request = new Request();
   m_Parameters = new Object[1];
   m_Parameters[0] = ((DeleteDB)queryObj).GetDatabaseName();
   
   m_Request.SetCallingMethod("DeleteDatabase");
   m_Request.SetRequestType(RequestType.EXECUTE_QUERY);
   m_Request.SetRootServerCallback(callback);
   m_Request.SetMethodParameters(m_Parameters);
 }
Example #10
0
    public void ModifyTable(Statement queryObj,IRootServerCallback callback)
    {
        m_Request = new Request();
               
        ModifyTab obj = (ModifyTab)queryObj;

        if (obj.GetTyp() == "ADD")
        {
          AddColumn columnData = obj.GetAddColumnData();
          m_Parameters = new Object[5];
          m_Parameters[0] = GetDatabaseName(m_token);
          m_Parameters[1] = columnData.GetTableName();
               
          if (columnData.GetColumnData().GetUniqueKey() == null)
            m_Parameters[2] = false;
          else
            m_Parameters[2] = true;
          
          m_Parameters[3] = columnData.GetColumnData().GetColumnName();

          if (columnData.GetColumnData().GetVarType() == "VARCHAR")
            m_Parameters[4] = "VARCHAR" + "(" + columnData.GetColumnData().GetVarRange() + ")";
          else
            m_Parameters[4] = columnData.GetColumnData().GetVarType();
          m_Request.SetCallingMethod("AddColumn");
        }
        else
        {
          DeleteColumn columnData = obj.GetDelcolumnData();
          m_Parameters = new Object[3];
          m_Parameters[0] = GetDatabaseName(m_token);
          m_Parameters[1] = columnData.GetTableName();
          m_Parameters[2] = columnData.GetColumnData();
          m_Request.SetCallingMethod("DeleteColumn");
        }

        m_Request.SetRequestType(RequestType.EXECUTE_QUERY);
        m_Request.SetRootServerCallback(callback);
        m_Request.SetMethodParameters(m_Parameters);
    }
Example #11
0
    private void CreateTable(Statement queryObj, IRootServerCallback callback)
    {
      List<TableColumn> columnList = new List<TableColumn>();
      Dictionary<string, bool> columnData = new Dictionary<string, bool>();
      List<bool> uniqueKey = new List<bool>();
      List<string> columnName = new List<string>();
      List<string> columnType = new List<string>();
      string tableName = ((CreateTable)queryObj).GetTableName();
      columnList = ((CreateTable)queryObj).GetList();
      foreach(TableColumn column in columnList)
      {
        if((column.GetUniqueKey() == "PRIMARY KEY" ||(column.GetUniqueKey() == "primary key") || (column.GetUniqueKey() =="INDEX") || (column.GetUniqueKey() =="index")))
        {
          columnData.Add(column.GetColumnName(), true);
        }
        else
        {
          columnData.Add(column.GetColumnName(), false);
        }
        if (column.GetVarType() == "VARCHAR")
        {
          string range = column.GetVarRange();
          columnType.Add("VARCHAR(" + range + ")");
        }
        else
        {
          columnType.Add(column.GetVarType());
        }
      }
      
      m_Request = new Request();
      m_Parameters = new Object[5];
      m_Parameters[0] = GetDatabaseName(m_token);
      m_Parameters[1] = tableName;
      m_Parameters[2] = uniqueKey;
      m_Parameters[3] = columnName;
      m_Parameters[4] = columnType;

      m_Request.SetCallingMethod("CreateTable");
      m_Request.SetRequestType(RequestType.EXECUTE_QUERY);
      m_Request.SetRootServerCallback(callback);
      m_Request.SetMethodParameters(m_Parameters);

    }
Example #12
0
 private void CreateDb(Statement queryObj, IRootServerCallback callback)
 {
   try
   {
     m_Request = new Request();
     m_Parameters = new Object[1];
   m_Parameters[0] = ((CreateDB)queryObj).GetDatabaseName(); 
   
   m_Request.SetCallingMethod("CreateDatabase");
   m_Request.SetRequestType(RequestType.EXECUTE_QUERY);
   m_Request.SetRootServerCallback(callback);
   m_Request.SetMethodParameters(m_Parameters);
   }
   catch (Exception ex)
   {
     Console.WriteLine("createdb: " + ex.Message);
   }
 }
Example #13
0
 private bool validateQuerySyntax(string query, out QueryResult qr)
 {
   qr = null;
   try
   {
     if (query != "")
     {
       m_Statement = m_QParser.ValidateQuery(query);
       return true;
     }
     else
     {
       qr = new QueryResult(-1, "Error parsing the query.");
       return false;
     }
   }
   catch (QueryParserException qpe)
   {
     qr = new QueryResult(-1, qpe.Message);
     return false;
   }
   catch (Exception ex)
   {
     qr = new QueryResult(-1, ex.Message);
     return false;
   }
 }