Пример #1
0
        private SqlStringBuilder BuildSubstring(int startIndex)
        {
            SqlStringBuilder builder = new SqlStringBuilder(this);

            int offset = 0;

            while (builder.Count > 0)
            {
                int nextOffset = offset + LengthOfPart(builder[0]);

                if (nextOffset > startIndex)
                {
                    break;
                }

                builder.RemoveAt(0);
                offset = nextOffset;
            }

            if (builder.Count > 0 && offset < startIndex)
            {
                builder[0] = ((string)builder[0]).Substring(startIndex - offset);
            }

            return(builder);
        }
Пример #2
0
        public SqlString Substring(int startIndex, int length)
        {
            if (startIndex < 0)
            {
                throw new ArgumentException("startIndex should be greater than or equal to 0", "startIndex");
            }

            if (length < 0)
            {
                throw new ArgumentException("length should be greater than or equal to 0", "length");
            }

            SqlStringBuilder builder = BuildSubstring(startIndex);

            if (builder.Count == 0)
            {
                return(builder.ToSqlString());
            }

            int offset     = 0;
            int nextOffset = -1;
            int count      = int.MaxValue;

            for (int i = 0; i < builder.Count; i++)
            {
                nextOffset = offset + LengthOfPart(builder[i]);
                if (nextOffset < length)
                {
                    offset = nextOffset;
                    continue;
                }
                else if (nextOffset >= length)
                {
                    count = i + 1;
                    break;
                }
            }

            while (builder.Count > count)
            {
                builder.RemoveAt(builder.Count - 1);
            }

            if (length < nextOffset)
            {
                string lastPart = (string)builder[builder.Count - 1];
                builder[builder.Count - 1] = lastPart.Substring(0, length - offset);
            }

            SqlString result = builder.ToSqlString();

            if (isCompacted)
            {
                result.SetCompacted();
            }
            return(result);
        }
		public void RemoveAt() 
		{
			SqlStringBuilder builder = new SqlStringBuilder();

			builder.Add("   select * ");
			builder.Add("from table");
			Assert.AreEqual( "   select * from table", builder.ToSqlString().ToString() );

			builder.RemoveAt(0);
			Assert.AreEqual( "from table", builder.ToSqlString().ToString(), "Removed the first element in the SqlStringBuilder" );

			builder.Insert(0, "SELECT * ");
			Assert.AreEqual( "SELECT * from table", builder.ToSqlString().ToString() );
		}
		public override SqlString ToGroupSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery,
												   IDictionary<string, IFilter> enabledFilters)
		{
			SqlStringBuilder buf = new SqlStringBuilder();
			foreach (IProjection projection in args)
			{
				if (projection.IsGrouped)
				{
					buf.Add(projection.ToGroupSqlString(criteria, criteriaQuery, enabledFilters)).Add(", ");
				}
			}
			if (buf.Count >= 2)
			{
				buf.RemoveAt(buf.Count - 1);
			}
			return buf.ToSqlString();
		}
		public SqlString ToGroupSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters)
		{
			SqlStringBuilder buf = new SqlStringBuilder();
			for (int i = 0; i < Length; i++)
			{
				IProjection proj = this[i];
				if (proj.IsGrouped)
				{
					buf.Add(proj.ToGroupSqlString(criteria, criteriaQuery,enabledFilters))
						.Add(", ");
				}
			}
			if (buf.Count >= 2)
			{
				buf.RemoveAt(buf.Count - 1);
			}
			return buf.ToSqlString();
		}
		public SqlString ToGroupSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery)
		{
			SqlStringBuilder buf = new SqlStringBuilder();
			for (int i = 0; i < Length; i++)
			{
				IProjection proj = this[i];
				if (proj.IsGrouped)
				{
					buf.Add(proj.ToGroupSqlString(criteria, criteriaQuery))
						.Add(", ");
				}
			}
			if (buf.Count >= 2)
			{
				buf.RemoveAt(buf.Count - 1);
			}
			//if (buf.Length > 2) buf.Length = buf.Length - 2; //pull off the last ", "
			return buf.ToSqlString();
		}
Пример #7
0
        private void RemoveLastOrderByClause()
        {
            if (lastOrderByPartIndex < 0)
            {
                // No ORDER BY clause
                return;
            }

            while (builder.Count > lastOrderByPartIndex + 1)
            {
                builder.RemoveAt(builder.Count - 1);
            }

            string lastPart = builder[builder.Count - 1] as string;

            if (lastPart != null)
            {
                builder[builder.Count - 1] = lastPart.Substring(0, lastOrderByIndex);
            }
        }
Пример #8
0
        /// <summary>
        /// Retrieves a substring from this instance. The substring starts at a specified character position.
        /// </summary>
        /// <param name="startIndex">The starting character position of a substring in this instance.</param>
        /// <returns>
        /// A new SqlString to the substring that begins at startIndex in this instance.
        /// </returns>
        /// <remarks>
        /// If the first SqlPart is a Parameter then no action is taken and a copy of the SqlString is
        /// returned.
        ///
        /// If the startIndex is greater than the length of the strings before the first SqlPart that
        /// is a Parameter then all of the strings will be removed and the first SqlPart returned
        /// will be the Parameter.
        /// </remarks>
        public SqlString Substring(int startIndex)
        {
            SqlStringBuilder builder = new SqlStringBuilder(Compact());

            string part = builder[0] as string;

            // if the first part is null then it is not a string so just
            // return them the compacted version
            if (part != null)
            {
                if (part.Length < startIndex)
                {
                    builder.RemoveAt(0);
                }
                else
                {
                    builder[0] = part.Substring(startIndex);
                }
            }

            return(builder.ToSqlString());
        }
Пример #9
0
		/// <summary>
		/// Get the order by string required for collection fetching
		/// </summary>
		protected SqlString OrderBy(IList<OuterJoinableAssociation> associations)
		{
			SqlStringBuilder buf = new SqlStringBuilder();

			OuterJoinableAssociation last = null;
			foreach (OuterJoinableAssociation oj in associations)
			{
				if (oj.JoinType == JoinType.LeftOuterJoin)
				{
					if (oj.Joinable.IsCollection)
					{
						IQueryableCollection queryableCollection = (IQueryableCollection)oj.Joinable;
						if (queryableCollection.HasOrdering)
						{
							string orderByString = queryableCollection.GetSQLOrderByString(oj.RHSAlias);
							buf.Add(orderByString).Add(StringHelper.CommaSpace);
						}
					}
					else
					{
						// it might still need to apply a collection ordering based on a
						// many-to-many defined order-by...
						if (last != null && last.Joinable.IsCollection)
						{
							IQueryableCollection queryableCollection = (IQueryableCollection)last.Joinable;
							if (queryableCollection.IsManyToMany && last.IsManyToManyWith(oj))
							{
								if (queryableCollection.HasManyToManyOrdering)
								{
									string orderByString = queryableCollection.GetManyToManyOrderByString(oj.RHSAlias);
									buf.Add(orderByString).Add(StringHelper.CommaSpace);
								}
							}
						}
					}
				}
				last = oj;
			}

			if (buf.Count > 0) {
				buf.RemoveAt(buf.Count-1);
			}

			return buf.ToSqlString();
		}
Пример #10
0
		private SqlStringBuilder BuildSubstring(int startIndex)
		{
			SqlStringBuilder builder = new SqlStringBuilder(this);

			int offset = 0;

			while (builder.Count > 0)
			{
				int nextOffset = offset + LengthOfPart(builder[0]);

				if (nextOffset > startIndex)
				{
					break;
				}

				builder.RemoveAt(0);
				offset = nextOffset;
			}

			if (builder.Count > 0 && offset < startIndex)
			{
				builder[0] = ((string) builder[0]).Substring(startIndex - offset);
			}

			return builder;
		}
		/// <summary>
		/// Retrieves a substring from this instance. The substring starts at a specified character position. 
		/// </summary>
		/// <param name="startIndex">The starting character position of a substring in this instance.</param>
		/// <returns>
		/// A new SqlString to the substring that begins at startIndex in this instance. 
		/// </returns>
		/// <remarks>
		/// If the first SqlPart is a Parameter then no action is taken and a copy of the SqlString is
		/// returned.
		/// 
		/// If the startIndex is greater than the length of the strings before the first SqlPart that
		/// is a Parameter then all of the strings will be removed and the first SqlPart returned
		/// will be the Parameter. 
		/// </remarks>
		public SqlString Substring( int startIndex )
		{
			SqlStringBuilder builder = new SqlStringBuilder( Compact() );

			string part = builder[ 0 ] as string;

			// if the first part is null then it is not a string so just
			// return them the compacted version
			if( part != null )
			{
				if( part.Length < startIndex )
				{
					builder.RemoveAt( 0 );
				}
				else
				{
					builder[ 0 ] = part.Substring( startIndex );
				}
			}

			return builder.ToSqlString();
		}