Ejemplo n.º 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]);
            }
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
0
        public void Test_Select()
        {
            var sql        = @"SELECT Customer.firstname, Customer.lastname, Address.Country, City 
                        FROM Customer 
                        INNER JOIN Address ON Address.CustNo = Customer.CustNo";
            var visitor    = parser.ParseScript(sql);
            var selectNode = visitor.SelectNodes.First();

            var tableVisitor = new TableVisitor();

            selectNode.Accept(tableVisitor);
            var tables = tableVisitor.SelectNodes;

            Console.WriteLine(
                "{0}: {1}",
                "Tables",
                String.Join(",", tables.Select(x => x.SchemaObject.BaseIdentifier.Value))
                );

            var columnsVisitor = new ColumnVisitor();

            selectNode.Accept(columnsVisitor);
            var columns = columnsVisitor.SelectNodes;

            Console.WriteLine(
                "{0}: {1}",
                "Columns",
                String.Join(",", columns.Select(x => x))
                );
        }
Ejemplo n.º 5
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]);
            }
        }
Ejemplo n.º 6
0
 public SqlServerParser(TransactSqlVersion transactSqlVersion)
 {
     _parser            = new TSqlParserInternal(transactSqlVersion, false);
     _tableVisitor      = CreateTableVisitor();
     _expressionVisitor = CreateExpressionVisitor();
     _identifierVisitor = CreateIdentifierVisitor();
     _actionVisitor     = CreateActionVisitor();
 }
Ejemplo n.º 7
0
        public IQsiTreeNode Parse(QsiScript script, CancellationToken cancellationToken = default)
        {
            _pgParser ??= new PgQuery10();

            var pgTree = (IPg10Node)_pgParser.Parse(script.Script) ?? throw new QsiException(QsiError.NotSupportedScript, script.ScriptType);

            switch (script.ScriptType)
            {
            case QsiScriptType.Set:
                return(ActionVisitor.Visit(pgTree));

            default:
                return(TableVisitor.Visit(pgTree));
            }
        }
Ejemplo n.º 8
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);
            }
        }
Ejemplo n.º 9
0
        public IQsiTreeNode Parse(QsiScript script, CancellationToken cancellationToken = default)
        {
            var parser = ImpalaUtility.CreateParserInternal(
                script.Script,
                Dialect
                );

            var stmt = parser.root().stmt();

            switch (stmt.children[0])
            {
            case Query_stmtContext queryStmt:
                return(TableVisitor.VisitQueryStmt(queryStmt));

            case Create_view_stmtContext createViewStmt:
                return(ActionVisitor.VisitCreateViewStmt(createViewStmt));

            case Create_tbl_as_select_stmtContext createTblAsSelectStmt:
                return(ActionVisitor.VisitCreateTblAsSelectStmt(createTblAsSelectStmt));

            case Use_stmtContext useStmt:
                return(ActionVisitor.VisitUseStmt(useStmt));

            case Upsert_stmtContext upsertStmt:
                return(ActionVisitor.VisitUpsertStmt(upsertStmt));

            case Update_stmtContext updateStmt:
                return(ActionVisitor.VisitUpdateStmt(updateStmt));

            case Insert_stmtContext insertStmt:
                return(ActionVisitor.VisitInsertStmt(insertStmt));

            case Delete_stmtContext deleteStmt:
                return(ActionVisitor.VisitDeleteStmt(deleteStmt));

            default:
                throw TreeHelper.NotSupportedTree(stmt.children[0]);
            }
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
0
        public IQsiTreeNode Parse(QsiScript script, CancellationToken cancellationToken = default)
        {
            var statement = CCJSqlParserUtility.Parse(script.Script);

            return(TableVisitor.Visit(statement) ?? throw new QsiException(QsiError.NotSupportedScript, script.ScriptType));
        }