Ejemplo n.º 1
0
        /// <summary>
        /// Search Sql alias including subqueries
        /// </summary>
        /// <param name="alias">Alias string</param>
        /// <returns>Sql Alias</returns>
        public ONSqlAlias GetOnSqlAliasInSql(string alias)
        {
            // owner from
            ONSqlAlias lOnSqlAlias = null;

            if (mFromAlias.ContainsKey(alias))
            {
                return(mFromAlias[alias]);
            }

            // Search in subqueries
            foreach (object parameter in ParametersItem)
            {
                ONSqlSelect onSubSelect = parameter as ONSqlSelect;
                if (onSubSelect != null)
                {
                    lOnSqlAlias = onSubSelect.GetOnSqlAliasInSql(alias);
                }

                if (lOnSqlAlias != null)
                {
                    return(lOnSqlAlias);
                }
            }

            return(lOnSqlAlias);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Generate a valid and unique alias
        /// </summary>
        /// <param name="alias">Source alias</param>
        /// <returns>Valid and Unique alias</returns>
        private string GenerateAlias(string alias)
        {
            StringBuilder lAliasBuilder = new StringBuilder();
            int           lLastDot      = alias.LastIndexOf('.');

            if (lLastDot < 0)
            {
                lLastDot = 0;
            }
            lAliasBuilder.Append(alias.Substring(lLastDot));

            int i = 1;

            // Go to root
            ONSqlSelect lRoot = this;

            while (lRoot.SuperQuery != null)
            {
                lRoot = lRoot.SuperQuery;
            }

            // Search alias
            while ((GetOnSqlAlias(lAliasBuilder.ToString()) != null) || (lRoot.GetOnSqlAliasInSql(lAliasBuilder.ToString()) != null) || (GetOnSqlAliasInSql(lAliasBuilder.ToString()) != null))
            {
                lAliasBuilder = new StringBuilder();

                lAliasBuilder.Append(alias);
                lAliasBuilder.Append("_");
                lAliasBuilder.Append(i.ToString());

                i++;
            }

            return(lAliasBuilder.ToString());
        }