示例#1
0
        public override string ToString()
        {
            if (OffsetValue > 0 || OffsetValue < 0)
            {
                return(OffsetValue.ToString());
            }

            return(OffsetFactor.ToString());
        }
        /// <summary>
        /// Compiles the fragment.
        /// </summary>
        /// <param name="queryBuilder">The query builder.</param>
        /// <param name="engine">The engine.</param>
        public virtual void Compile(QueryBuilder queryBuilder, IEngine engine)
        {
            switch (engine.Options.OffsetStyle)
            {
            case OffsetStyle.Offset:
                queryBuilder.Write("OFFSET ");

                object offsetValue = OffsetValue ?? 0;
                if (engine.Options.OffsetAsParameters || offsetValue is IQueryFragment)
                {
                    queryBuilder.WriteValue(offsetValue);
                }
                else
                {
                    queryBuilder.Write(offsetValue.ToString());
                }

                queryBuilder.Write(" ROWS");

                if (FetchValue != null)
                {
                    queryBuilder.Write(" FETCH NEXT ");

                    if (engine.Options.OffsetAsParameters || FetchValue is IQueryFragment)
                    {
                        queryBuilder.WriteValue(FetchValue);
                    }
                    else
                    {
                        queryBuilder.Write(FetchValue.ToString());
                    }

                    queryBuilder.Write(" ROWS ONLY");
                }
                break;

            case OffsetStyle.Limit:
                queryBuilder.Write("LIMIT ");

                object fetchValue = FetchValue ?? long.MaxValue;
                if (engine.Options.OffsetAsParameters || fetchValue is IQueryFragment)
                {
                    queryBuilder.WriteValue(fetchValue);
                }
                else
                {
                    queryBuilder.Write(fetchValue.ToString());
                }

                if (OffsetValue != null)
                {
                    queryBuilder.Write(" OFFSET ");

                    if (engine.Options.OffsetAsParameters || OffsetValue is IQueryFragment)
                    {
                        queryBuilder.WriteValue(OffsetValue);
                    }
                    else
                    {
                        queryBuilder.Write(OffsetValue.ToString());
                    }
                }
                break;

            default:
                throw new ClauseNotSupportedException("Offset clause is not supported in this engine.");
            }
        }