public override IASTNode VisitTableFactor(SqlServerCommandParser.TableFactorContext context)
        {
            TableFactorSegment result = new TableFactorSegment();

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

            if (null != context.alias())
            {
                result.SetAlias((AliasSegment)Visit(context.alias()));
            }
            return(result);
        }
        private bool IsSameProjection(ShorthandProjection shorthandProjection, ColumnOrderByItemSegment orderItem, SelectCommand selectCommand)
        {
            if (shorthandProjection.GetOwner() == null)
            {
                throw new ShardingException("shorthandProjection can not found owner");
            }
            SimpleTableSegment tableSegment = Find(shorthandProjection.GetOwner(), selectCommand);

            return(_schemaMetaData.ContainsColumn(tableSegment.GetTableName().GetIdentifier().GetValue(), orderItem.GetColumn().GetIdentifier().GetValue()));
        }
 private bool IsTable(SimpleTableSegment owner, ICollection <SimpleTableSegment> tableSegments)
 {
     foreach (var simpleTableSegment in tableSegments)
     {
         if (owner.GetTableName().GetIdentifier().GetValue().Equals(simpleTableSegment.GetAlias()))
         {
             return(false);
         }
     }
     return(true);
 }
        public override IASTNode VisitTableName(MySqlCommandParser.TableNameContext ctx)
        {
            SimpleTableSegment result = new SimpleTableSegment(new TableNameSegment(ctx.Start.StartIndex, ctx.Stop.StopIndex, (IdentifierValue)Visit(ctx.name())));

            MySqlCommandParser.OwnerContext owner = ctx.owner();
            if (null != owner)
            {
                result.SetOwner(new OwnerSegment(owner.Start.StartIndex, owner.Stop.StopIndex, (IdentifierValue)Visit(owner.identifier())));
            }
            return(result);
        }
        private ShorthandProjection FindShorthandProjection(ICollection <IProjection> projections, string tableNameOrAlias, SelectCommand selectCommand)
        {
            SimpleTableSegment tableSegment = Find(tableNameOrAlias, selectCommand);

            foreach (var projection in projections)
            {
                if (!(projection is ShorthandProjection))
                {
                    continue;
                }
                ShorthandProjection shorthandProjection = (ShorthandProjection)projection;
                if (shorthandProjection.GetOwner() != null && Find(
                        shorthandProjection.GetOwner(), selectCommand).GetTableName().GetIdentifier().GetValue().Equals(tableSegment.GetTableName().GetIdentifier().GetValue(), StringComparison.OrdinalIgnoreCase))
                {
                    return(shorthandProjection);
                }
            }
            return(null);
        }
 public void SetTable(SimpleTableSegment table)
 {
     this.table = table;
 }
Beispiel #8
0
 public TablesContext(SimpleTableSegment tableSegment) : this(new List <SimpleTableSegment>(1) { tableSegment })
 {
 }
Beispiel #9
0
 public CreateTableCommand(SimpleTableSegment table)
 {
     Table = table;
 }
 public AlterTableCommand(SimpleTableSegment table)
 {
     Table = table;
 }