public override object Execute(object context, object[] args, XmlDocument xmlResult) { if (context != null) { XmlNode node = context as XmlNode; if (node == null) { if (context is Resultset) { XmlReader reader = new ResultsetReader((Resultset)context, "context", _command.Context.GetSettings()); XQueryDocument tmp = new XQueryDocument(reader); _command.ContextItem = tmp.CreateNavigator(); } else throw new ESQLException( String.Format(Properties.Resources.XmlQueryContextMustBeANode, context), null); } else _command.ContextItem = node.CreateNavigator(); } if (args != null) { for (int k = 0; k < args.Length; k++) { XQueryParameter param = _command.Parameters[k]; object val = args[k]; if (val is Resultset) { XmlReader reader = new ResultsetReader((Resultset)val, XmlConvert.EncodeName(param.LocalName), _command.Context.GetSettings()); XQueryDocument tmp = new XQueryDocument(reader); param.Value = tmp.CreateNavigator(); } else if (val is XmlNode) param.Value = ((XmlNode)val).CreateNavigator(); else if (val is XmlNodeList) param.Value = new XmlNodeListIterator((XmlNodeList)val); else param.Value = val; } } XQueryNodeIterator iter = _command.Execute(); DOMConverter converter = new DOMConverter(xmlResult); XmlDataAccessor.NodeList res = new XmlDataAccessor.NodeList(); while (iter.MoveNext()) res.Add(converter.ToXmlNode(iter.Current)); if (res.Count == 1) return res[0]; return res; }
public static Resultset Dyncast([Implict] Executive engine, object arg) { QueryNode.LispProcessingContext owner = (QueryNode.LispProcessingContext)engine.Owner; XmlDataAccessor accessor = new XmlDataAccessor(); if (arg == null) return null; else if (arg is Resultset) return (Resultset)arg; else if (arg is XmlNode) { XmlNode node = ((XmlNode)arg); if (node is XmlDocument) node = ((XmlDocument)node).DocumentElement; XmlDataAccessor.NodeList nodeList = new XmlDataAccessor.NodeList(); foreach (XmlAttribute attr in node.Attributes) if (!XmlDataAccessor.IsSpecialAttribute(attr)) nodeList.Add(attr); foreach (XmlNode child in node.ChildNodes) nodeList.Add(child); return accessor.ParseNodes(nodeList, null, owner.Node); } else if (arg is XmlNodeList) return accessor.ParseNodes(((XmlNodeList)arg), null, owner.Node); else if (arg is Array) { Array array = (Array)arg; DataTable dt = RowType.CreateSchemaTable(); if (array.Rank > 1) throw new ESQLException("Can't cast multi-diminsion array to resultset"); else { Type elemType = array.GetType().GetElementType(); DataRow r = dt.NewRow(); r["ColumnName"] = "node"; r["ColumnOrdinal"] = 0; if (Type.GetTypeCode(elemType) == TypeCode.Object) r["DataType"] = typeof(System.Object); else r["DataType"] = elemType; dt.Rows.Add(r); } Resultset rs = new Resultset(new RowType(dt), null); foreach (object item in array) { Row row = rs.NewRow(); row.SetValue(0, item); rs.Enqueue(row); } return rs; } else if (arg == DBNull.Value) return null; else { DataTable dt = RowType.CreateSchemaTable(); DataRow r = dt.NewRow(); r["ColumnName"] = "node"; r["ColumnOrdinal"] = 0; r["DataType"] = TypeConverter.GetTypeByTypeCode(Type.GetTypeCode(arg.GetType())); dt.Rows.Add(r); Resultset rs = new Resultset(new RowType(dt), null); Row row = rs.NewRow(); row.SetValue(0, arg); rs.Enqueue(row); return rs; } }
public static object XmlValueConcat([Implict] Executive engine, params object[] args) { QueryNode.LispProcessingContext owner = (QueryNode.LispProcessingContext)engine.Owner; XmlDataAccessor.NodeList nodes = new XmlDataAccessor.NodeList(); for (int i = 0; i < args.Length; i++) { object val = args[i]; if (val != null && val != Undefined.Value) { if (val is XmlNode) nodes.Add((XmlNode)val); else if (val is XmlNodeList) foreach (XmlNode n in (XmlNodeList)val) nodes.Add(n); else nodes.Add(XmlDataAccessor.Serialize(owner.QueryContext.XmlResult, val)); } } return nodes; }