Exemple #1
0
        internal bool IsMultipartIdentifier(out string[] names)
        {
            if (this._isMultipartIdentifierComputed.HasValue)
            {
                names = this._names;
                return(this._isMultipartIdentifierComputed.Value);
            }
            this._names = (string[])null;
            Identifier leftExpr1 = this._leftExpr as Identifier;

            if (leftExpr1 != null)
            {
                this._names = new string[2]
                {
                    leftExpr1.Name,
                    this._identifier.Name
                }
            }
            ;
            DotExpr leftExpr2 = this._leftExpr as DotExpr;

            string[] names1;
            if (leftExpr2 != null && leftExpr2.IsMultipartIdentifier(out names1))
            {
                this._names = new string[names1.Length + 1];
                names1.CopyTo((Array)this._names, 0);
                this._names[this._names.Length - 1] = this._identifier.Name;
            }
            this._isMultipartIdentifierComputed = new bool?(this._names != null);
            names = this._names;
            return(this._isMultipartIdentifierComputed.Value);
        }
    }
Exemple #2
0
        internal string InferAliasName(AliasedExpr aliasedExpr, DbExpression convertedExpression)
        {
            if (aliasedExpr.Alias != null)
            {
                return(aliasedExpr.Alias.Name);
            }
            Identifier expr1 = aliasedExpr.Expr as Identifier;

            if (expr1 != null)
            {
                return(expr1.Name);
            }
            DotExpr expr2 = aliasedExpr.Expr as DotExpr;

            string[] names;
            if (expr2 != null && expr2.IsMultipartIdentifier(out names))
            {
                return(names[names.Length - 1]);
            }
            return(this.CreateNewAlias(convertedExpression));
        }
Exemple #3
0
        internal bool TryResolveDotExprAsGroupKeyAlternativeName(
            DotExpr dotExpr,
            out ValueExpression groupKeyResolution)
        {
            groupKeyResolution = (ValueExpression)null;
            string[]   names;
            ScopeEntry scopeEntry;
            int        scopeIndex;

            if (this.IsInAnyGroupScope() && dotExpr.IsMultipartIdentifier(out names) && this.TryScopeLookup(TypeResolver.GetFullName(names), out scopeEntry, out scopeIndex))
            {
                IGetAlternativeName getAlternativeName = scopeEntry as IGetAlternativeName;
                if (getAlternativeName != null && getAlternativeName.AlternativeName != null && ((IEnumerable <string>)names).SequenceEqual <string>((IEnumerable <string>)getAlternativeName.AlternativeName, (IEqualityComparer <string>) this.NameComparer))
                {
                    this.SetScopeRegionCorrelationFlag(scopeIndex);
                    groupKeyResolution = new ValueExpression(this.GetExpressionFromScopeEntry(scopeEntry, scopeIndex, TypeResolver.GetFullName(names), dotExpr.ErrCtx));
                    return(true);
                }
            }
            return(false);
        }
        /// <summary>
        ///     Try resolving multipart identifier as an alternative name of a group key (see SemanticAnalyzer.ProcessGroupByClause(...) for more info).
        /// </summary>
        internal bool TryResolveDotExprAsGroupKeyAlternativeName(DotExpr dotExpr, out ValueExpression groupKeyResolution)
        {
            groupKeyResolution = null;

            string[]   names;
            ScopeEntry scopeEntry;
            int        scopeIndex;

            if (IsInAnyGroupScope()
                &&
                dotExpr.IsMultipartIdentifier(out names)
                &&
                TryScopeLookup(TypeResolver.GetFullName(names), out scopeEntry, out scopeIndex))
            {
                var iGetAlternativeName = scopeEntry as IGetAlternativeName;

                //
                // Accept only if names[] match alternative name part by part.
                //
                if (iGetAlternativeName != null &&
                    iGetAlternativeName.AlternativeName != null
                    &&
                    names.SequenceEqual(iGetAlternativeName.AlternativeName, NameComparer))
                {
                    //
                    // Set correlation flag
                    //
                    SetScopeRegionCorrelationFlag(scopeIndex);

                    groupKeyResolution =
                        new ValueExpression(
                            GetExpressionFromScopeEntry(scopeEntry, scopeIndex, TypeResolver.GetFullName(names), dotExpr.ErrCtx));
                    return(true);
                }
            }
            return(false);
        }