//add a new column to row server public TableResponse AddColumn(string databaseName, string tableName, bool uniqueKey, string columnName, string columnType) { try { string activeDir_ = activeDir + databaseName + "\\"; string newPath = System.IO.Path.Combine(activeDir_, tableName); string pkPath = newPath + "\\" + columnName + ".dat"; string metaPath = newPath + "\\" + tableName + ".xml"; string rowPath = newPath + "\\row.dat"; // if new column is key, then generate new Pk binary file if (uniqueKey) { BinaryManager h = new BinaryManager(); h.GeneratePkFile(pkPath, columnType, 32, -1, 0); } BinaryManager.RowAddColumn(rowPath, metaPath, uniqueKey, columnName, columnType); BinaryManager.MetaAddColumn(metaPath, uniqueKey, columnName, columnType); return new TableResponse(true, "add column successfully", "add column"); } catch (Exception e) { Console.WriteLine("Error:" + e.Message.ToString()); return new TableResponse(false, "Error: add column error", "add column failed"); } }
//column key type: string : "int" , "float", "VarChar(10)"; public TableResponse CreateTable(string databaseName, string tableName, Dictionary<string, bool> columnName, List<string> columnType) { try { // Specify a "currently active folder" string activeDir_ = activeDir + databaseName + "\\"; string newPath = System.IO.Path.Combine(activeDir_, tableName); if (Directory.Exists(newPath)) { return new TableResponse(false, "Table exist already", "TableResponse"); } // Create the subfolder System.IO.Directory.CreateDirectory(newPath); //generate the corresponding PK files under the Folder Names: File Name= tableName_columnName.dat int dicIndex = 0; foreach (var i in columnName) { if (i.Value == true) { string path = newPath + "\\" + i.Key + ".dat"; BinaryManager h = new BinaryManager(); h.GeneratePkFile(path, columnType[dicIndex], 32, -1, 0); } dicIndex++; } //generate Row Table file string rowTbPath = newPath + "\\row.dat"; BinaryManager rowTbHeader = new BinaryManager(); rowTbHeader.GenerateRowFile(rowTbPath, columnType, columnName); //generate metadata XML file string metaPath = newPath + "\\" + tableName; BinaryManager.MetaGenerator(metaPath, columnType, columnName); return new TableResponse(true, "Table Created Successfully", "Table created"); } catch (Exception e) { Console.WriteLine("Error:" + e.Message.ToString()); return new TableResponse(false, "Error: Create Table error", "Table not created"); } }