Exemple #1
0
        private static void Create(string query)
        {
            char[]   separators = new char[] { ' ', ';' };
            string[] queryList  = query.Split(separators, StringSplitOptions.RemoveEmptyEntries);

            if (queryList.Length == 2)
            {
                string databaseName = default(string);
                databaseName = queryList[1];

                if (!GetInstance().IsKeyword(databaseName))
                {
                    Kernel.AddDBInstance(databaseName);
                    Console.WriteLine($"Database was created with name '{queryList[1]}'\n");
                    Kernel.OutDatabaseInfo();
                }
                else
                {
                    Console.WriteLine($"\nERROR: Name of the database can't be a keyword\n");
                }
            }
            else
            {
                Console.WriteLine($"\nERROR: Invalid numbers of variables\n");
            }
        }
Exemple #2
0
        private static void Select(string query)
        {
            char[]   separator = new char[] { ' ' };
            string[] temp      = query.Split(separator, 2, StringSplitOptions.RemoveEmptyEntries);
            if (temp.Length == 2 && query[query.Length - 1] == ')')
            {
                char[]   s1 = new char[] { '(' };
                string[] t1 = query.Split(s1, 2, StringSplitOptions.RemoveEmptyEntries);

                char[]   s2       = new char[] { ' ' };
                string[] tempName = t1[0].Split(s2, StringSplitOptions.RemoveEmptyEntries);

                char[]   s3         = new char[] { ';', ')' };
                string[] tempParams = t1[1].Split(s3, StringSplitOptions.RemoveEmptyEntries);



                if (tempName.Length == 3)
                {
                    string dbName    = tempName[1];
                    string tableName = tempName[2];

                    for (int i = 0; i < tempParams.Length; i++)
                    {
                        string[] param = tempParams[i].Split(',');
                        if (param.Length == 6)
                        {
                            //if(SharedDataAccessMethods)
                            Kernel.AddDBInstance(dbName);
                            var inst = Kernel.GetInstance(dbName);
                            inst.AddTable(tableName);
                            int    tableIndex = Kernel.GetInstance(dbName).indexOfTable(tableName);
                            Column buff       = GetInstance().GetColumn(param);
                            inst.TablesDB[tableIndex].AddColumn(buff);
                        }
                    }
                }
                else
                {
                    Console.WriteLine("\nERROR: Invalid numbers of variables in params\n");
                }
            }
            else
            {
                Console.WriteLine($"\nERROR: Missed part of the command\n");
            }
            Kernel.OutDatabaseInfo();
        }
Exemple #3
0
 static void CreateDatabase(string dbName)
 {
     try {
         if (!Kernel.isDatabaseExists(dbName))
         {
             Kernel.AddDBInstance(dbName);
             Interpreter.ConnectionString = dbName;
             Console.WriteLine($"\nDatabase created with name '{dbName}'\n");
         }
         else
         {
             throw new Exception("\nERROR: Invalid database name. Some database have same name!\n");
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
 }