public void TestDrop() { Parser.Parse("CREATE TABLE Employees (Name TEXT, Age INT);"); MiniSQLQuery q1 = Parser.Parse("DROP TABLE Employees;"); Assert.IsInstanceOfType(q1, typeof(DropTable)); }
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)); }
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)); }
public void TestGrant_Error() { Parser.Parse("CREATE SECURITY PROFILE Employee;"); MiniSQLQuery q1 = Parser.Parse("DROP TABLE Employees;"); Assert.IsNotInstanceOfType(q1, typeof(Grant)); }
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)); }
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)); }
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)); }
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)); }
public void DropTable() { MiniSQLQuery query = MiniSQLParser.Parse("DROP TABLE Person;"); DropTable dropQuery = query as DropTable; Assert.AreEqual("Person", dropQuery.table); }
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)); }
public void TestDropSecurityProfile_Error() { Parser.Parse("CREATE SECURITY PROFILE Employee;"); MiniSQLQuery q1 = Parser.Parse("SELECT * FROM Employee;"); Assert.IsNotInstanceOfType(q1, typeof(DropSecurityProfile)); }
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)); }
public void TestDropSecurityProfile() { Parser.Parse("CREATE SECURITY PROFILE Employee;"); MiniSQLQuery q1 = Parser.Parse("DROP SECURITY PROFILE Employee;"); Assert.IsInstanceOfType(q1, typeof(DropSecurityProfile)); }
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)); }
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); }
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)); }
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)); }
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)); }
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); }
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); }
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); }
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")); }
public string ExecuteMiniSQLQuery(string query) { MiniSQLQuery miniSQLQuery = MiniSQLParser.Parse(query); if (miniSQLQuery == null) { return("Error"); } return(miniSQLQuery.Execute(this)); }
//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); }
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); } }
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(); } }
public void TestCreateSecurity() { MiniSQLQuery q1 = Parser.Parse("CREATE SECURITY PROFILE Employee;"); Assert.IsInstanceOfType(q1, typeof(CreateSecurityProfile)); }
public void TestCreateTable() { MiniSQLQuery q1 = Parser.Parse("CREATE TABLE Employees (Name TEXT, Age INT);"); Assert.IsInstanceOfType(q1, typeof(CreateTable)); }
public void TestCreateSecurity_Error() { MiniSQLQuery q1 = Parser.Parse("DROP TABLE Employees;"); Assert.IsNotInstanceOfType(q1, typeof(CreateSecurityProfile)); }