示例#1
0
        public void TestDrop()
        {
            Parser.Parse("CREATE TABLE Employees (Name TEXT, Age INT);");
            MiniSQLQuery q1 = Parser.Parse("DROP TABLE Employees;");

            Assert.IsInstanceOfType(q1, typeof(DropTable));
        }
示例#2
0
        public void TestDelete_Error()
        {
            Parser.Parse("CREATE TABLE Employees_Personal (Name TEXT, Age INT);");
            MiniSQLQuery q1 = Parser.Parse("SELECT * FROM Employees_Personal WHERE Age=5;");

            Assert.IsNotInstanceOfType(q1, typeof(DeleteTuple));
        }
示例#3
0
        public void TestUpdate_Error()
        {
            Parser.Parse("CREATE TABLE Employees_Personal (Name TEXT, Age INT);");
            MiniSQLQuery q1 = Parser.Parse("SELECT * FROM Name;");

            Assert.IsNotInstanceOfType(q1, typeof(Update));
        }
示例#4
0
        public void TestGrant_Error()
        {
            Parser.Parse("CREATE SECURITY PROFILE Employee;");
            MiniSQLQuery q1 = Parser.Parse("DROP TABLE Employees;");

            Assert.IsNotInstanceOfType(q1, typeof(Grant));
        }
示例#5
0
        public void TestSelect()
        {
            Parser.Parse("CREATE TABLE Employees_Personal (Name TEXT, Age INT);");
            MiniSQLQuery q1 = Parser.Parse("SELECT Name, Age FROM Employees_Personal WHERE Age>17;");

            Assert.IsInstanceOfType(q1, typeof(Select));
        }
示例#6
0
        public void TestDrop_Error()
        {
            Parser.Parse("CREATE TABLE Employees (Name TEXT, Age INT);");
            MiniSQLQuery q1 = Parser.Parse("SELECT * FROM Employees;");

            Assert.IsNotInstanceOfType(q1, typeof(DropTable));
        }
示例#7
0
        public void TestUpdate()
        {
            Parser.Parse("CREATE TABLE Employees_Personal (Name TEXT, Age INT);");
            MiniSQLQuery q1 = Parser.Parse("UPDATE Employees_Personal SET Name='Ana' WHERE Age=15;");

            Assert.IsInstanceOfType(q1, typeof(Update));
        }
示例#8
0
        public void TestSelectAllWithOutC()
        {
            Parser.Parse("CREATE TABLE Employees_Personal (Name TEXT, Age INT);");
            MiniSQLQuery q1 = Parser.Parse("SELECT * FROM Employees_Personal;");

            Assert.IsInstanceOfType(q1, typeof(SelectAllWithOutC));
        }
示例#9
0
        public void DropTable()
        {
            MiniSQLQuery query     = MiniSQLParser.Parse("DROP TABLE Person;");
            DropTable    dropQuery = query as DropTable;

            Assert.AreEqual("Person", dropQuery.table);
        }
示例#10
0
        public void TestInsert()
        {
            Parser.Parse("CREATE TABLE Employees_Personal (Name TEXT, Age INT);");
            MiniSQLQuery q1 = Parser.Parse("INSERT INTO Employees_Personal VALUES ('Eva',5);");

            Assert.IsInstanceOfType(q1, typeof(Insert));
        }
示例#11
0
        public void TestDropSecurityProfile_Error()
        {
            Parser.Parse("CREATE SECURITY PROFILE Employee;");
            MiniSQLQuery q1 = Parser.Parse("SELECT * FROM Employee;");

            Assert.IsNotInstanceOfType(q1, typeof(DropSecurityProfile));
        }
示例#12
0
        public void TestGrant()
        {
            Parser.Parse("CREATE SECURITY PROFILE Employee;");
            MiniSQLQuery q1 = Parser.Parse("GRANT UPDATE ON Employees_Public TO Employee;");

            Assert.IsInstanceOfType(q1, typeof(Grant));
        }
示例#13
0
        public void TestDropSecurityProfile()
        {
            Parser.Parse("CREATE SECURITY PROFILE Employee;");
            MiniSQLQuery q1 = Parser.Parse("DROP SECURITY PROFILE Employee;");

            Assert.IsInstanceOfType(q1, typeof(DropSecurityProfile));
        }
示例#14
0
        public void TestDelete()
        {
            Parser.Parse("CREATE TABLE Employees_Personal (Name TEXT, Age INT);");
            MiniSQLQuery q1 = Parser.Parse("DELETE FROM Employees_Personal WHERE Age=18;");

            Assert.IsInstanceOfType(q1, typeof(DeleteTuple));
        }
示例#15
0
        public void Delete()
        {
            MiniSQLQuery query       = MiniSQLParser.Parse("DELETE FROM Person WHERE Age=20;");
            Delete       deleteQuery = query as Delete;

            Assert.AreEqual("Age=20", deleteQuery.Condition);
            Assert.AreEqual("Person", deleteQuery.Table);
        }
示例#16
0
        public void TestRevoke_Error()
        {
            Parser.Parse("CREATE SECURITY PROFILE Employee;");
            Parser.Parse("GRANT UPDATE ON Employees_Public TO Employee;");
            MiniSQLQuery q1 = Parser.Parse("GRANT UPDATE ON Employees_Public TO Employee;");

            Assert.IsNotInstanceOfType(q1, typeof(Revoke));
        }
示例#17
0
        public void TestAddUser()
        {
            Database db = new Database("bd1", "user", "password");

            Parser.Parse("CREATE SECURITY PROFILE Employee;");
            MiniSQLQuery q1 = Parser.Parse("ADD USER ('Eva','1234',Employee);");

            Assert.IsInstanceOfType(q1, typeof(AddUser));
        }
示例#18
0
        public void TestAddUser_Error()
        {
            Database db = new Database("bd1", "user", "password");

            Parser.Parse("CREATE SECURITY PROFILE Employee;");
            MiniSQLQuery q1 = Parser.Parse("DELETE USER Eva;");

            Assert.IsNotInstanceOfType(q1, typeof(AddUser));
        }
示例#19
0
        public void Select()
        {
            MiniSQLQuery query       = MiniSQLParser.Parse("SELECT Name, Age, Height FROM People;");
            Select       selectQuery = query as Select;

            Assert.IsTrue(selectQuery.Columns.Contains("Name"));
            Assert.IsTrue(selectQuery.Columns.Contains("Age"));
            Assert.IsTrue(selectQuery.Columns.Contains("Height"));
            Assert.AreEqual("People", selectQuery.Table);
        }
示例#20
0
        public void Insert()
        {
            MiniSQLQuery query       = MiniSQLParser.Parse("INSERT INTO Person VALUES (Unai, Foncea, 22);");
            Insert       insertQuery = query as Insert;

            Assert.IsTrue(insertQuery.Columns.Contains("Unai"));
            Assert.IsTrue(insertQuery.Columns.Contains("Foncea"));
            Assert.IsTrue(insertQuery.Columns.Contains("22"));
            Assert.AreEqual("Person", insertQuery.Table);
        }
示例#21
0
        public void Update()
        {
            MiniSQLQuery query       = MiniSQLParser.Parse("UPDATE Person SET Age=22 WHERE Year=1998;");
            Update       updateQuery = query as Update;

            Assert.AreEqual("Person", updateQuery.Table);
            Assert.AreEqual("22", updateQuery.UpdateValue);
            Assert.AreEqual("Age", updateQuery.TargetColumn);
            Assert.AreEqual("Year=1998", updateQuery.Condition);
        }
示例#22
0
        public void CreateTable()
        {
            MiniSQLQuery query       = MiniSQLParser.Parse("CREATE TABLE MyTable (name1 TEXT, name2 INT);");
            CreateTable  createQuery = query as CreateTable;

            Assert.AreEqual("MyTable", createQuery.Table);
            Assert.IsTrue(createQuery.Columns.Contains("name1"));
            Assert.IsTrue(createQuery.Columns.Contains("name2"));
            Assert.IsTrue(createQuery.Types.Contains("TEXT"));
            Assert.IsTrue(createQuery.Types.Contains("INT"));
        }
示例#23
0
        public string ExecuteMiniSQLQuery(string query)
        {
            MiniSQLQuery miniSQLQuery = MiniSQLParser.Parse(query);

            if (miniSQLQuery == null)
            {
                return("Error");
            }

            return(miniSQLQuery.Execute(this));
        }
示例#24
0
        //Method: Load any database
        public Database Load(String BDname)
        {
            //conexion abrir
            //string path = "../Debug/MyDB_CODIGO/" + BDname + ".txt";
            string path = @"./MyDB/" + this.Name + ".txt";

            if (File.Exists(path) == true)
            {
                string[] lines = System.IO.File.ReadAllLines(path);
                foreach (string line in lines)
                {
                    MiniSQLQuery miniSQLQuery = Parser.Parse(line);
                    miniSQLQuery.Execute(this);
                    MiniSQLTester.database = this;
                }
            }
            return(this);
        }
示例#25
0
        public string ExecuteMiniSQLQuery(string query, Boolean logOk)
        {
            //Parse the query
            if (logOk == false)
            {
                return(Query.SecurityIncorrectLogin);
            }
            else
            {
                MiniSQLQuery miniSQLQuery = Parser.Parse(query);

                if (miniSQLQuery == null)
                {
                    return("ErrorDatabase");
                }

                string result = miniSQLQuery.Execute(this);

                //Save(Name);
                return(result);
            }
        }
示例#26
0
文件: Program.cs 项目: GrupoJVNM/JVNM
        static void Main()
        {
            TcpListener server = null;

            try
            {
                // Set the TcpListener on port 12000.
                Int32     port      = 1200;
                IPAddress localAddr = IPAddress.Parse("127.0.0.1");

                // TcpListener server = new TcpListener(port);
                server = new TcpListener(localAddr, port);

                // Start listening for client requests.
                server.Start();

                // Buffer for reading data
                Byte[] bytes = new Byte[256];
                String data  = null;
                byte[] msg   = null;

                Boolean login = false;

                // Enter the listening loop.
                while (true)
                {
                    Console.Write("Waiting for a connection... ");

                    // Perform a blocking call to accept requests.
                    // You could also use server.AcceptSocket() here.
                    TcpClient client = server.AcceptTcpClient();
                    Console.WriteLine("Connected!");

                    data = null;

                    // Get a stream object for reading and writing
                    NetworkStream stream = client.GetStream();

                    int           i;
                    List <string> v = new List <string>();
                    // Loop to receive all the data sent by the client.
                    try
                    {
                        while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
                        {
                            // Translate data bytes to a ASCII string.
                            data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
                            Console.WriteLine("Received: {0}", data);

                            if (login == false)
                            {
                                v = CommaSeparatedNames(data);
                                MiniSQLTester.database = new Database(v[0], v[1], v[2]);
                            }


                            try
                            {
                                MiniSQLQuery query    = Parser.Parse(data);
                                string       sentence = query.Execute(MiniSQLTester.database);

                                if (sentence.Equals(Query.SecurityUserDoesNotExist) || sentence.Equals(Query.SecurityIncorrectLogin))
                                {
                                    //ENVIAR A LA CONSOLA
                                    msg = System.Text.Encoding.ASCII.GetBytes(sentence);
                                    stream.Write(msg, 0, msg.Length);

                                    client.Close();
                                }

                                else if (sentence.Equals(Query.CreateDatabaseSuccess) || sentence.Equals(Query.OpenDatabaseSuccess))
                                {
                                    login = true;
                                    msg   = System.Text.Encoding.ASCII.GetBytes(sentence);

                                    stream.Write(msg, 0, msg.Length);
                                    Console.WriteLine("Sent: {0}", sentence);
                                }

                                else if (login == true)
                                {
                                    string        dbtxt  = @"./MyDB/" + MiniSQLTester.database.Name + ".txt";
                                    List <string> lines2 = new List <String>();

                                    if (!data.Contains("stop"))
                                    {
                                        if ((data.Contains("CREATE") || data.Contains("INSERT") || data.Contains("DELETE") || data.Contains("GRANT") || data.Contains("ADD") || data.Contains("REVOKE")) && (!sentence.Contains("ERROR")))
                                        {
                                            lines2.Add(data);
                                        }

                                        msg = System.Text.Encoding.ASCII.GetBytes(sentence);

                                        stream.Write(msg, 0, msg.Length);
                                        Console.WriteLine("Sent: {0}", sentence);

                                        File.AppendAllLines(dbtxt, lines2);
                                        lines2.Clear();
                                    }
                                }
                            }
                            catch (Exception e)
                            {
                                msg = System.Text.Encoding.ASCII.GetBytes(Query.WrongSyntax);
                                stream.Write(msg, 0, msg.Length);
                                Console.WriteLine(msg);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Se ha cerrado la sesión");
                        Thread.Sleep(4000);
                        client.Close();
                    }
                }
            }
            catch (SocketException e)
            {
                Console.WriteLine("SocketException: {0}", e);
                Thread.Sleep(10000);
            }
            finally
            {
                Thread.Sleep(10000);
                // Stop listening for new clients.
                server.Stop();
            }
        }
示例#27
0
        public void TestCreateSecurity()
        {
            MiniSQLQuery q1 = Parser.Parse("CREATE SECURITY PROFILE Employee;");

            Assert.IsInstanceOfType(q1, typeof(CreateSecurityProfile));
        }
示例#28
0
        public void TestCreateTable()
        {
            MiniSQLQuery q1 = Parser.Parse("CREATE TABLE Employees (Name TEXT, Age INT);");

            Assert.IsInstanceOfType(q1, typeof(CreateTable));
        }
示例#29
0
        public void TestCreateSecurity_Error()
        {
            MiniSQLQuery q1 = Parser.Parse("DROP TABLE Employees;");

            Assert.IsNotInstanceOfType(q1, typeof(CreateSecurityProfile));
        }