public void ExecuteQuery() { if (Q.Q == 'C') { //Check if database name already exist //If not create the database //database names should not contain illgel chars as space,@ if (!CheckDataBaseExists(Q.DBName)) { //create a new dbname.xml file String[] es = new String[] { "db_name", "db_table", "db_recods_sectors" }; String[] evs = new String[] { Q.DBName, "0", "0" }; MemoryOps.CreateNodeWithElements(filepath, "db_" + Q.DBName, es, evs); Res.setResultBool(true); Res.setResultSuccessText("Database " + Q.DBName + " has been created successfully.."); } Res.setResultBool(false); Res.setResultErrorID(1); Res.setResultErrorText("Error: " + Q.DBName + " already exists.."); } if (Q.Q == 'R') { //Check if database exists //Check the password is correct** if (CheckDataBaseExists(Q.DBName)) { // MemoryOps.DeleteNode(filepath, "db_" +Q.DBName); MemoryOps.DeleteElement(filepath, "db_" + Q.DBName, "db_name"); Res.setResultBool(true); Res.setResultSuccessText("Database " + Q.DBName + " has been deleted successfully.."); } } }
public void ExecuteQuery() { if (Q.Q == 'I') { //check database selected //check table if (CheckDataBaseExists(Q.DBName)) { if (CheckTableExists(Tablepath)) { //Check if cols obeys schema MemoryOps.CreateNodeWithElements(SectorOps.GetSectorDocPath(Q.Table), "RECORD", Q.Cols, Q.Data.Select(i => i.ToString()).ToArray()); Res.setResultBool(true); Res.setResultSuccessText("Done executing query.."); } else { Res.setResultBool(false); Res.setResultErrorID(2); Res.setResultErrorText("Error on executing query: Table does not exist"); } } else { Res.setResultBool(false); Res.setResultErrorID(3); Res.setResultErrorText("Error on executing query: Database does not exist"); } } }
private bool CheckDataBaseExists(String DBName) { XmlNodeList DBS_LIST = MemoryOps.SelectNode(filepath, "db_" + DBName); //select database lists if (DBS_LIST.Count == 0) { return(false); } return(true); }
public static String GetSectorDocPath(String TableName) { int[] SectorInfo = Main.GetContents(Path.Combine(DirectoryOps.MainPath, DirectoryOps.Dirs[3], "dbsx_" + TableName + "si.sector")); String finalpath = Path.Combine(new String [] { DirectoryOps.MainPath, DirectoryOps.Dirs[2], "db_" + TableName, "sec_" + SectorInfo[1], SectorInfo[2].ToString() }); if (SectorInfo[2] == STAT.MIN_DOCS_IN_SECTOR) { //Go to a new sector if (SectorInfo[1] == STAT.MAX_NO_SECTORS) { SectorInfo[1] = SectorInfo[1] % STAT.MAX_NO_SECTORS; } else { //Create new Sector CreateSector(TableName); SectorInfo[1] = SectorInfo[1] + 1; } } else if (SectorInfo[2] < STAT.MIN_DOCS_IN_SECTOR) { //Check Doc free or not if (MemoryOps.GetNumberofNodes(finalpath) == STAT.MAX_NO_NODES) { //create new Doc CreateDoc(TableName); SectorInfo[2] = SectorInfo[2] + 1; } } else { //Go to a new sector SectorInfo[1] = SectorInfo[1] % STAT.MAX_NO_SECTORS; //create new doc CreateDoc(TableName); SectorInfo[2] = SectorInfo[2] + 1; } return(finalpath); }
public void ExecuteQuery() { if (Q.Q == 'T') { //Create table.xml MemoryOps.CreateStartElement(filepath, Q.Table); MemoryOps.CreateNodeWithElements(filepath, "INFO", new String[] { "db_name" }, new String[] { Q.DBName }); MemoryOps.CreateNode(filepath, "ATTRS"); for (int index = 0; index < Q.Attrs.Count; index++) { MemoryOps.CreateNodeWithElements(filepath, "ATTRS", new String[] { Q.Attrs[index].getAttrName() }, null); for (int i = 0; i < Q.Data.Length; i++) { if (Q.Data[i] != null) { MemoryOps.CreateNodeWithElements(filepath, Q.Attrs[index].getAttrName(), new String [] { Q.Data[i].getDataObjectName() }, new String[] { Q.Data[i].getDataObjectValue().ToString() }); } } } } }