/// <summary>
        /// Creates a new EXISTS predicate.
        /// </summary>
        /// <param name="item">Items/expression.</param>
        /// <param name="negate">Specifies whether the predicate is negated (NOT EXISTS).</param>
        internal ExistsPredicate(PredicateItem item, bool negate)
        {
            if (item.ItemType != SqlItemType.SubQuery)
                throw new ArgumentException(Messages.ExistsPredicate_OnlySubqueriesAreAllowed, "item");

            PredicateItems = new PredicateItem[] { item };
            Negate = negate;
        }
Beispiel #2
0
        /// <summary>
        /// Creates a new IN predicate.
        /// </summary>
        /// <param name="firstItem">First item. Test expression.</param>
        /// <param name="valueItems">Array of expressions (subqueries, values).</param>
        /// <param name="negate">Specifies whether the predicate is negated (NOT IN).</param>
        internal InPredicate(PredicateItem firstItem, PredicateItem[] valueItems, bool negate)
        {
            EnsureValueItemsAreValid(valueItems);
            PredicateItems = new PredicateItem[1 + valueItems.Length];
            PredicateItems[0] = firstItem;
            for (int idxValue = 0; idxValue < valueItems.Length; idxValue++)
                PredicateItems[idxValue + 1] = valueItems[idxValue];

            Negate = negate;
        }
Beispiel #3
0
        private static void EnsureValueItemsAreValid(PredicateItem[] valueItems)
        {
            if (valueItems == null || valueItems.Length == 0)
                throw new ArgumentException(Messages.InPredicate_AtLeastOneValueIsRequired, "valueItems");

            foreach (PredicateItem expression in valueItems)
            {
                if (expression == null)
                    throw new ArgumentException(Messages.InPredicate_NullsAreNotAllowedInArray, "valueItems");
            }
        }
        /// <summary>
        /// Creates an <see cref="InPredicate"/>.
        /// </summary>
        /// <param name="field">Database field.</param>
        /// <param name="values">List of values.</param>
        /// <param name="negate">Specifies whether the predicate is negated (NOT IN).</param>
        /// <returns>InPredicate.</returns>
        /// <remarks>Creates an IN predicate that determines if a field matches any value in a list.</remarks>
        public static InPredicate In(IDbColumn field, object[] values, bool negate)
        {
            if (field == null || values == null)
                throw new ArgumentException(Messages.PredicateFactory_ObjReferenceIsNull);

            PredicateItem[] itemValues = new PredicateItem[values.Length];
            for (int valIdx = 0; valIdx < values.Length; valIdx++)
                itemValues[valIdx] = new PredicateItem(values[valIdx], field.DbType, field.MaxLengthIfText, field.GetPrefixedAlias());

            return new InPredicate(new PredicateItem(field, SqlItemType.Column), itemValues, negate);
        }
        /// <summary>
        /// Creates an <see cref="InPredicate"/>.
        /// </summary>
        /// <param name="field">Database field.</param>
        /// <param name="subQuery"><see cref="SelectStatement"/> that selects values from a single column.</param>
        /// <param name="negate">Specifies whether the predicate is negated (NOT IN).</param>
        /// <returns>InPredicate.</returns>
        /// <remarks>Creates an IN predicate that determines if a field matches any value in a subquery.</remarks>
        public static InPredicate In(IDbColumn field, SelectStatement subQuery, bool negate)
        {
            if (field == null || subQuery == null)
                throw new ArgumentException(Messages.PredicateFactory_ObjReferenceIsNull);

            PredicateItem[] itemValues = new PredicateItem[] { new PredicateItem(subQuery, SqlItemType.SubQuery) };
            return new InPredicate(new PredicateItem(field, SqlItemType.Column), itemValues, negate);
        }
        internal ContainsPredicate(ContainsTermType type, IDbColumn field, string term, bool negate)
        {
            if (term == null)
                throw new ArgumentNullException("term", Messages.ContainsPredicate_NullIsNotAllowed);

            // throw new ArgumentException("CONTAINS predicate may only be used with textual field. " + field.ColumnName + " is not textual.", "field");
            if (!DBTypeUtil.IsText(field.DataType))
                throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Messages.ContainsPredicate_FieldXIsNotTextual, field.ColumnName), "field");

            term = CleanContainsParameter(term);
            if (term.Length == 0)
                throw new ArgumentException(Messages.ContainsPredicate_TermIsNotValid, "term");

            this.TermType = type;
            PredicateItems = new PredicateItem[]
            {
                new PredicateItem(field),
                new PredicateItem(term, DbType.String, field.MaxLengthIfText, field.GetPrefixedAlias())
            };
            Negate = negate;
        }
 /// <summary>
 /// Creates a new between predicate.
 /// </summary>
 /// <param name="firstItem">First item. Test expression.</param>
 /// <param name="secondItem">Second item. Begin expression.</param>
 /// <param name="thirdItem">Third item. End expression.</param>
 /// <param name="negate">Specifies whether the predicate is negated (NOT BETWEEN).</param>
 internal BetweenPredicate(PredicateItem firstItem, PredicateItem secondItem, PredicateItem thirdItem, bool negate)
 {
     PredicateItems = new PredicateItem[] { firstItem, secondItem, thirdItem };
     Negate = negate;
 }
 /// <summary>
 /// Creates a new comparison predicate.
 /// </summary>
 /// <param name="lhs">Left hand side item.</param>
 /// <param name="comparisonOperator"><see cref="ComparisonOperator"/>. Eg: ">=".</param>
 /// <param name="rhs">Right hand side item.</param>
 /// <param name="negate">Specifies whether the predicate is negated (NOT).</param>
 internal ComparePredicate(PredicateItem lhs, string comparisonOperator, PredicateItem rhs, bool negate)
 {
     PredicateItems = new PredicateItem[] { lhs, rhs };
     Negate = negate;
     this.comparisonOperator = comparisonOperator;
 }
Beispiel #9
0
 /// <summary>
 /// Creates a new LIKE predicate.
 /// </summary>
 /// <param name="lhs">Left hand side item.</param>
 /// <param name="rhs">Right hand side item (pattern).</param>
 /// <param name="negate">Specifies whether the predicate is negated (NOT LIKE).</param>
 internal LikePredicate(PredicateItem lhs, PredicateItem rhs, bool negate)
 {
     PredicateItems = new PredicateItem[] { lhs, rhs };
     Negate = negate;
 }
 /// <summary>
 /// Creates a new IS NULL predicate.
 /// </summary>
 /// <param name="item">Items/expression.</param>
 /// <param name="negate">Specifies whether the predicate is negated (IS NOT NULL).</param>
 internal IsNullPredicate(PredicateItem item, bool negate)
 {
     PredicateItems = new PredicateItem[] { item };
     Negate = negate;
 }