예제 #1
0
        //INTEGER | FLOAT | BOOLEAN | STRING | NAME | PARAM;
        private Expression ParseLiteral(RQ q)
        {
            if (q.IsNext(tokens["name"]))
            {
                RowValueExpression rv = new RowValueExpression();
                rv.row = q.Pop().value;
                return(rv);
            }

            if (q.IsNext(tokens["int"]) || q.IsNext(tokens["float"]) || q.IsNext(tokens["bool"]))
            {
                ValueExpression v = new ValueExpression();
                v.value = q.Pop().value;
                return(v);
            }

            if (q.IsNext(tokens["param"]))
            {
                ValueExpression v = new ValueExpression();
                v.value       = q.Peek().value;
                v.parameterId = int.Parse(v.value.Remove(0, 1));
                return(v);
            }

            if (q.IsNext(tokens["string"]))
            {
                ValueExpression v = new ValueExpression();
                v.value = q.Peek().value.Remove(0, 1);
                v.value = v.value.Remove(v.value.Length - 1);
                q.Pop();
                return(v);
            }

            return(null);
        }
예제 #2
0
        //'UPDATE' NAME 'SET' (NAME '=' expression) (',' NAME '=' expression)* ('WHERE' expression)?
        private Query ParseUpdate(RQ q)
        {
            if (!q.IsNext(tokens["update"]))
            {
                return(null);
            }
            q.Pop();

            TableSource s = ParseSource(q);

            if (!q.IsNext(tokens["set"]))
            {
                return(null);
            }
            q.Pop();

            List <string>     fields = new List <string>();
            List <Expression> values = new List <Expression>();

            while (true)
            {
                if (!q.IsNext(tokens["name"]))
                {
                    break;
                }
                string field = q.Pop().value;
                if (!q.IsNext(tokens["compare"]))
                {
                    break;
                }
                string op = q.Peek().value;
                if (op != "=")
                {
                    break;
                }
                q.Pop();

                Expression e2 = ParseExpression(q);

                fields.Add(field);
                values.Add(e2);

                if (!q.IsNext(tokens["comma"]))
                {
                    break;
                }
            }

            if (!q.IsNext(tokens["where"]))
            {
                return(null);
            }
            q.Pop();

            Expression e = ParseExpression(q);

            if (e == null)
            {
                e = new TrueExpression();
            }

            UpdateQuery u = new UpdateQuery();

            u.table  = s;
            u.fields = fields.ToArray();
            u.values = values.ToArray();
            u.exp    = e;
            return(u);
        }