public void to_begin() { if (_path != null) { if (_xr != null) { _xr.Close(); } _xr = new GotDotNet.XPath.XPathReader(_path, "/root/rows/row"); } }
public void close() { if (_xr != null) { _xr.Close(); _xr = null; } if (_flds != null) { _flds.Clear(); _flds = null; } }
protected void read_cols(string path, schema_doc sch = null) { _path = path; _cols = new List <Dictionary <string, string> >(); _flds = new List <schema_field>(); // carico le colonne di struttura + schema campi using (GotDotNet.XPath.XPathReader xr = new GotDotNet.XPath.XPathReader(_path, "/root/cols/col")) { while (xr.ReadUntilMatch()) { Dictionary <string, string> col = new Dictionary <string, string>(); while (xr.MoveToNextAttribute()) { col.Add(xr.Name, xr.Value); } _flds.Add(new schema_field(dbType.xml, col["name"], col["type"], col.ContainsKey("nullable") ? bool.Parse(col["nullable"]) : false , col.ContainsKey("maxlength") ? int.Parse(col["maxlength"]) : (int?)null, col.ContainsKey("numprec") ? int.Parse(col["numprec"]) : (int?)null , col.ContainsKey("numscale") ? int.Parse(col["numscale"]) : (int?)null, col.ContainsKey("default") ? col["numscale"] : "" , col.ContainsKey("autonumber") ? bool.Parse(col["autonumber"]) : false , col["level"] == "1" && col.ContainsKey("pkfield") && col["pkfield"] == "1", 0)); _cols.Add(col); } } // carico i campi using (GotDotNet.XPath.XPathReader xr = new GotDotNet.XPath.XPathReader(_path, "/root/data")) { if (xr.ReadUntilMatch()) { schema_doc sk = _db_xml != null ? _db_xml.schema : sch; if (_flds.Count == 0) { for (int i = 0; i < xr.AttributeCount; i++) { _flds.Add(sk.new_schema_field(sk.field_node(table, xr.GetAttribute("f" + i.ToString("00"))) , "f" + i.ToString("00"))); } } else { for (int i = 0; i < xr.AttributeCount; i++) { _flds.Find(x => x.Name.ToUpper() == xr.GetAttribute("f" + i.ToString("00")).ToUpper()).AttrName = "f" + i.ToString("00"); } } } } to_begin(); }
public void xmldata_to_table(db_schema db, string table) { List <schema_field> cols = db.table_fields(table); // cols using (GotDotNet.XPath.XPathReader xr = new GotDotNet.XPath.XPathReader(data_path(table), "/root/data")) { if (xr.ReadUntilMatch()) { while (xr.MoveToNextAttribute()) { schema_field field = findField(cols, xr.Value); if (field == null) { continue; } field.AttrName = xr.Name; } } else { throw new Exception("la struttura xml del file data della tabella '" + table + "' non è corretta"); } } // insert rows bool identity = db.type == dbType.sqlserver && cols.FirstOrDefault(x => x.AutoNumber) != null; if (identity) { db.set_identity(table, true); } try { using (GotDotNet.XPath.XPathReader xr = new GotDotNet.XPath.XPathReader(data_path(table), "/root/rows/row")) { string header = string.Format("INSERT INTO {0} ({1})", table, string.Join(", ", cols.Select(x => "[" + x.Name + "]"))); while (xr.ReadUntilMatch()) { db.exec(header + " VALUES (" + string.Join(", ", cols.Select(x => db.val_toqry(xr[x.AttrName], x.TypeField, type, _nullxml))) + ")"); } } } finally { if (identity) { db.set_identity(table, false); } } }