public override void Enumerate(IMemberCompletionAcceptor acceptor)
        {
            List <TableBinding> joinTargetList = new List <TableBinding>();

            TableRefBinding[] tableRefBindings = _queryScope.GetAllTableRefBindings();
            foreach (TableRefBinding tableRefBinding in tableRefBindings)
            {
                TableBinding          joinSource     = tableRefBinding.TableBinding;
                IList <TableRelation> tableRelations = _scope.DataContext.TableRelations.GetRelations(joinSource);

                foreach (TableRelation tableRelation in tableRelations)
                {
                    TableBinding joinTarget;

                    if (tableRelation.ParentTable == joinSource)
                    {
                        joinTarget = tableRelation.ChildTable;
                    }
                    else
                    {
                        joinTarget = tableRelation.ParentTable;
                    }

                    if (!joinTargetList.Contains(joinTarget))
                    {
                        joinTargetList.Add(joinTarget);
                    }
                }
            }

            if (joinTargetList.Count > 0)
            {
                foreach (TableBinding joinTarget in joinTargetList)
                {
                    acceptor.AcceptTable(joinTarget);
                }
            }
            else
            {
                foreach (TableBinding joinTarget in _scope.DataContext.Tables)
                {
                    acceptor.AcceptTable(joinTarget);
                }
            }
        }
        public override void Enumerate(IMemberCompletionAcceptor acceptor)
        {
            List <TableRelationData> tableRelationDataList = new List <TableRelationData>();

            TableRefBinding[] tableRefBindings = _queryScope.GetAllTableRefBindings();
            Array.Reverse(tableRefBindings);

            foreach (TableRefBinding joinSourceTableRef in tableRefBindings)
            {
                TableBinding          joinSource     = joinSourceTableRef.TableBinding;
                IList <TableRelation> tableRelations = _scope.DataContext.TableRelations.GetRelations(joinSource);

                foreach (TableRelation tableRelation in tableRelations)
                {
                    TableBinding joinTarget;

                    if (tableRelation.ParentTable == joinSource)
                    {
                        joinTarget = tableRelation.ChildTable;
                    }
                    else
                    {
                        joinTarget = tableRelation.ParentTable;
                    }

                    foreach (TableRefBinding joinTargetTableRef in tableRefBindings)
                    {
                        if (joinTargetTableRef.TableBinding == joinTarget)
                        {
                            TableRelationData tableRelationData = new TableRelationData();
                            tableRelationData.Relation = tableRelation;
                            tableRelationData.Child    = joinTargetTableRef;
                            tableRelationData.Parent   = joinSourceTableRef;
                            tableRelationDataList.Add(tableRelationData);
                        }
                    }
                }
            }

            foreach (TableRelationData tableRelationData in tableRelationDataList)
            {
                acceptor.AcceptRelation(tableRelationData.Parent, tableRelationData.Child, tableRelationData.Relation);
            }
        }
Esempio n. 3
0
        public override void Enumerate(IMemberCompletionAcceptor acceptor)
        {
            if (acceptor == null)
            {
                throw ExceptionBuilder.ArgumentNull("acceptor");
            }

            // Enumerate the complete global scope
            //
            // 1.	Enumerate all table refs and column refs as they are part
            //		of the query scope.

            foreach (TableRefBinding tableRefBinding in _queryScope.GetAllTableRefBindings())
            {
                acceptor.AcceptTableRef(tableRefBinding);
            }

            foreach (ColumnRefBinding columnRefBinding in _queryScope.GetAllColumnRefBindings())
            {
                acceptor.AcceptColumnRef(columnRefBinding);
            }

            // 2. Enumerate all tables, constants, aggregates and functions

            foreach (TableBinding table in _scope.DataContext.Tables)
            {
                acceptor.AcceptTable(table);
            }

            foreach (ConstantBinding constant in _scope.DataContext.Constants)
            {
                acceptor.AcceptConstant(constant);
            }

            foreach (AggregateBinding aggregateBinding in _scope.DataContext.Aggregates)
            {
                acceptor.AcceptAggregate(aggregateBinding);
            }

            foreach (FunctionBinding functionBinding in _scope.DataContext.Functions)
            {
                acceptor.AcceptFunction(functionBinding);
            }

            // 3. Enumerate parameters

            foreach (ParameterBinding parameter in _scope.Parameters)
            {
                acceptor.AcceptParameter(parameter);
            }

            // 4. Enumerate keywords

            TokenId[] tokenIDs = (TokenId[])Enum.GetValues(typeof(TokenId));

            foreach (TokenId tokenID in tokenIDs)
            {
                TokenInfo info = TokenInfo.FromTokenId(tokenID);

                if (info.IsKeyword)
                {
                    acceptor.AcceptKeyword(info.Text);
                }
            }

            // 5. Enumerate relations

            TableRefBinding[] tableRefBindings = _queryScope.GetAllTableRefBindings();

            foreach (TableRefBinding parentTableRef in tableRefBindings)
            {
                IList <TableRelation> relations = _scope.DataContext.TableRelations.GetChildRelations(parentTableRef.TableBinding);

                foreach (TableRelation relation in relations)
                {
                    TableBinding    childTable    = (relation.ParentTable == parentTableRef.TableBinding) ? relation.ChildTable : relation.ParentTable;
                    TableRefBinding childTableRef = null;

                    foreach (TableRefBinding tableRefBinding in tableRefBindings)
                    {
                        if (tableRefBinding.TableBinding == childTable)
                        {
                            childTableRef = tableRefBinding;
                            break;
                        }
                    }

                    if (childTableRef != null)
                    {
                        acceptor.AcceptRelation(parentTableRef, childTableRef, relation);
                    }
                }
            }
        }