Пример #1
0
        public override IASTNode VisitTableFactor(MySqlCommandParser.TableFactorContext ctx)
        {
            TableFactorSegment result = new TableFactorSegment();

            if (null != ctx.subquery())
            {
                SelectCommand        subquery             = (SelectCommand)Visit(ctx.subquery());
                SubQuerySegment      subquerySegment      = new SubQuerySegment(ctx.subquery().Start.StartIndex, ctx.subquery().Stop.StopIndex, subquery);
                SubQueryTableSegment subqueryTableSegment = new SubQueryTableSegment(subquerySegment);
                if (null != ctx.alias())
                {
                    subqueryTableSegment.SetAlias((AliasSegment)Visit(ctx.alias()));
                }
                result.SetTable(subqueryTableSegment);
            }
            if (null != ctx.tableName())
            {
                SimpleTableSegment table = (SimpleTableSegment)Visit(ctx.tableName());
                if (null != ctx.alias())
                {
                    table.SetAlias((AliasSegment)Visit(ctx.alias()));
                }
                result.SetTable(table);
            }
            if (null != ctx.tableReferences())
            {
                CollectionValue <TableReferenceSegment> tableReferences = (CollectionValue <TableReferenceSegment>)Visit(ctx.tableReferences());
                result.TableReferences.AddAll(tableReferences.GetValue());
            }
            return(result);
        }
        public override IASTNode VisitSelectClause(SqlServerCommandParser.SelectClauseContext context)
        {
            var result = new SelectCommand();

            result.Projections = (ProjectionsSegment)Visit(context.projections());
            if (null != context.duplicateSpecification())
            {
                result.Projections.SetDistinctRow(IsDistinct(context));
            }
            if (null != context.fromClause())
            {
                CollectionValue <TableReferenceSegment> tableReferences = (CollectionValue <TableReferenceSegment>)Visit(context.fromClause());
                foreach (var tableReferenceSegment in tableReferences.GetValue())
                {
                    result.TableReferences.Add(tableReferenceSegment);
                }
            }
            if (null != context.whereClause())
            {
                result.Where = (WhereSegment)Visit(context.whereClause());
            }
            if (null != context.groupByClause())
            {
                result.GroupBy = (GroupBySegment)Visit(context.groupByClause());
            }
            if (null != context.orderByClause())
            {
                result.OrderBy = (OrderBySegment)Visit(context.orderByClause());
            }
            return(result);
        }
        public override IASTNode VisitCreateDefinitionClause(SqlServerCommandParser.CreateDefinitionClauseContext context)
        {
            CollectionValue <ICreateDefinitionSegment> result = new CollectionValue <ICreateDefinitionSegment>();

            foreach (var createTableDefinitionContext in context.createTableDefinitions().createTableDefinition())
            {
                if (null != createTableDefinitionContext.columnDefinition())
                {
                    result.GetValue().Add((ColumnDefinitionSegment)Visit(createTableDefinitionContext.columnDefinition()));
                }
                if (null != createTableDefinitionContext.tableConstraint())
                {
                    result.GetValue().Add((ConstraintDefinitionSegment)Visit(createTableDefinitionContext.tableConstraint()));
                }
            }
            return(result);
        }
        public override IASTNode VisitTableReferences(SqlServerCommandParser.TableReferencesContext context)
        {
            CollectionValue <TableReferenceSegment> result = new CollectionValue <TableReferenceSegment>();

            foreach (var tableReferenceContext in context.tableReference())
            {
                result.GetValue().Add((TableReferenceSegment)Visit(tableReferenceContext));
            }
            return(result);
        }
Пример #5
0
        public override IASTNode VisitColumnNames(MySqlCommandParser.ColumnNamesContext ctx)
        {
            CollectionValue <ColumnSegment> result = new CollectionValue <ColumnSegment>();

            foreach (var each in ctx.columnName())
            {
                result.GetValue().Add((ColumnSegment)Visit(each));
            }
            return(result);
        }
Пример #6
0
        public override IASTNode VisitTableReferences(MySqlCommandParser.TableReferencesContext ctx)
        {
            CollectionValue <TableReferenceSegment> result = new CollectionValue <TableReferenceSegment>();

            foreach (MySqlCommandParser.EscapedTableReferenceContext each in ctx.escapedTableReference())
            {
                result.GetValue().Add((TableReferenceSegment)Visit(each));
            }
            return(result);
        }
Пример #7
0
        public override IASTNode VisitMultipleTableNames(MySqlCommandParser.MultipleTableNamesContext ctx)
        {
            CollectionValue <SimpleTableSegment> result = new CollectionValue <SimpleTableSegment>();

            foreach (var each in ctx.tableName())
            {
                result.GetValue().Add((SimpleTableSegment)Visit(each));
            }
            return(result);
        }
        public override IASTNode VisitMultipleTableNames(SqlServerCommandParser.MultipleTableNamesContext context)
        {
            CollectionValue <SimpleTableSegment> result = new CollectionValue <SimpleTableSegment>();

            foreach (var tableNameContext in context.tableName())
            {
                result.GetValue().Add((SimpleTableSegment)Visit(tableNameContext));
            }

            return(result);
        }
Пример #9
0
        public override IASTNode VisitColumnNames(SqlServerCommandParser.ColumnNamesContext context)
        {
            CollectionValue <ColumnSegment> result = new CollectionValue <ColumnSegment>();

            foreach (var columnName in context.columnNameWithSort())
            {
                result.GetValue().Add((ColumnSegment)Visit(columnName));
            }

            return(result);
        }
        public override IASTNode VisitAlterDefinitionClause(SqlServerCommandParser.AlterDefinitionClauseContext context)
        {
            CollectionValue <IAlterDefinitionSegment> result = new CollectionValue <IAlterDefinitionSegment>();

            if (null != context.addColumnSpecification())
            {
                var addColumnDefinitionSegments = ((CollectionValue <AddColumnDefinitionSegment>)Visit(context.addColumnSpecification())).GetValue();
                foreach (var addColumnDefinitionSegment in addColumnDefinitionSegments)
                {
                    result.GetValue().Add(addColumnDefinitionSegment);
                }
            }
            if (null != context.modifyColumnSpecification())
            {
                result.GetValue().Add((ModifyColumnDefinitionSegment)Visit(context.modifyColumnSpecification()));
            }
            if (null != context.alterDrop() && null != context.alterDrop().dropColumnSpecification())
            {
                result.GetValue().Add((DropColumnDefinitionSegment)Visit(context.alterDrop().dropColumnSpecification()));
            }
            return(result);
        }
        public override IASTNode VisitMultipleTablesClause(SqlServerCommandParser.MultipleTablesClauseContext context)
        {
            CollectionValue <SimpleTableSegment> result = new CollectionValue <SimpleTableSegment>();

            result.Combine((CollectionValue <SimpleTableSegment>)Visit(context.multipleTableNames()));
            CollectionValue <TableReferenceSegment> tableReferences = (CollectionValue <TableReferenceSegment>)Visit(context.tableReferences());

            foreach (var tableReferenceSegment in tableReferences.GetValue())
            {
                result.GetValue().AddAll(tableReferenceSegment.GetTables());
            }
            return(result);
        }
        public override IASTNode VisitUpdate(SqlServerCommandParser.UpdateContext context)
        {
            UpdateCommand result = new UpdateCommand();
            CollectionValue <TableReferenceSegment> tableReferences = (CollectionValue <TableReferenceSegment>)Visit(context.tableReferences());

            foreach (var tableReferenceSegment in tableReferences.GetValue())
            {
                result.Tables.AddAll(tableReferenceSegment.GetTables());
            }
            result.SetAssignment = (SetAssignmentSegment)Visit(context.setAssignmentsClause());
            if (null != context.whereClause())
            {
                result.Where = (WhereSegment)Visit(context.whereClause());
            }
            result.SetParameterCount(GetCurrentParameterIndex());
            return(result);
        }
        public override IASTNode VisitCreateTable(SqlServerCommandParser.CreateTableContext context)
        {
            CreateTableCommand result = new CreateTableCommand((SimpleTableSegment)Visit(context.tableName()));

            if (null != context.createDefinitionClause())
            {
                CollectionValue <ICreateDefinitionSegment> createDefinitions = (CollectionValue <ICreateDefinitionSegment>)Visit(context.createDefinitionClause());
                foreach (var createDefinitionSegment in createDefinitions.GetValue())
                {
                    if (createDefinitionSegment is ColumnDefinitionSegment columnDefinitionSegment)
                    {
                        result.ColumnDefinitions.Add(columnDefinitionSegment);
                    }
                    else if (createDefinitionSegment is ConstraintDefinitionSegment constraintDefinitionSegment)
                    {
                        result.ConstraintDefinitions.Add(constraintDefinitionSegment);
                    }
                }
            }
            return(result);
        }
        public override IASTNode VisitAddColumnSpecification(SqlServerCommandParser.AddColumnSpecificationContext context)
        {
            CollectionValue <AddColumnDefinitionSegment> result = new CollectionValue <AddColumnDefinitionSegment>();

            if (null != context.alterColumnAddOptions())
            {
                foreach (var alterColumnAddOptionContext in context.alterColumnAddOptions().alterColumnAddOption())
                {
                    if (null != alterColumnAddOptionContext.columnDefinition())
                    {
                        AddColumnDefinitionSegment addColumnDefinition = new AddColumnDefinitionSegment(
                            alterColumnAddOptionContext.columnDefinition().Start.StartIndex, alterColumnAddOptionContext.columnDefinition().Stop.StopIndex,
                            new List <ColumnDefinitionSegment>()
                        {
                            (ColumnDefinitionSegment)Visit(alterColumnAddOptionContext.columnDefinition())
                        });
                        result.GetValue().Add(addColumnDefinition);
                    }
                }
            }
            return(result);
        }
Пример #15
0
        public override IASTNode VisitSelectClause(MySqlCommandParser.SelectClauseContext ctx)
        {
            SelectCommand result = new SelectCommand();

            result.Projections = (ProjectionsSegment)Visit(ctx.projections());
            if (null != ctx.selectSpecification())
            {
                result.Projections.SetDistinctRow(IsDistinct(ctx));
            }
            if (null != ctx.fromClause())
            {
                CollectionValue <TableReferenceSegment> tableReferences = (CollectionValue <TableReferenceSegment>)Visit(ctx.fromClause());
                foreach (TableReferenceSegment each in tableReferences.GetValue())
                {
                    result.TableReferences.Add(each);
                }
            }
            if (null != ctx.whereClause())
            {
                result.Where = (WhereSegment)Visit(ctx.whereClause());
            }
            if (null != ctx.groupByClause())
            {
                result.GroupBy = (GroupBySegment)Visit(ctx.groupByClause());
            }
            if (null != ctx.orderByClause())
            {
                result.OrderBy = (OrderBySegment)Visit(ctx.orderByClause());
            }
            if (null != ctx.limitClause())
            {
                result.Limit = (LimitSegment)Visit(ctx.limitClause());
            }
            if (null != ctx.lockClause())
            {
                result.Lock = (LockSegment)Visit(ctx.lockClause());
            }
            return(result);
        }
        public override IASTNode VisitInsertValuesClause(SqlServerCommandParser.InsertValuesClauseContext context)
        {
            InsertCommand result = new InsertCommand();

            if (null != context.columnNames())
            {
                SqlServerCommandParser.ColumnNamesContext columnNames    = context.columnNames();
                CollectionValue <ColumnSegment>           columnSegments = (CollectionValue <ColumnSegment>)Visit(columnNames);
                result.InsertColumns = new InsertColumnsSegment(columnNames.Start.StartIndex, columnNames.Stop.StopIndex, columnSegments.GetValue());
            }
            else
            {
                result.InsertColumns = new InsertColumnsSegment(context.Start.StartIndex - 1, context.Stop.StopIndex - 1, new List <ColumnSegment>());
            }
            result.Values.AddAll(CreateInsertValuesSegments(context.assignmentValues()));
            return(result);
        }