Exemplo n.º 1
0
        protected override ISqlFragment buildWhereFragment(IMartenSession session)
        {
            if (WhereClauses.Count == 0)
            {
                return(_storage.DefaultWhereFragment());
            }

            var parser = new WhereClauseParser(session, this);

            ISqlFragment where = null;

            switch (WhereClauses.Count)
            {
            case 0:
                where = _storage.DefaultWhereFragment();
                break;

            case 1:
                where = parser.Build(WhereClauses.Single());
                break;

            default:
                var wheres = WhereClauses.Select(x => parser.Build(x)).ToArray();

                where = new CompoundWhereFragment("and", wheres);
                break;
            }

            return(_storage.FilterDocuments(null, where));
        }
        public override string ToString()
        {
            string connectionString;

            if (!string.IsNullOrWhiteSpace(LogicalConnectionString))
            {
                connectionString = LogicalConnectionString;
                var             regParams = new Regex(@"(@[\w\d]+)", RegexOptions.Compiled);
                MatchCollection matches   = regParams.Matches(LogicalConnectionString);
                int             padding   = 0;
                foreach (Match match in matches)
                {
                    if (!_whereClauses.ContainsKey(match.Value))
                    {
                        throw new ArgumentException(
                                  string.Format("The Placeholder with the name '{0}' couldn't be found.", match.Value));
                    }

                    string stringBefore = connectionString.Substring(0, padding + match.Index);

                    connectionString = stringBefore + _whereClauses[match.Value] +
                                       connectionString.Substring(padding + match.Index + match.Length);

                    padding += _whereClauses[match.Value].Length - match.Length;
                }
            }
            else
            {
                connectionString = string.Join(" AND ", WhereClauses.Select(x => x.Value));
            }
            return(string.Format("WHERE {0}", connectionString));
        }
Exemplo n.º 3
0
        private string BuildWhereString()
        {
            var result = "";

            if (WhereClauses.Count > 0)
            {
                result += " WHERE (";
                result += String.Join(" AND ", WhereClauses.Select(wc => wc.Get(UnderlyingQueryType)));
                result += ")";
            }

            return(result);
        }