public Mwb() { _table = null; _column = null; tab = Resources.Tab; nl = Resources.Nl; Columns = new List <MyColumn>(); Tables = new List <MyTable>(); Usertype = new List <MyUserDatatype>(); MyUserDatatype typ = new MyUserDatatype(); Usertype.Add(typ); typ.id = 1; typ.name = "VARCHAR"; typ.actualType = "com.mysql.rdbms.mysql.datatype.varchar"; typ.flags = ""; typ.sqlDefinition = "verchar"; Routines = new List <MyRoutine>(); Indexes = new List <MyIndex>(); tit = ""; Database = ""; }
// // ノードの再帰的処理2 // private void NodeProcess2(XElement ere, int level) { //IEnumerable<XNode> nodes = nod.Nodes(); //List<XNode> nod2 = nodes.ToList(); if (ere.HasAttributes == true) { List <XAttribute> latr = ere.Attributes().ToList(); foreach (XAttribute atr in latr) { XName nam = atr.Name; if ((nam.ToString() == "struct-name") && (atr.Value == "db.UserDatatype")) { if (ere.HasElements) { GetUserDatatype(ere.Elements().ToList()); } } else if ((nam.ToString() == "struct-name") && (atr.Value == "db.mysql.Table")) { XName id2 = XName.Get("id"); XAttribute atr2 = ere.Attribute(id2); string linkid = ""; if (atr2 != null) { linkid = atr2.Value; } if (ere.HasElements) { GetTable(ere.Elements().ToList(), linkid); } } else if ((nam.ToString() == "struct-name") && (atr.Value == "db.mysql.Column")) { _table = Tables[Tables.Count - 1]; XName id2 = XName.Get("id"); XAttribute atr2 = ere.Attribute(id2); string linkid = ""; if (atr2 != null) { linkid = atr2.Value; } if (ere.HasElements) { GetColumn(ere.Elements().ToList(), linkid); } } else if ((nam.ToString() == "struct-name") && (atr.Value == "db.mysql.Routine")) { MyRoutine rot = new MyRoutine(); Routines.Add(rot); rot.id = Routines.Count; IEnumerable <XElement> els = ere.Elements(); if (els != null) { foreach (XElement ere3 in els) { if (ere3.HasAttributes) { XAttribute atr2 = ere3.Attribute(XName.Get("key")); string val = ""; if (atr2 != null) { val = atr2.Value; } if (val == "name") { rot.name = ere3.Value; } else if (val == "sqlBody") { rot.sqlBody = ere3.Value; } } } } } else if ((nam.ToString() == "struct-name") && (atr.Value == "db.mysql.RoutineParam")) { MyRoutineParam prm = new MyRoutineParam(); MyRoutine rot = Routines[Routines.Count - 1]; if (rot != null) { rot.Params.Add(prm); prm.id = rot.Params.Count; IEnumerable <XElement> els = ere.Elements(); if (els != null) { foreach (XElement ele4 in els) { if (ele4.HasAttributes) { XAttribute atr3 = ele4.Attribute(XName.Get("key")); string val = ""; if (atr3 != null) { val = atr3.Value; } if (val == "name") { prm.name = ele4.Value; } else if (val == "datatype") { prm.datatype = ele4.Value; } else if (val == "paramType") { prm.paramType = ele4.Value; } } } } } } else if ((ere.Name == "value") && (nam.ToString() == "struct-name") && (atr.Value == "db.mysql.Index")) { MyIndex idx = new MyIndex(); Indexes.Add(idx); idx.id = Indexes.Count; IEnumerable <XElement> els = ere.Elements(); if (els != null) { foreach (XElement ele4 in els) { if (ele4.HasAttributes) { XAttribute atr3 = ele4.Attribute(XName.Get("key")); string val = ""; if (atr3 != null) { val = atr3.Value; } if (val == "name") { idx.name = ele4.Value; } else if (val == "indexKind") { idx.indexKind = ele4.Value; } else if (val == "keyBlockSize") { idx.keyBlockSize = int.Parse(ele4.Value); } else if (val == "withParser") { idx.withParser = ele4.Value; } else if (val == "deferability") { idx.deferability = int.Parse(ele4.Value); } else if (val == "comment") { idx.comment = ele4.Value; } else if (val == "indexType") { idx.indexType = ele4.Value; } else if (val == "isPrimary") { idx.isPrimary = int.Parse(ele4.Value); } else if (val == "unique") { idx.unique = int.Parse(ele4.Value); } else if (val == "oldName") { idx.oldName = ele4.Value; } else if (val == "owner") { idx.owner = ele4.Value; } } } } } else if ((ere.Name == "value") && (nam.ToString() == "struct-name") && (atr.Value == "db.mysql.IndexColumn")) { MyIndexColumn col = new MyIndexColumn(); MyIndex idx = Indexes[Indexes.Count - 1]; if (idx != null) { idx.IndexColumn.Add(col); IEnumerable <XElement> els = ere.Elements(); if (els != null) { foreach (XElement ele4 in els) { if (ele4.HasAttributes) { XAttribute atr3 = ele4.Attribute(XName.Get("key")); string val = ""; if (atr3 != null) { val = atr3.Value; } if (val == "name") { col.name = ele4.Value; } else if (val == "columnLength") { col.columnLength = int.Parse(ele4.Value); } else if (val == "comment") { col.comment = ele4.Value; } else if (val == "descend") { col.descend = int.Parse(ele4.Value); } else if (val == "referencedColumn") { col.referencedColumn = ele4.Value; } else if (val == "owner") { col.owner = ele4.Value; } } } } } } } } if (ere.HasElements == true) { List <XElement> chd = ere.Elements().ToList(); foreach (XElement ere1 in chd) { NodeProcess2(ere1, level + 1); } } }
// // ノードの再帰的処理1 // private void NodeProcess1(XmlNode nod, int level) { if (nod.Attributes != null) { foreach (XmlAttribute atr in nod.Attributes) { if ((atr.Name == "struct-name") && (atr.Value == "db.mysql.Table")) { if (_table != null) { Tables.Add(_table); } _table = new MyTable(); } else if ((atr.Name == "struct-name") && (atr.Value == "db.mysql.Column")) { clevel = level; if (_column != null) { Columns.Add(_column); _table.Columns.Add(_column); } _column = new MyColumn(); } else if ((atr.Name == "key") && (atr.Value == "autoIncrement")) { _column.autoIncrement = int.Parse(nod.FirstChild.Value); } else if ((atr.Name == "key") && (atr.Value == "tableEngine")) { _table.tableEngine = nod.FirstChild.Value; dbe = true; } else if ((atr.Name == "key") && (atr.Value == "name")) { if (dbe) { if ((_table != null) && (nod.FirstChild != null)) { _table.name = nod.FirstChild.Value; dbe = false; } } else { if ((_column != null) && (nod.FirstChild != null)) { _column.name = nod.FirstChild.Value; } } } } } foreach (XmlNode nod1 in nod.ChildNodes) { NodeProcess1(nod1, level + 1); } if (clevel == level) { if (_column != null) { Columns.Add(_column); _table.Columns.Add(_column); _column = null; } clevel = 0; } }