예제 #1
0
        /// <summary>
        /// Creates a WHERE clause comparison for a field and value in the form ([fieldName] LIKE [value]), where the value data type is <see cref="String"/>.
        /// </summary>
        /// <param name="where">The query builder instance</param>
        /// <param name="fieldName">The name of the field to use as the expression on the left of the operator.</param>
        /// <param name="operator">The comparison operator to use.</param>
        /// <param name="value">The value of the parameter created for the right side of the operator.</param>
        /// <param name="isAnsi">Is the database field an ANSI string or Unicode string?</param>
        /// <param name="length">Is the database field fixed length or variable length?</param>
        /// <returns></returns>
        public static IDbQueryWhereClause StringMatch(this IDbQueryWhereClause where, string fieldName, Csg.Data.Sql.SqlWildcardDecoration @operator, string value, bool isAnsi = false, int?length = null)
        {
            var filter = new Csg.Data.Sql.SqlStringMatchFilter(where.Root, fieldName, @operator, value);

            if (isAnsi && length.HasValue && length.Value > 0)
            {
                filter.DataType = DbType.AnsiStringFixedLength;
            }
            else if (isAnsi)
            {
                filter.DataType = DbType.AnsiString;
            }
            else if (length.HasValue && length.Value > 0)
            {
                filter.DataType = DbType.StringFixedLength;
            }
            else
            {
                filter.DataType = DbType.String;
            }

            if (length.HasValue && length.Value >= 0)
            {
                filter.Size = length.Value;
            }

            where.AddFilter(filter);

            return(where);
        }
        /// <summary>
        /// Adds a string pattern matching filter to the query's where clause.
        /// </summary>
        /// <param name="query"></param>
        /// <param name="fieldName"></param>
        /// <param name="operator"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static IDbQueryWhereClause StringMatch(this IDbQueryWhereClause query, string fieldName, Csg.Data.Sql.SqlWildcardDecoration @operator, DbString value)
        {
            var filter = new Csg.Data.Sql.SqlStringMatchFilter(query.Root, fieldName, @operator, value.Value);

            if (value.IsAnsi && value.IsFixedLength)
            {
                filter.DataType = DbType.AnsiStringFixedLength;
            }
            else if (value.IsAnsi)
            {
                filter.DataType = DbType.AnsiString;
            }
            else if (value.IsFixedLength)
            {
                filter.DataType = DbType.StringFixedLength;
            }
            else
            {
                filter.DataType = DbType.String;
            }

            if (value.Length >= 0)
            {
                filter.Size = value.Length;
            }

            query.AddFilter(filter);

            return(query);
        }
예제 #3
0
        protected override void RenderInternal(SqlTextWriter writer, SqlBuildArguments args)
        {
            string s = this.Value;

            if (s == null)
            {
                s = string.Empty;
            }

            writer.WriteBeginGroup();
            writer.WriteColumnName(this.ColumnName, args.TableName(this.Table));
            writer.WriteSpace();
            writer.Write(SqlConstants.LIKE);
            writer.WriteSpace();
            writer.WriteParameter(args.CreateParameter(SqlStringMatchFilter.DecorateValue(this.Value, this.Operator), this.DataType));
            writer.WriteEndGroup();
        }