示例#1
0
        private void processCreation() {
#if OLDCREATION
            Entity = Regex.Match(Query, @"^\s*create\s+(\w+)").Groups[1].Value;
            Type = Entity;
            var applyes = Regex.Matches(Query,@"(?<name>\w+)\s*=\s*'(?<value>[^']*)'");
            var dict = new Dictionary<string, string>();
            foreach (Match applye in applyes) {
                dict[applye.Groups["name"].Value] = applye.Groups["value"].Value;
            }
            create(dict);
            //Query = "from " + Entity + " where Id = " + CreatedObjId;
            PropertyBag["result"] = new object[] { CreatedObj };
#else

			Query = Query.replace(@"/\*[\s\S]+?\*/", "");
            var createscriptxml = new BxlParser().Parse(this.Query,"main");
        	var transform = createscriptxml.Element("transform");
			if(null!=transform) {
				transform.Remove();
				var file = transform.attr("code")+".xslt";
				var path = myapp.files.Resolve(file,true);
				if(path.noContent()) {
					throw new Exception("cannot find transform file "+file);
				}
				var xslt = new XslCompiledTransform();
				xslt.Load(path,XsltSettings.TrustedXslt,new XmlUrlResolver());
				var sw = new StringWriter();
				var arglist = new XsltArgumentList();
				arglist.AddParam("timestamp","",DateTime.Now.ToString("yyyy-MM-dd-hh-mm-ss"));
				xslt.Transform(createscriptxml.CreateReader(),arglist,sw);
				createscriptxml = XElement.Parse(sw.ToString());
			}
            var creations = createscriptxml.Elements("create");
            var result = new List<HqlResult>();
            foreach (var creation in creations) {
                var tree = creation.attr("tree");
                var subresult = new HqlResult();
                subresult.Entity = creation.attr("id");
                subresult.Items = new List<object>();
                if (creation.Elements(subresult.Entity).Count() == 0) {
                    creation.Add(new XElement(subresult.Entity));
                }
                var items = creation.Descendants(subresult.Entity);
                foreach (var item in items) {
                    var selfattributes = item.Attributes();
                    var parentattributes =
                        item.Parent.Attributes().Where(
                            x => null == selfattributes.FirstOrDefault(y => y.Name.LocalName == x.Name.LocalName));
                    var allattributes =
                        selfattributes.Union(parentattributes).Where(x => x.Name.LocalName != "id").ToArray();
                    var dict = new Dictionary<string, string>();
                    foreach (var o in allattributes) {
                        dict[o.Name.LocalName] = o.Value;
                    }
                    if(tree.hasContent() && item.Parent!=null && item.Parent.Name.LocalName!="create") {
                        dict[tree] = item.Parent.attr("code");
                    }
                    create(dict, subresult.Entity);
                    subresult.Items.Add(this.CreatedObj);
                }
                var cols = new HqlColumnLoader().GetColumns(subresult.Entity, View);
                subresult.Columns = cols;
                result.Add(subresult);

                

            }
            PropertyBag["results"] = result;
            PropertyBag["multiple"] = true;

#endif
        }
示例#2
0
        public void execute() {
            PropertyBag["usefields"] = false;
            PropertyBag["useid"] = false;
            PropertyBag["fields"] = new string[] {};
            PropertyBag["ididx"] = -1;
            var q_ = Query.replace(@"/\*[\s\S]+?\*/","");
        	Query = q_;
            if (q_.like(@"^\s*((create)|(transform))\s+")) {
                processCreation();
                return;
                ;
            }
            if (q_.like(@"(?ix)[\r\n]+\s*GO\s*[\r\n]+"))
            {
                var queries =
                    Regex.Split(q_, @"(?ix)[\r\n]+\s*GO\s*[\r\n]+").Select(x => x.Trim()).Where(
                        x => x.hasContent() && x != "GO");
                var results = new List<HqlResult>();
                foreach (var query in queries) {
                    var result = new HqlResult();
                    var parsed = new HqlParserLite().Parse(query);
                    if (parsed.Processed && parsed.IsSimple && parsed.Fields.Count==0)
                    {
                        result.Entity = parsed.TableName;
                        result.Items = myapp.storage.GetDefault().WithSystem(System).Query(query).ToList();
                        var cols1 = new HqlColumnLoader().GetColumns(result.Entity, View);
                        result.Columns = cols1;
                        results.Add(result);
                    }else {
                        throw  new Exception("cannot execute non simple queries in batch");
                    }

                }
                PropertyBag["results"] = results;
                PropertyBag["multiple"] = true;
            }
            else {
                
                var parsed = new HqlParserLite().Parse(q_);

                if (parsed.Processed && parsed.TableName.hasContent()) {
                    Entity = parsed.TableName;
                    Type = Entity;
                }
                if (parsed.Processed && parsed.IsSimple && parsed.Fields.Count != 0) {

                    PropertyBag["usefields"] = true;
                    if (parsed.Fields.Contains("Id")) {
                        PropertyBag["useid"] = true;
                        PropertyBag["ididx"] = parsed.Fields.IndexOf("Id");
                    }
                    PropertyBag["fields"] = parsed.Fields.ToArray();
                }
                PropertyBag["result"] = myapp.storage.GetDefault().WithSystem(System).Query(q_);

            }
            var cols = new HqlColumnLoader().GetColumns(Type, View);
        	foreach (var hqlColumn in cols.Values) {
        		hqlColumn.System = System;
        	}
            PropertyBag["columns"] = cols;
			HqlObjectDelegate hqlobjects = q => myapp.storage.GetDefault().WithSystem(System).Query(q).OfType<IEntityDataPattern>().ToList();
			HqlArrayDelegate hqlarrays = q => myapp.storage.GetDefault().WithSystem(System).Query(q).OfType<object[]>().ToList();
        	PropertyBag["hqlobjects"] = hqlobjects;
        	PropertyBag["hqlarrays"] = hqlarrays;
        }