public void InsertContent(string command, string dbName) { var tableName = DbApiHelper.GetName(command); DbApiHelper.OpenDbForAction(_сontentFolder, dbName, database => { return(DbApiHelper.OpenTableForAction(database, tableName, table => { var metaInfoNodes = table.Descendants(_columnInfoTagName) .First() .Elements() .Select(x => new { x.Name, x.Value }).ToArray(); var insertingLines = DbApiHelper.GetValues(command); foreach (var line in insertingLines) { var newRecord = new XElement(AnyRecordName, line.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries) .Select((value, i) => new XAttribute(metaInfoNodes[i].Name, value))); table.Descendants(_columnContentTagName).First().Add(newRecord); } return null; })); }); }
public void CreateTable(string command, string dbName) { var tableName = DbApiHelper.GetName(command); var xmlFile = new XDocument( new XDeclaration("1.0", "Unicode", "yes"), new XComment(string.Format("{0}.{1}", dbName, tableName))); var columns = DbApiHelper.ParseColumnInfo(command); var metaInfoNode = new XElement(_columnInfoTagName); metaInfoNode.AddFirst(columns.Select(c => new XElement(c.Name, c.Type))); var columnContentNode = new XElement(_columnContentTagName); var rootNode = new XElement(tableName, metaInfoNode, columnContentNode); xmlFile.AddFirst(rootNode); DbApiHelper.OpenDbForAction(_сontentFolder, dbName, database => { using (var xmlStream = database.CreateEntry(tableName).Open()) { xmlFile.Save(xmlStream); return(null); } }); }
public void DropTable(string command, string dbName) { var tableName = DbApiHelper.GetName(command); DbApiHelper.OpenDbForAction(_сontentFolder, dbName, database => { database.GetEntry(tableName).Delete(); return(null); }); }