예제 #1
0
        /// <summary>michele, 14/12/2014 - coloca where ou and na query, ignorando as ocorrencias do where que podem ter havido na subquery</summary>
        public string WhereAndSubQuery(string trechoQuery = null)
        {
            StringBuilder whereAnd             = new StringBuilder();
            string        queryCompleta        = Convert.ToString(query);
            int           indiceUltimaSubQuery = queryCompleta.LastIndexOf(")");
            string        queryIni             = G1.GetSubstringLeft(queryCompleta, indiceUltimaSubQuery);
            string        queryFim             = queryCompleta.Replace(queryIni, "");

            if (queryFim.ToUpper().IndexOf(" WHERE ") < 0)
            {
                whereAnd.Append(" Where ");
            }
            else
            {
                whereAnd.Append(" And ");
            }
            if (trechoQuery != null)
            {
                whereAnd.Append(trechoQuery); //concatena o trecho da query
            }
            whereAnd.Append(" ");             //coloca espaço no final da expressão para evitar erros
            return(Convert.ToString(whereAnd));
        }