Example #1
0
        private IQsiTreeNode ParseDataManipulationStatement(DataManipulationStatementContext statement)
        {
            switch (statement.children[0])
            {
            case SelectStatementContext selectStatement:
                return(TableVisitor.VisitSelectStatement(selectStatement));

            case SelectIntoStatementContext selectIntoStatement:
                return(ActionVisitor.VisitSelectIntoStatement(selectIntoStatement));

            case DeleteStatementContext deleteStatement:
                return(ActionVisitor.VisitDeleteStatement(deleteStatement));

            case InsertStatementContext insertStatement:
                return(ActionVisitor.VisitInsertStatement(insertStatement));

            case ReplaceStatementContext replaceStatement:
                return(ActionVisitor.VisitReplaceStatement(replaceStatement));

            case UpdateStatementContext updateStatement:
                return(ActionVisitor.VisitUpdateStatement(updateStatement));

            case MergeDeltaParameterContext mergeDeltaParameter:
                throw new NotImplementedException();

            case MergeIntoStatementContext mergeIntoStatement:
                throw new NotImplementedException();

            default:
                throw TreeHelper.NotSupportedTree(statement.children[0]);
            }
        }
Example #2
0
        private IQsiTreeNode ParseInternal(QsiScript script, Parser parser)
        {
            var primarSqlParser = (global::PrimarSql.Internal.PrimarSqlParser)parser;
            var rootContext     = primarSqlParser.root();

            if (rootContext.children[0] is not SqlStatementContext sqlStatement)
            {
                return(null);
            }

            if (sqlStatement.children[0] is not DmlStatementContext dmlStatement)
            {
                return(null);
            }

            switch (dmlStatement.children[0])
            {
            case SelectStatementContext selectStatement:
                return(TableVisitor.VisitSelectStatement(selectStatement));

            case InsertStatementContext insertStatement:
                return(ActionVisitor.VisitInsertStatement(insertStatement));

            case DeleteStatementContext deleteStatement:
                return(ActionVisitor.VisitDeleteStatement(deleteStatement));

            case UpdateStatementContext updateStatement:
                return(ActionVisitor.VisitUpdateStatement(updateStatement));

            default:
                return(null);
            }
        }
Example #3
0
        public IQsiTreeNode Parse(QsiScript script, CancellationToken cancellationToken = default)
        {
            var stream = new AntlrInputStream(script.Script);
            var lexer  = new CqlLexerInternal(stream);
            var tokens = new CommonTokenStream(lexer);
            var parser = new CqlParserInternal(tokens);

            parser.AddErrorListener(new ErrorListener());

            var statement = parser.cqlStatement().children[0];

            switch (statement)
            {
            case SelectStatementContext selectStatement:
                return(TableVisitor.VisitSelectStatement(selectStatement));

            case CreateMaterializedViewStatementContext createMaterializedViewStatement:
                return(DefinitionVisitor.VisitCreateMaterializedViewStatement(createMaterializedViewStatement));

            case UseStatementContext useStatement:
                return(ActionVisitor.VisitUseStatement(useStatement));

            case InsertStatementContext insertStatement:
                return(ActionVisitor.VisitInsertStatement(insertStatement));

            case UpdateStatementContext updateStatement:
                return(ActionVisitor.VisitUpdateStatement(updateStatement));

            case DeleteStatementContext deleteStatement:
                return(ActionVisitor.VisitDeleteStatement(deleteStatement));

            default:
                throw TreeHelper.NotSupportedTree(statement);
            }
        }
Example #4
0
        public IQsiTreeNode Parse(QsiScript script, CancellationToken cancellationToken = default)
        {
            var parser = MySQLUtility.CreateParser(script.Script, _version);
            var query  = parser.query();

            if (query.children[0] is not SimpleStatementContext simpleStatement)
            {
                return(null);
            }

            switch (simpleStatement.children[0])
            {
            case SelectStatementContext selectStatement:
                return(TableVisitor.VisitSelectStatement(selectStatement));

            case CreateStatementContext createStatement when
                createStatement.children[1] is CreateViewContext createView:
                return(TableVisitor.VisitCreateView(createView));

            case DeleteStatementContext deleteStatement:
                return(ActionVisitor.VisitDeleteStatement(deleteStatement));

            case ReplaceStatementContext replaceStatement:
                return(ActionVisitor.VisitReplaceStatement(replaceStatement));

            case UpdateStatementContext updateStatement:
                return(ActionVisitor.VisitUpdateStatement(updateStatement));

            case InsertStatementContext insertStatement:
                return(ActionVisitor.VisitInsertStatement(insertStatement));

            default:
                throw TreeHelper.NotSupportedTree(simpleStatement.children[0]);
            }
        }
        private IQsiTreeNode ParseInternal(QsiScript script, Parser parser)
        {
            var primarSqlParser = (global::PrimarSql.Internal.PrimarSqlParser)parser;

            switch (script.ScriptType)
            {
            case QsiScriptType.Select:
                return(TableVisitor.VisitSelectStatement(primarSqlParser.selectStatement()));

            case QsiScriptType.Insert:
                return(ActionVisitor.VisitInsertStatement(primarSqlParser.insertStatement()));

            case QsiScriptType.Delete:
                return(ActionVisitor.VisitDeleteStatement(primarSqlParser.deleteStatement()));

            case QsiScriptType.Update:
                return(ActionVisitor.VisitUpdateStatement(primarSqlParser.updateStatement()));

            default:
                return(null);
            }
        }
Example #6
0
        public IQsiTreeNode Parse(QsiScript script, CancellationToken cancellationToken = default)
        {
            var result = PhoenixSqlParserInternal.Parse(script.Script);

            switch (result)
            {
            case SelectStatement selectStatement:
                return(TableVisitor.VisitSelectStatement(selectStatement));

            case CreateTableStatement {
                    TableType: PTableType.View
            } createTableStatement:
                return(TableVisitor.VisitCreateViewStatement(createTableStatement));

            case IDMLStatement dmlStatement:
                return(ActionVisitor.Visit(dmlStatement));

            case UseSchemaStatement useSchemaStatement:
                return(ActionVisitor.VisitUseSchemaStatement(useSchemaStatement));
            }

            throw TreeHelper.NotSupportedTree(result);
        }