コード例 #1
0
        /// <summary>
        /// Tries to parse a script node.
        /// </summary>
        /// <param name="Parser">Custom parser.</param>
        /// <param name="Result">Parsed Script Node.</param>
        /// <returns>If successful in parsing a script node.</returns>
        public bool TryParse(ScriptParser Parser, out ScriptNode Result)
        {
            Result = null;

            try
            {
                string s = Parser.NextToken().ToUpper();
                if (s != "FROM")
                {
                    return(false);
                }

                if (!SelectParser.TryParseSources(Parser, out SourceDefinition Source))
                {
                    return(false);
                }

                ScriptNode Where = null;

                s = Parser.PeekNextToken().ToUpper();
                if (s == "WHERE")
                {
                    Parser.NextToken();
                    Where = Parser.ParseOrs();
                }

                Result = new Delete(Source, Where, Parser.Start, Parser.Length, Parser.Expression);

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
コード例 #2
0
ファイル: DropParser.cs プロジェクト: live0717/IoTGateway
        /// <summary>
        /// Tries to parse a script node.
        /// </summary>
        /// <param name="Parser">Custom parser.</param>
        /// <param name="Result">Parsed Script Node.</param>
        /// <returns>If successful in parsing a script node.</returns>
        public bool TryParse(ScriptParser Parser, out ScriptNode Result)
        {
            Result = null;

            try
            {
                string s = Parser.NextToken().ToUpper();
                if (s != "INDEX")
                {
                    return(false);
                }

                ScriptNode Name = Parser.ParseNoWhiteSpace();

                s = Parser.NextToken().ToUpper();
                if (s != "ON")
                {
                    return(false);
                }

                if (!SelectParser.TryParseSources(Parser, out SourceDefinition Source))
                {
                    return(false);
                }

                Result = new DropIndex(Name, Source, Parser.Start, Parser.Length, Parser.Expression);

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
コード例 #3
0
        /// <summary>
        /// Tries to parse a script node.
        /// </summary>
        /// <param name="Parser">Custom parser.</param>
        /// <param name="Result">Parsed Script Node.</param>
        /// <returns>If successful in parsing a script node.</returns>
        public bool TryParse(ScriptParser Parser, out ScriptNode Result)
        {
            Result = null;

            try
            {
                string s = Parser.NextToken().ToUpper();
                if (s != "INDEX")
                {
                    return(false);
                }

                ScriptNode Name = Parser.ParseNoWhiteSpace();

                s = Parser.NextToken().ToUpper();
                if (s != "ON")
                {
                    return(false);
                }

                if (!SelectParser.TryParseSources(Parser, out SourceDefinition Source))
                {
                    return(false);
                }

                s = Parser.NextToken();
                if (s != "(")
                {
                    return(false);
                }

                this.ParseList(Parser, out ScriptNode[] Columns, out bool[] Ascending);

                if (Columns.Length == 0)
                {
                    return(false);
                }

                if (Parser.NextToken() != ")")
                {
                    return(false);
                }

                Result = new CreateIndex(Name, Source, Columns, Ascending, Parser.Start, Parser.Length, Parser.Expression);

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
コード例 #4
0
ファイル: DropParser.cs プロジェクト: robinreigns/IoTGateway
        /// <summary>
        /// Tries to parse a script node.
        /// </summary>
        /// <param name="Parser">Custom parser.</param>
        /// <param name="Result">Parsed Script Node.</param>
        /// <returns>If successful in parsing a script node.</returns>
        public bool TryParse(ScriptParser Parser, out ScriptNode Result)
        {
            Result = null;

            try
            {
                string s = Parser.NextToken().ToUpper();
                switch (s)
                {
                case "INDEX":
                    ScriptNode Name = Parser.ParseNoWhiteSpace();

                    s = Parser.NextToken().ToUpper();
                    if (s != "ON")
                    {
                        return(false);
                    }

                    if (!SelectParser.TryParseSources(Parser, out SourceDefinition Source))
                    {
                        return(false);
                    }

                    Result = new DropIndex(Name, Source, Parser.Start, Parser.Length, Parser.Expression);

                    return(true);

                case "TABLE":
                case "COLLECTION":
                    if (!SelectParser.TryParseSources(Parser, out Source))
                    {
                        return(false);
                    }

                    Result = new DropCollection(Source, Parser.Start, Parser.Length, Parser.Expression);

                    return(true);

                default:
                    return(false);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
コード例 #5
0
        /// <summary>
        /// Tries to parse a script node.
        /// </summary>
        /// <param name="Parser">Custom parser.</param>
        /// <param name="Result">Parsed Script Node.</param>
        /// <returns>If successful in parsing a script node.</returns>
        public bool TryParse(ScriptParser Parser, out ScriptNode Result)
        {
            Result = null;

            try
            {
                string s = Parser.NextToken().ToUpper();
                if (s != "INTO")
                {
                    return(false);
                }

                if (!SelectParser.TryParseSources(Parser, out SourceDefinition Source))
                {
                    return(false);
                }

                switch (Parser.PeekNextToken().ToUpper())
                {
                case "(":
                    Parser.NextToken();

                    ScriptNode Node = Parser.ParseList();
                    if (!(Node is ElementList Columns))
                    {
                        Columns = new ElementList(new ScriptNode[] { Node }, Node.Start, Node.Length, Node.Expression);
                    }

                    if (Parser.NextToken() != ")")
                    {
                        return(false);
                    }

                    if (Parser.NextToken().ToUpper() != "VALUES")
                    {
                        return(false);
                    }

                    if (Parser.NextToken() != "(")
                    {
                        return(false);
                    }

                    Node = Parser.ParseList();
                    if (!(Node is ElementList Values))
                    {
                        Values = new ElementList(new ScriptNode[] { Node }, Node.Start, Node.Length, Node.Expression);
                    }

                    if (Values.Elements.Length != Columns.Elements.Length)
                    {
                        return(false);
                    }

                    if (Parser.NextToken() != ")")
                    {
                        return(false);
                    }

                    Result = new InsertValues(Source, Columns, Values, Parser.Start, Parser.Length, Parser.Expression);
                    return(true);

                case "SELECT":
                    Node = Parser.ParseStatement();
                    if (!(Node is Select Select))
                    {
                        return(false);
                    }

                    Result = new InsertSelect(Source, Select, Parser.Start, Parser.Position, Parser.Expression);
                    return(true);

                case "OBJECT":
                case "OBJECTS":
                    Parser.NextToken();

                    Node = Parser.ParseList();
                    if (!(Node is ElementList Objects))
                    {
                        Objects = new ElementList(new ScriptNode[] { Node }, Node.Start, Node.Length, Node.Expression);
                    }

                    Result = new InsertObjects(Source, Objects, Parser.Start, Parser.Length, Parser.Expression);
                    return(true);

                default:
                    return(false);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
コード例 #6
0
        /// <summary>
        /// Tries to parse a script node.
        /// </summary>
        /// <param name="Parser">Custom parser.</param>
        /// <param name="Result">Parsed Script Node.</param>
        /// <returns>If successful in parsing a script node.</returns>
        public bool TryParse(ScriptParser Parser, out ScriptNode Result)
        {
            Result = null;

            try
            {
                if (!SelectParser.TryParseSources(Parser, out SourceDefinition Source))
                {
                    return(false);
                }

                string s = Parser.NextToken().ToUpper();
                if (s != "SET")
                {
                    return(false);
                }

                List <Assignment> SetOperations = new List <Assignment>();
                ScriptNode        Node          = Parser.ParseList();

                if (!(Node is ElementList List))
                {
                    List = new ElementList(new ScriptNode[] { Node }, Node.Start, Node.Length, Node.Expression);
                }

                foreach (ScriptNode Operation in List.Elements)
                {
                    if (Operation is EqualTo EqualTo)
                    {
                        if (EqualTo.LeftOperand is VariableReference Ref)
                        {
                            SetOperations.Add(new Assignment(Ref.VariableName, EqualTo.RightOperand, EqualTo.Start, EqualTo.Length, EqualTo.Expression));
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else if (Operation is Assignment Assignment)
                    {
                        SetOperations.Add(Assignment);
                    }
                    else
                    {
                        return(false);
                    }
                }

                ScriptNode Where = null;

                s = Parser.PeekNextToken().ToUpper();
                if (s == "WHERE")
                {
                    Parser.NextToken();
                    Where = Parser.ParseOrs();
                }

                Result = new Update(Source, SetOperations.ToArray(), Where, Parser.Start, Parser.Length, Parser.Expression);

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }