Exemplo n.º 1
0
        private NPathSelectQuery ParseSelectQuery()
        {
            NPathSelectQuery query = new NPathSelectQuery();

            queries.Push(query);

            tokenizer.GetCurrentToken("select", "Select");

            NPathSelectClause selectClause = new NPathSelectClause();

            ParseSelectClause(selectClause);
            query.Select = selectClause;

            tokenizer.GetCurrentToken("from", "From");
            NPathFromClause fromClause = new NPathFromClause();

            ParseFromClause(fromClause);
            query.From = fromClause;

            if (tokenizer.GetCurrentToken().IsType("where"))
            {
                NPathWhereClause whereClause = new NPathWhereClause();
                query.Where = whereClause;
                ParseWhereClause(whereClause);
            }

            if (tokenizer.GetCurrentToken().IsType("order by"))             // do not localize
            {
                NPathOrderByClause orderByClause = new NPathOrderByClause();
                ParseOrderByClause(orderByClause);
                query.OrderBy = orderByClause;
            }

            return(query);
        }
Exemplo n.º 2
0
        private void ParseSelectClause(NPathSelectClause selectClause)
        {
            if (tokenizer.GetNextToken().IsType("distinct"))
            {
                selectClause.Distinct = true;
                tokenizer.MoveNext();
            }

            if (tokenizer.GetNextToken().IsType("top"))
            {
                selectClause.HasTop = true;
                tokenizer.MoveNext();
                double top = double.Parse(tokenizer.GetNextToken("decimal", "Decimal value").Text);                 // do not localize
                selectClause.Top = (int)top;
                tokenizer.MoveNext();

                if (tokenizer.GetNextToken().IsType("percent"))
                {
                    selectClause.Percent = true;
                    tokenizer.MoveNext();
                }
                if (tokenizer.GetNextToken().IsType("with ties"))                 // do not localize
                {
                    selectClause.WithTies = true;
                    tokenizer.MoveNext();
                }
            }


            do
            {
                tokenizer.MoveNext();
                {
                    IValue           expression = ParseExpression();
                    NPathSelectField field      = new NPathSelectField();
                    field.Expression = expression;
                    field.Alias      = null;
                    selectClause.SelectFields.Add(field);
                }

                if (tokenizer.GetCurrentToken().IsType("as"))
                {
                    NPathSelectField field = selectClause.SelectFields[selectClause.SelectFields.Count - 1] as NPathSelectField;
                    tokenizer.MoveNext();
                    field.Alias = tokenizer.GetCurrentToken().Text;
                    tokenizer.MoveNext();
                }
            } while (tokenizer.GetCurrentToken().IsType("comma"));
        }
Exemplo n.º 3
0
        protected virtual void EmitSelect(NPathSelectQuery query)
        {
            NPathSelectClause select = query.Select;

            Write("select ");             // do not localize

            if (query.Select.HasTop)
            {
                Write("top {0}", query.Select.Top);                 // do not localize
                if (query.Select.Percent)
                {
                    Write("% ");
                }
            }
            int i = 0;

            foreach (NPathSelectField field in select.SelectFields)
            {
                if (field.Expression is NPathIdentifier)
                {
                    NPathIdentifier path = field.Expression as NPathIdentifier;
                    Write(path.Path);
                }
                if (field.Expression is NPathFunction)
                {
                    NPathFunction function = field.Expression as NPathFunction;
                    EmitFunction(function);
                }
                if (field.Expression is NPathExpression)
                {
                    NPathExpression expression = field.Expression as NPathExpression;
                    EmitExpression(expression);
                }

                if (field.Alias != null && field.Alias != "")
                {
                    WriteLine(" as [{0}]", field.Alias);                     // do not localize
                }

                if (i < select.SelectFields.Count - 1)
                {
                    Write(",");
                }
                i++;
            }
            WriteLine();
        }