Example #1
0
        internal static string ParseSelect(this ExpandedNavigationSelectItem expanded, DbUtility utility)
        {
            if (expanded.CountOption.HasValue)
            {
                return("count(0)");
            }
            if (expanded.SelectAndExpand == null)
            {
                return("*");
            }
            if (expanded.SelectAndExpand.AllSelected)
            {
                return("*");
            }
            List <string>  s      = new List <string>();
            PathSelectItem select = null;

            foreach (var item in expanded.SelectAndExpand.SelectedItems)
            {
                select = item as PathSelectItem;
                if (select != null)
                {
                    foreach (PropertySegment path in select.SelectedPath)
                    {
                        s.Add(utility.SafeDbObject(path.Property.Name));
                    }
                }
            }
            return(string.Join(",", s));
        }
Example #2
0
        internal static string ParseSelect(this ODataQueryOptions options, DbUtility utility)
        {
            if (options.Count != null)
            {
                return("count(0)");
            }
            if (options.SelectExpand == null)
            {
                return("*");
            }
            if (options.SelectExpand.SelectExpandClause.AllSelected)
            {
                return("*");
            }
            List <string>  s      = new List <string>();
            PathSelectItem select = null;

            foreach (var item in options.SelectExpand.SelectExpandClause.SelectedItems)
            {
                select = item as PathSelectItem;
                if (select != null)
                {
                    foreach (PropertySegment path in select.SelectedPath)
                    {
                        s.Add(utility.SafeDbObject(path.Property.Name));
                    }
                }
            }
            return(string.Join(",", s));
        }
Example #3
0
 static string BindRangeVariable(ResourceRangeVariable entityRangeVariable, DbUtility dbUtility)
 {
     return(dbUtility.SafeDbObject(entityRangeVariable.Name));
 }
Example #4
0
 static string BindPropertyAccessQueryNode(SingleValuePropertyAccessNode singleValuePropertyAccessNode, DbUtility dbUtility)
 {
     return(dbUtility.SafeDbObject(singleValuePropertyAccessNode.Property.Name));
 }
Example #5
0
        static string BindSingleValueFunctionCallNode(SingleValueFunctionCallNode node, List <DbParameter> pars, DbUtility dbUtility)
        {
            var         arguments = node.Parameters.ToList();
            string      name      = string.Empty;
            string      parName   = string.Empty;
            object      parValue  = null;
            DbParameter dbpar     = null;

            switch (node.Name)
            {
            case "concat":
                List <string> p = new List <string>();
                foreach (var item in arguments)
                {
                    parValue = Bind(item, pars, dbUtility);
                    dbpar    = dbUtility.CreateParameter(parValue, pars);
                    p.Add(dbpar.ParameterName);
                }
                return(string.Format("concat({0})", string.Join(",", p)));

            case "contains":
                name     = dbUtility.SafeDbObject(Bind(arguments[0], pars, dbUtility));
                parValue = string.Format("%{0}%", (arguments[1] as ConstantNode).Value);
                dbpar    = dbUtility.CreateParameter(parValue, pars);
                return(string.Format("{0} like {1}", name, dbpar.ParameterName));

            case "endswith":
                name     = dbUtility.SafeDbObject(Bind(arguments[0], pars, dbUtility));
                parValue = string.Format("%{0}", (arguments[1] as ConstantNode).Value);
                dbpar    = dbUtility.CreateParameter(parValue, pars);
                return(string.Format("{0} like {1}", name, dbpar.ParameterName));

            case "startswith":
                name     = Bind(arguments[0], pars, dbUtility);
                parValue = string.Format("{0}%", (arguments[1] as ConstantNode).Value);
                dbpar    = dbUtility.CreateParameter(parValue, pars);
                return(string.Format("{0} like {1}", name, parName));

            case "length":
                return(string.Format("len({0})", Bind(arguments[0], pars, dbUtility)));

            case "indexof":
                name     = dbUtility.SafeDbObject(Bind(arguments[0], pars, dbUtility));
                parValue = (arguments[1] as ConstantNode).Value;
                dbpar    = dbUtility.CreateParameter(parValue, pars);
                return(string.Format("charindex({0},{1})", dbpar.ParameterName, name));

            case "substring":
                parValue = Bind(arguments[0], pars, dbUtility);
                dbpar    = dbUtility.CreateParameter(parValue, pars);
                return(string.Format("SUBSTRING({0},{1},{2})",
                                     dbpar.ParameterName,
                                     (arguments[1] as ConstantNode).Value,
                                     arguments.Count > 2 ? (arguments[2] as ConstantNode).Value : 0));

            case "tolower":
                parValue = Bind(arguments[0], pars, dbUtility);
                dbpar    = dbUtility.CreateParameter(parValue, pars);
                return("LOWER(" + dbpar.ParameterName + ")");

            case "toupper":
                parValue = Bind(arguments[0], pars, dbUtility);
                dbpar    = dbUtility.CreateParameter(parValue, pars);
                return("UPPER(" + parName + ")");

            case "trim":
            case "year":
            case "years":
            case "month":
            case "months":
            case "day":
            case "days":
            case "hour":
            case "hours":
            case "minute":
            case "minutes":
            case "second":
            case "seconds":
            case "round":
            case "floor":
            case "ceiling":
                parValue = Bind(arguments[0], pars, dbUtility);
                dbpar    = dbUtility.CreateParameter(parValue, pars);
                return(node.Name + "(" + parName + ")");

            default:
                throw new NotImplementedException();
            }
        }
Example #6
0
 static string BindNavigationPropertyNode(SingleValueNode singleValueNode, IEdmNavigationProperty edmNavigationProperty, List <DbParameter> pars, DbUtility dbUtility)
 {
     return(Bind(singleValueNode, pars, dbUtility) + "." + dbUtility.SafeDbObject(edmNavigationProperty.Name));
 }
Example #7
0
 static string BindCollectionPropertyAccessNode(CollectionPropertyAccessNode collectionPropertyAccessNode, DbUtility dbUtility)
 {
     return(dbUtility.SafeDbObject(collectionPropertyAccessNode.Property.Name));
     //return Bind(collectionPropertyAccessNode.Source) + "." + collectionPropertyAccessNode.Property.Name;
 }