Ejemplo n.º 1
0
        private void ParseWhereClause(SelectStatement s)
        {
            if (_tokens.LookAhead().TokenType != TokenType.KW_WHERE) return;
            _tokens.Read();

            ExpressionList l = ParseExprList();
            if (l.Count < 1) {
                throw new Exception("The expression is missing from the WHERE clause.");
            }

            s.WhereClause = new WhereClause(l);
        }
Ejemplo n.º 2
0
        private void ParseSelectClause(SelectStatement s)
        {
            bool wildcard = false;
            bool distinct = false;

            switch (_tokens.LookAhead().TokenType) {
                case TokenType.KW_DISTINCT:
                    _tokens.Read();
                    distinct = true;
                    break;
                case TokenType.OP_MUL:
                    _tokens.Read();
                    wildcard = true;
                    break;
                case TokenType.KW_ALL:
                    _tokens.Read();
                    distinct = false;
                    break;
            }

            if (wildcard && _tokens.LookAhead().TokenType != TokenType.KW_FROM) {
                throw new Exception("SELECT syntax error. No result columns specified. Near \"" + _tokens.LookAhead().Lexeme.StringValue() + "\"");
            }

            ExpressionList l = null;
            if (!wildcard) {
                l = ParseColumnList();
                if (l.Count == 0) {
                    throw new Exception("SELECT syntax error. No result columns specified.");
                }
            }
            s.SelectClause = new SelectClause(l, wildcard, distinct);
        }
Ejemplo n.º 3
0
        private Expression ParseSelectStatement()
        {
            if (_tokens.LookAhead().TokenType != TokenType.KW_SELECT) return null;
            _tokens.Read();

            SelectStatement s = new SelectStatement();
            ParseSelectClause(s);
            ParseFromClause(s);
            ParseWhereClause(s);
            ParseGroupByClause(s);
            ParseOrderByClause(s);
            ParseLimitClause(s);
            return s;
        }
Ejemplo n.º 4
0
 private void ParseOrderingTerms(SelectStatement s)
 {
     ExpressionList l = new ExpressionList();
     //match exp (ASC|DESC) (, exp (ASC|DESC))*
     while (true) {
         ParseExpression();
         if (_exprs.Count < 1) {
             throw new Exception("The base expression is missing.");
         }
         Expression e = _exprs.Pop();
         switch (_tokens.LookAhead().TokenType) {
             case TokenType.KW_ASC:
                 _tokens.Read();
                 l.Add(new OrderingTerm(e, SortOrder.ASCENDING));
                 break;
             case TokenType.KW_DESC:
                 _tokens.Read();
                 l.Add(new OrderingTerm(e, SortOrder.DESCENDING));
                 break;
             default:
                 l.Add(new OrderingTerm(e, SortOrder.ASCENDING));
                 break;
         }
         if (_tokens.LookAhead().TokenType != TokenType.PM_COMMA) { break; }
         else {
             _tokens.Read();
         }
     }
     s.OrderByClause = new OrderByClause(l);
 }
Ejemplo n.º 5
0
 private void ParseOrderByClause(SelectStatement s)
 {
     if (_tokens.LookAhead().TokenType != TokenType.KW_ORDER) return;
     _tokens.Read();
     if (_tokens.LookAhead().TokenType != TokenType.KW_BY) {
         throw new Exception("ORDER BY clause syntax error.");
     }
     _tokens.Read();
     ParseOrderingTerms(s);
 }
Ejemplo n.º 6
0
        private void ParseLimitClause(SelectStatement s)
        {
            if (_tokens.LookAhead().TokenType != TokenType.KW_LIMIT) return;
            _tokens.Read();

            ParseExpression();
            if (_exprs.Count < 1) {
                throw new Exception("The expression for the LIMIT clause was missing.");
            }

            s.LimitClause = new LimitClause(_exprs.Pop());

            if (_tokens.LookAhead().TokenType != TokenType.KW_OFFSET) return;
            _tokens.Read();

            ParseExpression();
            if (_exprs.Count < 1) {
                throw new Exception("The expression for the OFFSET clause was missing.");
            }

            s.LimitClause.Offset = _exprs.Pop();
        }
Ejemplo n.º 7
0
        private void ParseGroupByClause(SelectStatement s)
        {
            if (_tokens.LookAhead().TokenType != TokenType.KW_GROUP) return;
            _tokens.Read();
            if (_tokens.LookAhead().TokenType != TokenType.KW_BY) {
                throw new Exception("GROUP BY clause syntax error.");
            }
            _tokens.Read();

            ExpressionList l = ParseExprList();
            if (l.Count == 0) {
                throw new Exception("The expression is missing from the GROUP BY clause.");
            }

            s.GroupByClause = new GroupByClause(l);

            if (_tokens.LookAhead().TokenType != TokenType.KW_HAVING) return;
            _tokens.Read();

            ParseExpression();
            if (_exprs.Count < 1) {
                throw new Exception("The expression is missing from the HAVING clause.");
            }

            s.GroupByClause.HavingClause = new HavingClause(_exprs.Pop());
        }
Ejemplo n.º 8
0
 private void ParseFromClause(SelectStatement s)
 {
     if (_tokens.LookAhead().TokenType != TokenType.KW_FROM) return;
     _tokens.Read();
     ExpressionList l = ParseColumnList();
     if (l.Count == 0) {
         throw new Exception("FROM syntax error. No table expressions specified.");
     }
     s.FromClause = new FromClause(l);
 }